| Index: tools/gn/ninja_create_bundle_target_writer.cc
|
| diff --git a/tools/gn/ninja_create_bundle_target_writer.cc b/tools/gn/ninja_create_bundle_target_writer.cc
|
| index 26701e50db59e6a886ae516aadaaf9ac5480129b..351ec0c883e91666e1861fa1e51b82ed69ed1511 100644
|
| --- a/tools/gn/ninja_create_bundle_target_writer.cc
|
| +++ b/tools/gn/ninja_create_bundle_target_writer.cc
|
| @@ -57,13 +57,10 @@ void NinjaCreateBundleTargetWriter::Run() {
|
|
|
| std::string code_signing_rule_name = WriteCodeSigningRuleDefinition();
|
|
|
| - OutputFile input_dep =
|
| - WriteInputDepsStampAndGetDep(std::vector<const Target*>());
|
| -
|
| std::vector<OutputFile> output_files;
|
| - WriteCopyBundleDataRules(input_dep, &output_files);
|
| - WriteCompileAssetsCatalogRule(input_dep, &output_files);
|
| - WriteCodeSigningRules(code_signing_rule_name, input_dep, &output_files);
|
| + WriteCopyBundleDataSteps(&output_files);
|
| + WriteCompileAssetsCatalogStep(&output_files);
|
| + WriteCodeSigningStep(code_signing_rule_name, &output_files);
|
|
|
| std::vector<OutputFile> order_only_deps;
|
| for (const auto& pair : target_->data_deps())
|
| @@ -113,37 +110,41 @@ std::string NinjaCreateBundleTargetWriter::WriteCodeSigningRuleDefinition() {
|
| return custom_rule_name;
|
| }
|
|
|
| -void NinjaCreateBundleTargetWriter::WriteCopyBundleDataRules(
|
| - const OutputFile& input_dep,
|
| +void NinjaCreateBundleTargetWriter::WriteCopyBundleDataSteps(
|
| std::vector<OutputFile>* output_files) {
|
| - for (const BundleFileRule& file_rule : target_->bundle_data().file_rules()) {
|
| - for (const SourceFile& source_file : file_rule.sources()) {
|
| - OutputFile output_file = file_rule.ApplyPatternToSourceAsOutputFile(
|
| - settings_, target_->bundle_data(), source_file);
|
| - output_files->push_back(output_file);
|
| -
|
| - out_ << "build ";
|
| - path_output_.WriteFile(out_, output_file);
|
| - out_ << ": "
|
| - << GetNinjaRulePrefixForToolchain(settings_)
|
| - << Toolchain::ToolTypeToName(Toolchain::TYPE_COPY_BUNDLE_DATA)
|
| - << " ";
|
| - path_output_.WriteFile(out_, source_file);
|
| - if (!input_dep.value().empty()) {
|
| - out_ << " | ";
|
| - path_output_.WriteFile(out_, input_dep);
|
| - }
|
| - out_ << std::endl;
|
| - }
|
| + for (const BundleFileRule& file_rule : target_->bundle_data().file_rules())
|
| + WriteCopyBundleFileRuleSteps(file_rule, output_files);
|
| +}
|
| +
|
| +void NinjaCreateBundleTargetWriter::WriteCopyBundleFileRuleSteps(
|
| + const BundleFileRule& file_rule,
|
| + std::vector<OutputFile>* output_files) {
|
| + // Note that we don't write implicit deps for copy steps. "copy_bundle_data"
|
| + // steps as this is most likely implemented using hardlink in the common case.
|
| + // See NinjaCopyTargetWriter::WriteCopyRules() for a detailed explanation.
|
| + for (const SourceFile& source_file : file_rule.sources()) {
|
| + OutputFile output_file = file_rule.ApplyPatternToSourceAsOutputFile(
|
| + settings_, target_->bundle_data(), source_file);
|
| + output_files->push_back(output_file);
|
| +
|
| + out_ << "build ";
|
| + path_output_.WriteFile(out_, output_file);
|
| + out_ << ": " << GetNinjaRulePrefixForToolchain(settings_)
|
| + << Toolchain::ToolTypeToName(Toolchain::TYPE_COPY_BUNDLE_DATA) << " ";
|
| + path_output_.WriteFile(out_, source_file);
|
| + out_ << std::endl;
|
| }
|
| }
|
|
|
| -void NinjaCreateBundleTargetWriter::WriteCompileAssetsCatalogRule(
|
| - const OutputFile& input_dep,
|
| +void NinjaCreateBundleTargetWriter::WriteCompileAssetsCatalogStep(
|
| std::vector<OutputFile>* output_files) {
|
| - if (target_->bundle_data().asset_catalog_sources().empty())
|
| + if (target_->bundle_data().assets_catalog_sources().empty())
|
| return;
|
|
|
| + OutputFile input_dep = WriteCompileAssetsCatalogInputDepsStamp(
|
| + target_->bundle_data().assets_catalog_deps());
|
| + DCHECK(!input_dep.value().empty());
|
| +
|
| OutputFile output_file(settings_->build_settings(),
|
| target_->bundle_data().GetCompiledAssetCatalogPath());
|
| output_files->push_back(output_file);
|
| @@ -154,40 +155,53 @@ void NinjaCreateBundleTargetWriter::WriteCompileAssetsCatalogRule(
|
| << Toolchain::ToolTypeToName(Toolchain::TYPE_COMPILE_XCASSETS);
|
|
|
| std::set<SourceFile> asset_catalog_bundles;
|
| - for (const auto& source : target_->bundle_data().asset_catalog_sources()) {
|
| - SourceFile asset_catalog_bundle;
|
| - CHECK(IsSourceFileFromAssetCatalog(source, &asset_catalog_bundle));
|
| - if (asset_catalog_bundles.find(asset_catalog_bundle) !=
|
| - asset_catalog_bundles.end())
|
| - continue;
|
| + for (const auto& source : target_->bundle_data().assets_catalog_sources()) {
|
| out_ << " ";
|
| - path_output_.WriteFile(out_, asset_catalog_bundle);
|
| - asset_catalog_bundles.insert(asset_catalog_bundle);
|
| + path_output_.WriteFile(out_, source);
|
| + asset_catalog_bundles.insert(source);
|
| }
|
|
|
| - out_ << " |";
|
| - for (const auto& source : target_->bundle_data().asset_catalog_sources()) {
|
| - out_ << " ";
|
| - path_output_.WriteFile(
|
| - out_, OutputFile(settings_->build_settings(), source));
|
| - }
|
| + out_ << " | ";
|
| + path_output_.WriteFile(out_, input_dep);
|
| + out_ << std::endl;
|
| +}
|
|
|
| - if (!input_dep.value().empty()) {
|
| +OutputFile
|
| +NinjaCreateBundleTargetWriter::WriteCompileAssetsCatalogInputDepsStamp(
|
| + const std::vector<const Target*>& dependencies) {
|
| + DCHECK(!dependencies.empty());
|
| + if (dependencies.size() == 1)
|
| + return dependencies[0]->dependency_output_file();
|
| +
|
| + OutputFile xcassets_input_stamp_file =
|
| + OutputFile(RebasePath(GetTargetOutputDir(target_).value(),
|
| + settings_->build_settings()->build_dir(),
|
| + settings_->build_settings()->root_path_utf8()));
|
| + xcassets_input_stamp_file.value().append(target_->label().name());
|
| + xcassets_input_stamp_file.value().append(".xcassets.inputdeps.stamp");
|
| +
|
| + out_ << "build ";
|
| + path_output_.WriteFile(out_, xcassets_input_stamp_file);
|
| + out_ << ": " << GetNinjaRulePrefixForToolchain(settings_)
|
| + << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP);
|
| +
|
| + for (const Target* target : dependencies) {
|
| out_ << " ";
|
| - path_output_.WriteFile(out_, input_dep);
|
| + path_output_.WriteFile(out_, target->dependency_output_file());
|
| }
|
| out_ << std::endl;
|
| + return xcassets_input_stamp_file;
|
| }
|
|
|
| -void NinjaCreateBundleTargetWriter::WriteCodeSigningRules(
|
| +void NinjaCreateBundleTargetWriter::WriteCodeSigningStep(
|
| const std::string& code_signing_rule_name,
|
| - const OutputFile& input_dep,
|
| std::vector<OutputFile>* output_files) {
|
| if (code_signing_rule_name.empty())
|
| return;
|
|
|
| OutputFile code_signing_input_stamp_file =
|
| - WriteCodeSigningInputDepsStamp(input_dep, output_files);
|
| + WriteCodeSigningInputDepsStamp(output_files);
|
| + DCHECK(!code_signing_input_stamp_file.value().empty());
|
|
|
| out_ << "build";
|
| std::vector<OutputFile> code_signing_output_files;
|
| @@ -197,19 +211,17 @@ void NinjaCreateBundleTargetWriter::WriteCodeSigningRules(
|
| path_output_.WriteFiles(out_, code_signing_output_files);
|
|
|
| // Since the code signature step depends on all the files from the bundle,
|
| - // the create_bundle stamp can just depends on the output of the signature.
|
| + // the create_bundle stamp can just depends on the output of the signature
|
| + // script (dependencies are transitive).
|
| output_files->swap(code_signing_output_files);
|
|
|
| out_ << ": " << code_signing_rule_name;
|
| - if (!code_signing_input_stamp_file.value().empty()) {
|
| - out_ << " | ";
|
| - path_output_.WriteFile(out_, code_signing_input_stamp_file);
|
| - }
|
| + out_ << " | ";
|
| + path_output_.WriteFile(out_, code_signing_input_stamp_file);
|
| out_ << std::endl;
|
| }
|
|
|
| OutputFile NinjaCreateBundleTargetWriter::WriteCodeSigningInputDepsStamp(
|
| - const OutputFile& input_dep,
|
| std::vector<OutputFile>* output_files) {
|
| std::vector<SourceFile> code_signing_input_files;
|
| code_signing_input_files.push_back(
|
| @@ -222,15 +234,32 @@ OutputFile NinjaCreateBundleTargetWriter::WriteCodeSigningInputDepsStamp(
|
| code_signing_input_files.push_back(
|
| output_file.AsSourceFile(settings_->build_settings()));
|
| }
|
| - if (!input_dep.value().empty()) {
|
| - code_signing_input_files.push_back(
|
| - input_dep.AsSourceFile(settings_->build_settings()));
|
| +
|
| + std::vector<const Target*> dependencies;
|
| + for (const auto& label_target_pair : target_->private_deps()) {
|
| + if (label_target_pair.ptr->output_type() == Target::BUNDLE_DATA)
|
| + continue;
|
| + dependencies.push_back(label_target_pair.ptr);
|
| + }
|
| + for (const auto& label_target_pair : target_->public_deps()) {
|
| + if (label_target_pair.ptr->output_type() == Target::BUNDLE_DATA)
|
| + continue;
|
| + dependencies.push_back(label_target_pair.ptr);
|
| }
|
|
|
| DCHECK(!code_signing_input_files.empty());
|
| - if (code_signing_input_files.size() == 1)
|
| + if (code_signing_input_files.size() == 1 && dependencies.empty())
|
| return OutputFile(settings_->build_settings(), code_signing_input_files[0]);
|
|
|
| + // Remove possible duplicates (if a target is listed in both deps and
|
| + // public_deps.
|
| + std::sort(dependencies.begin(), dependencies.end(),
|
| + [](const Target* lhs, const Target* rhs) -> bool {
|
| + return lhs->label() < rhs->label();
|
| + });
|
| + dependencies.erase(std::unique(dependencies.begin(), dependencies.end()),
|
| + dependencies.end());
|
| +
|
| OutputFile code_signing_input_stamp_file =
|
| OutputFile(RebasePath(GetTargetOutputDir(target_).value(),
|
| settings_->build_settings()->build_dir(),
|
| @@ -247,6 +276,10 @@ OutputFile NinjaCreateBundleTargetWriter::WriteCodeSigningInputDepsStamp(
|
| out_ << " ";
|
| path_output_.WriteFile(out_, source);
|
| }
|
| + for (const Target* target : dependencies) {
|
| + out_ << " ";
|
| + path_output_.WriteFile(out_, target->dependency_output_file());
|
| + }
|
| out_ << std::endl;
|
| return code_signing_input_stamp_file;
|
| }
|
|
|