浏览代码

Allow precompiled resources with -resource:foo.res

And add them to the magic new feature.
Jeroen van Rijn 1 年之前
父节点
当前提交
cc73e06a46
共有 3 个文件被更改,包括 21 次插入8 次删除
  1. 11 0
      src/cached.cpp
  2. 3 8
      src/linker.cpp
  3. 7 0
      src/path.cpp

+ 11 - 0
src/cached.cpp

@@ -200,6 +200,17 @@ gb_internal bool try_cached_build(Checker *c, Array<String> const &args) {
 		}
 	}
 
+	// Add Windows resource file to file list, if applicable
+	if (build_context.has_resource) {
+		String res_path = {};
+		if (build_context.build_paths[BuildPath_RC].basename == "")  {
+			res_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RES]);
+		} else {
+			res_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RC]);
+		}
+		array_add(&files, res_path);
+	}
+
 	for (auto const &entry : c->info.load_file_cache) {
 		auto *cache = entry.value;
 		if (!cache || !cache->exists) {

+ 3 - 8
src/linker.cpp

@@ -305,18 +305,13 @@ gb_internal i32 linker_stage(LinkerData *gen) {
 			defer (gb_free(heap_allocator(), windows_sdk_bin_path.text));
 
 			if (!build_context.use_lld) { // msvc
-				String temp_res_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RES]);
-				String temp_rc_path  = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RC]);
-				defer (gb_free(heap_allocator(), temp_res_path.text));
-				defer (gb_free(heap_allocator(), temp_rc_path.text));
-
-				String res_path = concatenate3_strings(heap_allocator(), str_lit("\""), temp_res_path, str_lit("\""));
-				String rc_path  = concatenate3_strings(heap_allocator(), str_lit("\""), temp_rc_path,  str_lit("\""));
+				String res_path = quote_path(heap_allocator(), build_context.build_paths[BuildPath_RES]);
+				String rc_path  = quote_path(heap_allocator(), build_context.build_paths[BuildPath_RC]);
 				defer (gb_free(heap_allocator(), res_path.text));
 				defer (gb_free(heap_allocator(), rc_path.text));
 
 				if (build_context.has_resource) {
-					if (temp_rc_path == "")  {
+					if (build_context.build_paths[BuildPath_RC].basename == "")  {
 						debugf("Using precompiled resource %.*s\n", LIT(res_path));
 					} else {
 						debugf("Compiling resource %.*s\n", LIT(res_path));

+ 7 - 0
src/path.cpp

@@ -152,6 +152,13 @@ gb_internal String path_to_string(gbAllocator a, Path path) {
 	return res;
 }
 
+gb_internal String quote_path(gbAllocator a, Path path) {
+	String temp   = path_to_string(a, path);
+	String quoted = concatenate3_strings(a, str_lit("\""), temp, str_lit("\""));
+	gb_free(a, temp.text);
+	return quoted;
+}
+
 // NOTE(Jeroen): Naively turns a Path into a string, then normalizes it using `path_to_full_path`.
 gb_internal String path_to_full_path(gbAllocator a, Path path) {
 	String temp = path_to_string(heap_allocator(), path);