aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-04-20 16:47:28 +0100
committergingerBill <bill@gingerbill.org>2019-04-20 16:47:28 +0100
commit63bbb9b62fe60765b9101e3622592a2ab120a06d (patch)
tree8b780826b1ab79edd8d8372d5cb4866dec3bfa65
parent56c4039e72e569448e8d2fc79a40245e1dc13efa (diff)
Change the file name rules for imports (use / rather than \ on windows)
-rw-r--r--src/build_settings.cpp8
-rw-r--r--src/common.cpp10
-rw-r--r--src/parser.cpp42
3 files changed, 48 insertions, 12 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp
index 2b8f99e4c..d3e892175 100644
--- a/src/build_settings.cpp
+++ b/src/build_settings.cpp
@@ -443,6 +443,13 @@ String path_to_fullpath(gbAllocator a, String s) {
text[len] = 0;
result = string16_to_string(a, make_string16(text, len));
result = string_trim_whitespace(result);
+
+ // Replace Windows style separators
+ for (isize i = 0; i < result.len; i++) {
+ if (result[i] == '\\') {
+ result[i] = '/';
+ }
+ }
}
return result;
@@ -471,6 +478,7 @@ String get_fullpath_relative(gbAllocator a, String base_dir, String path) {
gb_memmove(str+i, path.text, path.len); i += path.len;
str[i] = 0;
+
String res = make_string(str, i);
res = string_trim_whitespace(res);
return path_to_fullpath(a, res);
diff --git a/src/common.cpp b/src/common.cpp
index b3169e89f..ed1fd16e2 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -740,7 +740,15 @@ String path_to_full_path(gbAllocator a, String path) {
defer (gb_free(ha, path_c));
char *fullpath = gb_path_get_full_name(a, path_c);
- return make_string_c(fullpath);
+ String res = string_trim_whitespace(make_string_c(fullpath));
+#if defined(GB_SYSTEM_WINDOWS)
+ for (isize i = 0; i < res.len; i++) {
+ if (res[i] == '\\') {
+ res[i] = '/';
+ }
+ }
+#endif
+ return res;
}
diff --git a/src/parser.cpp b/src/parser.cpp
index ae346b52f..d17efd092 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -4208,9 +4208,19 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
}
}
+ bool has_windows_drive = false;
+#if defined(GB_SYSTEM_WINDOWS)
+ if (colon_pos == 1 && original_string.len > 2) {
+ if (original_string[2] == '/' || original_string[2] == '\\') {
+ colon_pos = -1;
+ has_windows_drive = true;
+ }
+ }
+#endif
+
String file_str = {};
if (colon_pos == 0) {
- syntax_error(node, "Expected a collection name");
+ error(node, "Expected a collection name");
return false;
}
@@ -4221,8 +4231,15 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
file_str = original_string;
}
- if (!is_import_path_valid(file_str)) {
- syntax_error(node, "Invalid import path: '%.*s'", LIT(file_str));
+
+ if (has_windows_drive) {
+ String sub_file_path = substring(file_str, 3, file_str.len);
+ if (!is_import_path_valid(sub_file_path)) {
+ error(node, "Invalid import path: '%.*s'", LIT(file_str));
+ return false;
+ }
+ } else if (!is_import_path_valid(file_str)) {
+ error(node, "Invalid import path: '%.*s'", LIT(file_str));
return false;
}
@@ -4243,7 +4260,7 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
if (collection_name.len > 0) {
if (collection_name == "system") {
if (node->kind != Ast_ForeignImportDecl) {
- syntax_error(node, "The library collection 'system' is restrict for 'foreign_library'");
+ error(node, "The library collection 'system' is restrict for 'foreign_library'");
return false;
} else {
*path = file_str;
@@ -4251,7 +4268,7 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
}
} else if (!find_library_collection_path(collection_name, &base_dir)) {
// NOTE(bill): It's a naughty name
- syntax_error(node, "Unknown library collection: '%.*s'", LIT(collection_name));
+ error(node, "Unknown library collection: '%.*s'", LIT(collection_name));
return false;
}
} else {
@@ -4270,10 +4287,12 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
#endif
}
-
- String fullpath = string_trim_whitespace(get_fullpath_relative(a, base_dir, file_str));
- *path = fullpath;
-
+ if (has_windows_drive) {
+ *path = file_str;
+ } else {
+ String fullpath = string_trim_whitespace(get_fullpath_relative(a, base_dir, file_str));
+ *path = fullpath;
+ }
return true;
}
@@ -4616,8 +4635,9 @@ GB_THREAD_PROC(parse_worker_file_proc) {
ParseFileError parse_packages(Parser *p, String init_filename) {
GB_ASSERT(init_filename.text[init_filename.len] == 0);
- char *fullpath_str = gb_path_get_full_name(heap_allocator(), cast(char const *)&init_filename[0]);
- String init_fullpath = string_trim_whitespace(make_string_c(fullpath_str));
+ // char *fullpath_str = gb_path_get_full_name(heap_allocator(), cast(char const *)&init_filename[0]);
+ // String init_fullpath = string_trim_whitespace(make_string_c(fullpath_str));
+ String init_fullpath = path_to_full_path(heap_allocator(), init_filename);
if (!path_is_directory(init_fullpath)) {
String const ext = str_lit(".odin");
if (!string_ends_with(init_fullpath, ext)) {