aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-07-01 17:14:43 +0100
committergingerBill <bill@gingerbill.org>2018-07-01 17:14:43 +0100
commitbc37bd5429482bbcee00850f2f571c279f62dbda (patch)
tree7de1a2dbf3951cc9f3a253ed41f6feec4112b7e9 /src
parent5f20e042591be5fe9c0ca9e8603b03c190d61483 (diff)
parentcdf873542b60c7e67d388117f96df87e72140651 (diff)
Merge branch 'packages' of https://github.com/odin-lang/Odin into packages
Diffstat (limited to 'src')
-rw-r--r--src/build_settings.cpp14
-rw-r--r--src/common.cpp64
2 files changed, 70 insertions, 8 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp
index 5b3d846cb..ee4466698 100644
--- a/src/build_settings.cpp
+++ b/src/build_settings.cpp
@@ -150,8 +150,10 @@ TargetArchKind get_target_arch_from_string(String str) {
return TargetArch_Invalid;
}
+
bool is_excluded_target_filename(String name) {
String const ext = str_lit(".odin");
+ String original_name = name;
GB_ASSERT(string_ends_with(name, ext));
name = substring(name, 0, name.len-ext.len);
@@ -166,7 +168,7 @@ bool is_excluded_target_filename(String name) {
}
str1 = substring(str1, n, str1.len);
- str2 = str1;
+ str2 = substring(name, 0, gb_max(n-1, 0));
n = str2.len;
for (isize i = str2.len-1; i >= 0 && str2[i] != '_'; i--) {
n -= 1;
@@ -177,29 +179,25 @@ bool is_excluded_target_filename(String name) {
return false;
}
-
-
TargetOsKind os1 = get_target_os_from_string(str1);
TargetArchKind arch1 = get_target_arch_from_string(str1);
TargetOsKind os2 = get_target_os_from_string(str2);
TargetArchKind arch2 = get_target_arch_from_string(str2);
- if (arch1 != TargetArch_Invalid && os2 != TargetOs_Invalid) {
+ if (os1 != TargetOs_Invalid && arch2 != TargetArch_Invalid) {
+ return os1 != build_context.metrics.os || arch2 != build_context.metrics.arch;
+ } else if (arch1 != TargetArch_Invalid && os2 != TargetOs_Invalid) {
return arch1 != build_context.metrics.arch || os2 != build_context.metrics.os;
- } else if (arch1 != TargetArch_Invalid && os1 != TargetOs_Invalid) {
- return arch2 != build_context.metrics.arch || os1 != build_context.metrics.os;
} else if (os1 != TargetOs_Invalid) {
return os1 != build_context.metrics.os;
} else if (arch1 != TargetArch_Invalid) {
return arch1 != build_context.metrics.arch;
}
-
return false;
}
-
struct LibraryCollections {
String name;
String path;
diff --git a/src/common.cpp b/src/common.cpp
index 12c3457ac..ec6ec7798 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -822,7 +822,71 @@ ReadDirectoryError read_directory(String path, Array<FileInfo> *fi) {
return ReadDirectory_None;
}
+#elif defined(GB_SYSTEM_LINUX)
+
+#include <dirent.h>
+
+ReadDirectoryError read_directory(String path, Array<FileInfo> *fi) {
+ GB_ASSERT(fi != nullptr);
+
+ gbAllocator a = heap_allocator();
+
+ char *c_path = alloc_cstring(a, path);
+ defer (gb_free(a, c_path));
+
+ DIR *dir = opendir(c_path);
+ if (!dir) {
+ return ReadDirectory_NotDir;
+ }
+
+ array_init(fi, a, 0, 100);
+ for (;;) {
+ struct dirent *entry = readdir(dir);
+ if (entry == nullptr) {
+ break;
+ }
+
+ String name = make_string_c(entry->d_name);
+ if (name == "." || name == "..") {
+ continue;
+ }
+
+ String filepath = {};
+ filepath.len = path.len+1+name.len;
+ filepath.text = gb_alloc_array(a, u8, filepath.len+1);
+ defer (gb_free(a, filepath.text));
+ gb_memmove(filepath.text, path.text, path.len);
+ gb_memmove(filepath.text+path.len, "/", 1);
+ gb_memmove(filepath.text+path.len+1, name.text, name.len);
+ filepath.text[filepath.len] = 0;
+
+
+ struct stat dir_stat = {};
+
+ if (stat((char *)filepath.text, &dir_stat)) {
+ continue;
+ }
+
+ if (S_ISDIR(dir_stat.st_mode)) {
+ continue;
+ }
+
+ i64 size = dir_stat.st_size;
+
+ FileInfo info = {};
+ info.name = name;
+ info.fullpath = path_to_full_path(a, filepath);
+ info.size = size;
+ array_add(fi, info);
+ }
+
+ if (fi->count == 0) {
+ return ReadDirectory_Empty;
+ }
+
+ return ReadDirectory_None;
+}
#else
#error Implement read_directory
#endif