From ad0a413b40cc95e240f8a83fa21a709b4ab2b1bb Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Tue, 5 Apr 2022 20:26:18 +0200 Subject: Give build/run/check/test/doc a `-file` flag. A package has canonically always been a directory, but odin allowing you to build a single-file package confused newcomers who didn't understand why they could then not access variables and procedures from another file in the same directory. This change disallows building single-file packages by default, requiring the `-file` flag to acknowledge you understand the nuance. `-help` for these commands also clarifies the difference. ``` W:\Odin>odin build -help odin is a tool for managing Odin source code Usage: odin build [arguments] build Compile directory of .odin files as an executable. One must contain the program's entry point, all must be in the same package. Use `-file` to build a single file instead. Examples: odin build . # Build package in current directory odin build # Build package in odin build filename.odin -file # Build single-file package, must contain entry point. Flags -file Tells `odin build` to treat the given file as a self-contained package. This means that `/a.odin` won't have access to `/b.odin`'s contents. ``` ``` W:\Odin>odin run examples\demo\demo.odin ERROR: `odin run` takes a package as its first argument. Did you mean `odin run examples\demo\demo.odin -file`? The `-file` flag tells it to treat a file as a self-contained package. ``` --- src/build_settings.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/build_settings.cpp') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index b9875e43f..2f3eb03a5 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -598,7 +598,6 @@ bool allow_check_foreign_filepath(void) { return true; } - // TODO(bill): OS dependent versions for the BuildContext // join_path // is_dir @@ -606,6 +605,28 @@ bool allow_check_foreign_filepath(void) { // is_abs_path // has_subdir +enum TargetFileValidity : u8 { + TargetFileValidity_Invalid, + + TargetFileValidity_Writable_File, + TargetFileValidity_No_Write_Permission, + TargetFileValidity_Directory, + + TargetTargetFileValidity_COUNT, +}; + +TargetFileValidity set_output_filename(void) { + // Assembles the output filename from build_context information. + // Returns `true` if it doesn't exist or is a file. + // Returns `false` if a directory or write-protected file. + + + + + return TargetFileValidity_Writable_File; +} + + String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1}; String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1}; -- cgit v1.2.3