do not use tool prefix for phony rule This is to fix https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8737840748939434977/+/u/compile__with_patch_/stdout Bug: 42440099 Change-Id: Iddd5d446e8e13d0e8e24e96143ae2cf03e22da4b Reviewed-on: https://gn-review.googlesource.com/c/gn/+/17700 Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Reviewed-by: David Turner <digit@google.com> Commit-Queue: Takuto Ikuta <tikuta@google.com>
diff --git a/src/gn/ninja_create_bundle_target_writer.cc b/src/gn/ninja_create_bundle_target_writer.cc index 87f0ab7..09299c7 100644 --- a/src/gn/ninja_create_bundle_target_writer.cc +++ b/src/gn/ninja_create_bundle_target_writer.cc
@@ -395,12 +395,13 @@ GetBuildDirForTargetAsOutputFile(target_, BuildDirType::OBJ); stamp_or_phony.value().append(target_->label().name()); stamp_or_phony.value().append(".postprocessing.inputdeps.stamp"); - tool = GeneralTool::kGeneralToolStamp; + tool = GetNinjaRulePrefixForToolchain(settings_) + + GeneralTool::kGeneralToolStamp; } out_ << "build "; WriteOutput(stamp_or_phony); - out_ << ": " << GetNinjaRulePrefixForToolchain(settings_) << tool; + out_ << ": " << tool; for (const SourceFile& source : post_processing_input_files) { out_ << " ";
diff --git a/src/gn/ninja_create_bundle_target_writer_unittest.cc b/src/gn/ninja_create_bundle_target_writer_unittest.cc index 4397643..8540671 100644 --- a/src/gn/ninja_create_bundle_target_writer_unittest.cc +++ b/src/gn/ninja_create_bundle_target_writer_unittest.cc
@@ -493,3 +493,90 @@ std::string out_str = out.str(); EXPECT_EQ(expected, out_str); } + +TEST(NinjaCreateBundleTargetWriter, PostProcessingNoStampFilesCustomToolchain) { + Err err; + TestWithScope setup; + setup.build_settings()->set_no_stamp_files(true); + + Label other_toolchain_label(SourceDir("//other/"), "toolchain"); + setup.settings()->set_toolchain_label(other_toolchain_label); + + std::unique_ptr<Target> action = NewAction(setup); + ASSERT_TRUE(action->OnResolved(&err)) << err.message(); + + Target executable(setup.settings(), Label(SourceDir("//baz/"), "quz")); + executable.set_output_type(Target::EXECUTABLE); + executable.sources().push_back(SourceFile("//baz/quz.c")); + executable.SetToolchain(setup.toolchain()); + executable.visibility().SetPublic(); + ASSERT_TRUE(executable.OnResolved(&err)); + + Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data")); + bundle_data.set_output_type(Target::BUNDLE_DATA); + bundle_data.sources().push_back(SourceFile("//foo/input1.txt")); + bundle_data.sources().push_back(SourceFile("//foo/input2.txt")); + bundle_data.action_values().outputs() = SubstitutionList::MakeForTest( + "{{bundle_resources_dir}}/{{source_file_part}}"); + bundle_data.SetToolchain(setup.toolchain()); + bundle_data.visibility().SetPublic(); + ASSERT_TRUE(bundle_data.OnResolved(&err)); + + Target create_bundle( + setup.settings(), + Label(SourceDir("//baz/"), "bar", setup.toolchain()->label().dir(), + setup.toolchain()->label().name())); + SetupBundleDataDir(&create_bundle.bundle_data(), "//out/Debug"); + create_bundle.set_output_type(Target::CREATE_BUNDLE); + create_bundle.bundle_data().set_post_processing_script( + SourceFile("//build/codesign.py")); + create_bundle.bundle_data().post_processing_sources().push_back( + SourceFile("//out/Debug/quz")); + create_bundle.bundle_data().post_processing_outputs() = + SubstitutionList::MakeForTest( + "//out/Debug/bar.bundle/Contents/quz", + "//out/Debug/bar.bundle/_CodeSignature/CodeResources"); + create_bundle.bundle_data().post_processing_args() = + SubstitutionList::MakeForTest("-b=quz", "bar.bundle"); + create_bundle.public_deps().push_back(LabelTargetPair(&executable)); + create_bundle.private_deps().push_back(LabelTargetPair(&bundle_data)); + create_bundle.private_deps().push_back(LabelTargetPair(action.get())); + create_bundle.SetToolchain(setup.toolchain()); + ASSERT_TRUE(create_bundle.OnResolved(&err)); + + std::ostringstream out; + NinjaCreateBundleTargetWriter writer(&create_bundle, out); + writer.Run(); + + const char expected[] = + "build toolchain/phony/baz/bar.inputdeps: phony ./quz " + "toolchain/phony/foo/bar " + "toolchain/phony/foo/data\n" + "rule __baz_bar___toolchain_default__post_processing_rule\n" + " command = ../../build/codesign.py -b=quz bar.bundle\n" + " description = POST PROCESSING //baz:bar(//toolchain:default)\n" + " restat = 1\n" + "\n" + "build bar.bundle/Contents/Resources/input1.txt: " + "toolchain_copy_bundle_data " + "../../foo/input1.txt || toolchain/phony/baz/bar.inputdeps\n" + "build bar.bundle/Contents/Resources/input2.txt: " + "toolchain_copy_bundle_data " + "../../foo/input2.txt || toolchain/phony/baz/bar.inputdeps\n" + "build toolchain/phony/baz/bar.postprocessing.inputdeps: phony " + "../../build/codesign.py " + "quz " + "bar.bundle/Contents/Resources/input1.txt " + "bar.bundle/Contents/Resources/input2.txt || " + "toolchain/phony/baz/bar.inputdeps\n" + "build bar.bundle/Contents/quz bar.bundle/_CodeSignature/CodeResources: " + "__baz_bar___toolchain_default__post_processing_rule " + "| toolchain/phony/baz/bar.postprocessing.inputdeps\n" + "build toolchain/phony/baz/bar: phony " + "bar.bundle/Contents/quz " + "bar.bundle/_CodeSignature/CodeResources || " + "toolchain/phony/baz/bar.inputdeps\n" + "build bar.bundle: phony toolchain/phony/baz/bar\n"; + std::string out_str = out.str(); + EXPECT_EQ(expected, out_str) << expected << "\n" << out_str; +}