diff --git a/compiler/build.odin b/compiler/build.odin index b1803c0..a57a328 100644 --- a/compiler/build.odin +++ b/compiler/build.odin @@ -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 diff --git a/compiler_tests.odin b/compiler_tests.odin index 00c3b20..4c116d0 100644 --- a/compiler_tests.odin +++ b/compiler_tests.odin @@ -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) diff --git a/main.odin b/main.odin index c3357d8..85b6d64 100644 --- a/main.odin +++ b/main.odin @@ -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()