toolchain version command
This commit is contained in:
+7
-1
@@ -123,7 +123,13 @@ build_output_path :: proc(project_root, name: string, allocator := context.alloc
|
||||
if dir_error != nil {
|
||||
return "", false
|
||||
}
|
||||
if err := os2.make_directory_all(build_dir); err != nil {
|
||||
if os.exists(build_dir) {
|
||||
if !os.is_dir(build_dir) {
|
||||
fmt.eprintfln("build path exists and is not a directory: %s", build_dir)
|
||||
delete(build_dir, allocator)
|
||||
return "", false
|
||||
}
|
||||
} else if err := os2.make_directory_all(build_dir); err != nil {
|
||||
fmt.eprintfln("failed to create build directory '%s': %v", build_dir, err)
|
||||
delete(build_dir, allocator)
|
||||
return "", false
|
||||
|
||||
@@ -2563,6 +2563,13 @@ build_command_is_recognized :: proc(t: ^testing.T) {
|
||||
testing.expect(t, !is_build_command("--build"))
|
||||
}
|
||||
|
||||
@(test)
|
||||
version_command_is_recognized :: proc(t: ^testing.T) {
|
||||
testing.expect(t, is_version_command("version"))
|
||||
testing.expect(t, !is_version_command("--version"))
|
||||
testing.expect(t, len(BROLANG_VERSION) > 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
build_subcommand_compiles_and_runs :: proc(t: ^testing.T) {
|
||||
output := "examples/build/hello/build/hello"
|
||||
@@ -2571,6 +2578,9 @@ build_subcommand_compiles_and_runs :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, status, 0)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
status = compiler_core.run_build("examples/build/hello")
|
||||
testing.expect_value(t, status, 0)
|
||||
testing.expect(t, os.exists(output))
|
||||
}
|
||||
|
||||
@(test)
|
||||
|
||||
@@ -11,6 +11,8 @@ import "core:os/os2"
|
||||
import "core:path/filepath"
|
||||
import "core:strings"
|
||||
|
||||
BROLANG_VERSION :: "0.0.0-dev"
|
||||
|
||||
Cli_Options :: struct {
|
||||
input_path: string,
|
||||
output_path: string,
|
||||
@@ -107,6 +109,9 @@ print_usage :: proc() {
|
||||
fmt.eprintln(
|
||||
" brolang init",
|
||||
)
|
||||
fmt.eprintln(
|
||||
" brolang version",
|
||||
)
|
||||
}
|
||||
|
||||
is_translate_c_command :: proc(arg: string) -> bool {
|
||||
@@ -125,6 +130,10 @@ is_init_command :: proc(arg: string) -> bool {
|
||||
return arg == "init"
|
||||
}
|
||||
|
||||
is_version_command :: proc(arg: string) -> bool {
|
||||
return arg == "version"
|
||||
}
|
||||
|
||||
template_root_valid :: proc(root: string) -> bool {
|
||||
std_build, std_error := filepath.join({root, "std", "build", "build.bro"})
|
||||
if std_error != nil {
|
||||
@@ -476,6 +485,14 @@ run_translate_c :: proc(args: []string) -> int {
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
if len(os2.args) >= 2 && is_version_command(os2.args[1]) {
|
||||
if len(os2.args) != 2 {
|
||||
print_usage()
|
||||
os2.exit(2)
|
||||
}
|
||||
fmt.printfln("brolang %s", BROLANG_VERSION)
|
||||
os2.exit(0)
|
||||
}
|
||||
if len(os2.args) >= 2 && is_build_command(os2.args[1]) {
|
||||
if len(os2.args) > 3 {
|
||||
print_usage()
|
||||
|
||||
Reference in New Issue
Block a user