<commit_before>#-----------------------------------------------------------------------
# TITLE:
#   compiletool.tcl
#
# AUTHOR:
#   <NAME>
#
# DESCRIPTION:
#   Kite "compile" tool.  This compiles the project's make targets.
#
#-----------------------------------------------------------------------

#-----------------------------------------------------------------------
# Registration

set ::ktools(compile) {
    arglist     {}
    package     kiteapp
    ensemble    compiletool
    description "Compile \"src\" directories"
    intree      yes
}

set ::khelp(compile) {
    The 'kite compile' tool compiles the contents of the project's 
    "src" directories, as defined by the "src" statement in 
    project.kite.  By default, all such directories are compiled.  
    Alternatively, the user may specify a list of names.  Note that
    directories are always compiled in the order in which they are
    defined in project.kite.

    For example, to compile the contents of the <root>/src/fred and
    <root>/src/george directories,

        $ kite compile fred george

    See the discussion of the "src" statement in the project(5) manpage
    for more.
}

#-----------------------------------------------------------------------
# compiletool ensemble

snit::type compiletool {
    # Make it a singleton
    pragma -hasinstances no -hastypedestroy no

    #-------------------------------------------------------------------
    # Execution 

    # execute argv
    #
    # Executes the tool given the command line arguments.

    typemethod execute {argv} {
        checkargs compile 0 - {?names?} $argv

        if {[llength $argv] > 0} {
            foreach name $argv {
                if {$name ni [project src names]} {
                    throw FATAL "Unknown src directory: \"$name\""
                }
            }
            set toCompile $argv
        } else {
            set toCompile [project src names]
        }

        foreach name [project src names] {
            if {$name ni $toCompile} {
                continue
            }

            set dir [project root src $name]

            puts ""
            puts [string repeat = 75]
            puts "Making: src/$name"
            puts ""
            ExecuteScript $dir [project src build $name]
        }
    }

    # ExecuteScript dir script
    #
    # dir     - The directory in which to execute it.
    # script  - A script of shell commands.
    #
    # Executes the commands one at a time, throwing FATAL on error.

    proc ExecuteScript {dir script} {
        foreach command [split $script \n] {
            if {[string trim $command] eq ""} {
                continue
            }

            ExecuteCommand $dir $command
        }
    }

    # ExecuteCommand dir command
    #
    # dir     - The directory in which to execute it
    # command - The command to execute.
    #
    # Executes the command in the directory, throwing FATAL
    # on error.

    proc ExecuteCommand {dir command} {
        cd $dir
        puts "$command"
        try {
            exec {*}$command >@ stdout 2>@ stderr 
        } on error {result} {
            throw FATAL "Error making: $path"
        }   
    }
}





<commit_msg>Fixed bug in 'kite compile'.<commit_after>#-----------------------------------------------------------------------
# TITLE:
#   compiletool.tcl
#
# AUTHOR:
#   <NAME>
#
# DESCRIPTION:
#   Kite "compile" tool.  This compiles the project's make targets.
#
#-----------------------------------------------------------------------

#-----------------------------------------------------------------------
# Registration

set ::ktools(compile) {
    arglist     {}
    package     kiteapp
    ensemble    compiletool
    description "Compile \"src\" directories"
    intree      yes
}

set ::khelp(compile) {
    The 'kite compile' tool compiles the contents of the project's 
    "src" directories, as defined by the "src" statement in 
    project.kite.  By default, all such directories are compiled.  
    Alternatively, the user may specify a list of names.  Note that
    directories are always compiled in the order in which they are
    defined in project.kite.

    For example, to compile the contents of the <root>/src/fred and
    <root>/src/george directories,

        $ kite compile fred george

    See the discussion of the "src" statement in the project(5) manpage
    for more.
}

#-----------------------------------------------------------------------
# compiletool ensemble

snit::type compiletool {
    # Make it a singleton
    pragma -hasinstances no -hastypedestroy no

    #-------------------------------------------------------------------
    # Execution 

    # execute argv
    #
    # Executes the tool given the command line arguments.

    typemethod execute {argv} {
        checkargs compile 0 - {?names?} $argv

        if {[llength $argv] > 0} {
            foreach name $argv {
                if {$name ni [project src names]} {
                    throw FATAL "Unknown src directory: \"$name\""
                }
            }
            set toCompile $argv
        } else {
            set toCompile [project src names]
        }

        foreach name [project src names] {
            if {$name ni $toCompile} {
                continue
            }

            set dir [project root src $name]

            puts ""
            puts [string repeat = 75]
            puts "Making: src/$name"
            puts ""
            ExecuteScript $dir [project src build $name]
        }
    }

    # ExecuteScript dir script
    #
    # dir     - The directory in which to execute it.
    # script  - A script of shell commands.
    #
    # Executes the commands one at a time, throwing FATAL on error.

    proc ExecuteScript {dir script} {
        foreach command [split $script \n] {
            if {[string trim $command] eq ""} {
                continue
            }

            ExecuteCommand $dir $command
        }
    }

    # ExecuteCommand dir command
    #
    # dir     - The directory in which to execute it
    # command - The command to execute.
    #
    # Executes the command in the directory, throwing FATAL
    # on error.

    proc ExecuteCommand {dir command} {
        cd $dir
        puts "$command"
        try {
            exec {*}$command >@ stdout 2>@ stderr 
        } on error {result} {
            throw FATAL "Error making: $dir"
        }   
    }
}






{'fraction_non_alphanumeric': 0.18245341614906832, 'fraction_numerical': 0.0018633540372670807, 'mean_word_length': 1.31025824964132, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7029383', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1601, 'n_words': 598}