mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Change the file name rules for imports (use / rather than \ on windows)
This commit is contained in:
@@ -443,6 +443,13 @@ String path_to_fullpath(gbAllocator a, String s) {
|
|||||||
text[len] = 0;
|
text[len] = 0;
|
||||||
result = string16_to_string(a, make_string16(text, len));
|
result = string16_to_string(a, make_string16(text, len));
|
||||||
result = string_trim_whitespace(result);
|
result = string_trim_whitespace(result);
|
||||||
|
|
||||||
|
// Replace Windows style separators
|
||||||
|
for (isize i = 0; i < result.len; i++) {
|
||||||
|
if (result[i] == '\\') {
|
||||||
|
result[i] = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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;
|
gb_memmove(str+i, path.text, path.len); i += path.len;
|
||||||
str[i] = 0;
|
str[i] = 0;
|
||||||
|
|
||||||
|
|
||||||
String res = make_string(str, i);
|
String res = make_string(str, i);
|
||||||
res = string_trim_whitespace(res);
|
res = string_trim_whitespace(res);
|
||||||
return path_to_fullpath(a, res);
|
return path_to_fullpath(a, res);
|
||||||
|
|||||||
+9
-1
@@ -740,7 +740,15 @@ String path_to_full_path(gbAllocator a, String path) {
|
|||||||
defer (gb_free(ha, path_c));
|
defer (gb_free(ha, path_c));
|
||||||
|
|
||||||
char *fullpath = gb_path_get_full_name(a, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+31
-11
@@ -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 = {};
|
String file_str = {};
|
||||||
if (colon_pos == 0) {
|
if (colon_pos == 0) {
|
||||||
syntax_error(node, "Expected a collection name");
|
error(node, "Expected a collection name");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4221,8 +4231,15 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
|
|||||||
file_str = original_string;
|
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;
|
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.len > 0) {
|
||||||
if (collection_name == "system") {
|
if (collection_name == "system") {
|
||||||
if (node->kind != Ast_ForeignImportDecl) {
|
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;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
*path = file_str;
|
*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)) {
|
} else if (!find_library_collection_path(collection_name, &base_dir)) {
|
||||||
// NOTE(bill): It's a naughty name
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -4270,10 +4287,12 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (has_windows_drive) {
|
||||||
String fullpath = string_trim_whitespace(get_fullpath_relative(a, base_dir, file_str));
|
*path = file_str;
|
||||||
*path = fullpath;
|
} else {
|
||||||
|
String fullpath = string_trim_whitespace(get_fullpath_relative(a, base_dir, file_str));
|
||||||
|
*path = fullpath;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4616,8 +4635,9 @@ GB_THREAD_PROC(parse_worker_file_proc) {
|
|||||||
ParseFileError parse_packages(Parser *p, String init_filename) {
|
ParseFileError parse_packages(Parser *p, String init_filename) {
|
||||||
GB_ASSERT(init_filename.text[init_filename.len] == 0);
|
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]);
|
// 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 = 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)) {
|
if (!path_is_directory(init_fullpath)) {
|
||||||
String const ext = str_lit(".odin");
|
String const ext = str_lit(".odin");
|
||||||
if (!string_ends_with(init_fullpath, ext)) {
|
if (!string_ends_with(init_fullpath, ext)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user