initial working version of the builder
This commit is contained in:
parent
51ec473ee6
commit
b7e340b562
7 changed files with 124 additions and 10 deletions
80
src/command_executor.odin
Normal file
80
src/command_executor.odin
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package main
|
||||
|
||||
import c "core:c/libc"
|
||||
import "core:log"
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
|
||||
ExecutionError :: enum {
|
||||
None,
|
||||
ErrorDuringCommandExecution,
|
||||
}
|
||||
|
||||
execute_command :: proc(
|
||||
command: Command,
|
||||
target_name: TargetName,
|
||||
configuration: ConfigurationTargets,
|
||||
) -> (
|
||||
error: ExecutionError,
|
||||
) {
|
||||
target_config, found_target_in_config := configuration[target_name]
|
||||
if !found_target_in_config && target_name != "" {
|
||||
log.errorf("No such target in config: %s", target_name)
|
||||
os.exit(1)
|
||||
}
|
||||
|
||||
compile_flags: string
|
||||
sb := strings.builder_make()
|
||||
defer strings.builder_destroy(&sb)
|
||||
|
||||
// Append the command
|
||||
strings.write_string(&sb, "odin ")
|
||||
strings.write_string(&sb, command_to_string(command))
|
||||
strings.write_byte(&sb, ' ')
|
||||
|
||||
if def_config, ok := configuration[DEFAULT_TARGET_NAME]; ok && !found_target_in_config {
|
||||
strings.write_string(&sb, string(def_config.source))
|
||||
} else if found_target_in_config {
|
||||
strings.write_string(&sb, string(target_config.source))
|
||||
}
|
||||
|
||||
// Add the collections to the compile flags
|
||||
if def_config, ok := configuration[DEFAULT_TARGET_NAME]; ok {
|
||||
for collectionName, collectionPath in def_config.collections {
|
||||
strings.write_string(&sb, " -collection:")
|
||||
strings.write_string(&sb, string(collectionName))
|
||||
strings.write_string(&sb, "=")
|
||||
strings.write_string(&sb, string(collectionPath))
|
||||
}
|
||||
}
|
||||
if found_target_in_config {
|
||||
for collectionName, collectionPath in target_config.collections {
|
||||
strings.write_string(&sb, " -collection:")
|
||||
strings.write_string(&sb, string(collectionName))
|
||||
strings.write_string(&sb, "=")
|
||||
strings.write_string(&sb, string(collectionPath))
|
||||
}
|
||||
}
|
||||
|
||||
// Add the other type of flags
|
||||
if def_config, ok := configuration[DEFAULT_TARGET_NAME]; ok {
|
||||
for flag in def_config.flags {
|
||||
strings.write_byte(&sb, ' ')
|
||||
strings.write_string(&sb, flag)
|
||||
}
|
||||
}
|
||||
if found_target_in_config {
|
||||
for flag in target_config.flags {
|
||||
strings.write_byte(&sb, ' ')
|
||||
strings.write_string(&sb, flag)
|
||||
}
|
||||
}
|
||||
|
||||
compile_flags = strings.to_string(sb)
|
||||
|
||||
log.infof("Calling command:\n\t'%s'", compile_flags)
|
||||
ccommand, err := strings.clone_to_cstring(compile_flags)
|
||||
c.system(ccommand)
|
||||
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue