diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gn/filesystem_utils.cc | 2 | ||||
-rw-r--r-- | tools/gn/filesystem_utils.h | 1 | ||||
-rw-r--r-- | tools/gn/ninja_binary_target_writer.cc | 6 | ||||
-rw-r--r-- | tools/gn/ninja_binary_target_writer_unittest.cc | 12 | ||||
-rw-r--r-- | tools/gn/ninja_helper.cc | 15 |
5 files changed, 34 insertions, 2 deletions
diff --git a/tools/gn/filesystem_utils.cc b/tools/gn/filesystem_utils.cc index 0bc266d..6279964 100644 --- a/tools/gn/filesystem_utils.cc +++ b/tools/gn/filesystem_utils.cc @@ -181,6 +181,8 @@ SourceFileType GetSourceFileType(const SourceFile& file) { return SOURCE_RC; if (extension == "S" || extension == "s") return SOURCE_S; + if (extension == "o" || extension == "obj") + return SOURCE_O; return SOURCE_UNKNOWN; } diff --git a/tools/gn/filesystem_utils.h b/tools/gn/filesystem_utils.h index cb5fbfd..09451a5 100644 --- a/tools/gn/filesystem_utils.h +++ b/tools/gn/filesystem_utils.h @@ -26,6 +26,7 @@ enum SourceFileType { SOURCE_MM, SOURCE_S, SOURCE_RC, + SOURCE_O, // Object files can be inputs, too. Also counts .obj. }; SourceFileType GetSourceFileType(const SourceFile& file); diff --git a/tools/gn/ninja_binary_target_writer.cc b/tools/gn/ninja_binary_target_writer.cc index cbc5ff6..4c69c64 100644 --- a/tools/gn/ninja_binary_target_writer.cc +++ b/tools/gn/ninja_binary_target_writer.cc @@ -154,6 +154,12 @@ void NinjaBinaryTargetWriter::WriteSources( SourceFileType input_file_type = GetSourceFileType(input_file); if (input_file_type == SOURCE_UNKNOWN) continue; // Skip unknown file types. + if (input_file_type == SOURCE_O) { + // Object files just get passed to the output and not compiled. + object_files->push_back(helper_.GetOutputFileForSource( + target_, input_file, input_file_type)); + continue; + } std::string command = helper_.GetRuleForSourceType(settings_, input_file_type); if (command.empty()) diff --git a/tools/gn/ninja_binary_target_writer_unittest.cc b/tools/gn/ninja_binary_target_writer_unittest.cc index 94755c6..4f120c2 100644 --- a/tools/gn/ninja_binary_target_writer_unittest.cc +++ b/tools/gn/ninja_binary_target_writer_unittest.cc @@ -17,6 +17,10 @@ TEST(NinjaBinaryTargetWriter, SourceSet) { target.set_output_type(Target::SOURCE_SET); target.sources().push_back(SourceFile("//foo/input1.cc")); target.sources().push_back(SourceFile("//foo/input2.cc")); + // Also test object files, which should be just passed through to the + // dependents to link. + target.sources().push_back(SourceFile("//foo/input3.o")); + target.sources().push_back(SourceFile("//foo/input4.obj")); target.OnResolved(); // Source set itself. @@ -39,7 +43,8 @@ TEST(NinjaBinaryTargetWriter, SourceSet) { "build obj/foo/bar.input1.obj: cxx ../../foo/input1.cc\n" "build obj/foo/bar.input2.obj: cxx ../../foo/input2.cc\n" "\n" - "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.obj obj/foo/bar.input2.obj\n"; + "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.obj " + "obj/foo/bar.input2.obj ../../foo/input3.o ../../foo/input4.obj\n"; std::string out_str = out.str(); #if defined(OS_WIN) std::replace(out_str.begin(), out_str.end(), '\\', '/'); @@ -74,7 +79,10 @@ TEST(NinjaBinaryTargetWriter, SourceSet) { "ldflags = /MANIFEST /ManifestFile:obj/foo/shlib.intermediate." "manifest\n" "libs =\n" - "build shlib.dll shlib.dll.lib: solink obj/foo/bar.input1.obj " + // Ordering of the obj files here is arbitrary. Currently they're put + // in a set and come out sorted. + "build shlib.dll shlib.dll.lib: solink ../../foo/input3.o " + "../../foo/input4.obj obj/foo/bar.input1.obj " "obj/foo/bar.input2.obj\n" " soname = shlib.dll\n" " lib = shlib.dll\n" diff --git a/tools/gn/ninja_helper.cc b/tools/gn/ninja_helper.cc index 6ddacd0..0ea93016 100644 --- a/tools/gn/ninja_helper.cc +++ b/tools/gn/ninja_helper.cc @@ -86,6 +86,19 @@ OutputFile NinjaHelper::GetOutputFileForSource( name.append("res"); break; + // Pass .o/.obj files through unchanged. + case SOURCE_O: { + // System-absolute file names get preserved (they don't need to be + // rebased relative to the build dir). + if (source.is_system_absolute()) + return OutputFile(source.value()); + + // Construct the relative location of the file from the build dir. + OutputFile ret(build_to_src_no_last_slash()); + source.SourceAbsoluteWithOneSlash().AppendToString(&ret.value()); + return ret; + } + case SOURCE_H: case SOURCE_UNKNOWN: NOTREACHED(); @@ -224,5 +237,7 @@ std::string NinjaHelper::GetRuleForSourceType(const Settings* settings, // TODO(brettw) asm files. + // .obj files have no rules to make them (they're already built) so we return + // the enpty string for SOURCE_O. return std::string(); } |