| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/bundle_data.h" | 5 #include "tools/gn/bundle_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "tools/gn/output_file.h" | 8 #include "tools/gn/output_file.h" |
| 9 #include "tools/gn/settings.h" | 9 #include "tools/gn/settings.h" |
| 10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 std::string asset_catalog_path = dir.as_string(); | 36 std::string asset_catalog_path = dir.as_string(); |
| 37 *asset_catalog = SourceFile(SourceFile::SWAP_IN, &asset_catalog_path); | 37 *asset_catalog = SourceFile(SourceFile::SWAP_IN, &asset_catalog_path); |
| 38 } | 38 } |
| 39 return true; | 39 return true; |
| 40 } | 40 } |
| 41 | 41 |
| 42 BundleData::BundleData() {} | 42 BundleData::BundleData() {} |
| 43 | 43 |
| 44 BundleData::~BundleData() {} | 44 BundleData::~BundleData() {} |
| 45 | 45 |
| 46 void BundleData::AddFileRuleFromTarget(const Target* target) { | 46 void BundleData::AddBundleData(const Target* target) { |
| 47 DCHECK_EQ(target->output_type(), Target::BUNDLE_DATA); | 47 DCHECK_EQ(target->output_type(), Target::BUNDLE_DATA); |
| 48 bundle_deps_.push_back(target); |
| 49 } |
| 48 | 50 |
| 49 std::vector<SourceFile> file_rule_sources; | 51 void BundleData::OnTargetResolved(Target* owning_target) { |
| 50 for (const SourceFile& source_file : target->sources()) { | 52 // Only initialize file_rules_ and asset_catalog_sources for "create_bundle" |
| 51 if (IsSourceFileFromAssetCatalog(source_file, nullptr)) { | 53 // target (properties are only used by those targets). |
| 52 asset_catalog_sources_.push_back(source_file); | 54 if (owning_target->output_type() != Target::CREATE_BUNDLE) |
| 53 } else { | 55 return; |
| 54 file_rule_sources.push_back(source_file); | 56 |
| 57 for (const Target* target : bundle_deps_) { |
| 58 SourceFiles file_rule_sources; |
| 59 for (const SourceFile& source_file : target->sources()) { |
| 60 if (IsSourceFileFromAssetCatalog(source_file, nullptr)) { |
| 61 asset_catalog_sources_.push_back(source_file); |
| 62 } else { |
| 63 file_rule_sources.push_back(source_file); |
| 64 } |
| 65 } |
| 66 |
| 67 if (!file_rule_sources.empty()) { |
| 68 DCHECK_EQ(target->action_values().outputs().list().size(), 1u); |
| 69 file_rules_.push_back(BundleFileRule( |
| 70 file_rule_sources, target->action_values().outputs().list()[0])); |
| 55 } | 71 } |
| 56 } | 72 } |
| 57 | 73 |
| 58 if (!file_rule_sources.empty()) { | 74 GetSourceFiles(&owning_target->sources()); |
| 59 DCHECK_EQ(target->action_values().outputs().list().size(), 1u); | |
| 60 file_rules_.push_back(BundleFileRule( | |
| 61 file_rule_sources, target->action_values().outputs().list()[0])); | |
| 62 } | |
| 63 } | 75 } |
| 64 | 76 |
| 65 void BundleData::GetSourceFiles(std::vector<SourceFile>* sources) const { | 77 void BundleData::GetSourceFiles(SourceFiles* sources) const { |
| 66 for (const BundleFileRule& file_rule : file_rules_) { | 78 for (const BundleFileRule& file_rule : file_rules_) { |
| 67 sources->insert(sources->end(), file_rule.sources().begin(), | 79 sources->insert(sources->end(), file_rule.sources().begin(), |
| 68 file_rule.sources().end()); | 80 file_rule.sources().end()); |
| 69 } | 81 } |
| 70 sources->insert(sources->end(), asset_catalog_sources_.begin(), | 82 sources->insert(sources->end(), asset_catalog_sources_.begin(), |
| 71 asset_catalog_sources_.end()); | 83 asset_catalog_sources_.end()); |
| 72 } | 84 } |
| 73 | 85 |
| 74 void BundleData::GetOutputFiles(const Settings* settings, | 86 void BundleData::GetOutputFiles(const Settings* settings, |
| 75 std::vector<OutputFile>* outputs) const { | 87 OutputFiles* outputs) const { |
| 76 std::vector<SourceFile> outputs_as_sources; | 88 SourceFiles outputs_as_sources; |
| 77 GetOutputsAsSourceFiles(settings, &outputs_as_sources); | 89 GetOutputsAsSourceFiles(settings, &outputs_as_sources); |
| 78 for (const SourceFile& source_file : outputs_as_sources) | 90 for (const SourceFile& source_file : outputs_as_sources) |
| 79 outputs->push_back(OutputFile(settings->build_settings(), source_file)); | 91 outputs->push_back(OutputFile(settings->build_settings(), source_file)); |
| 80 } | 92 } |
| 81 | 93 |
| 82 void BundleData::GetOutputsAsSourceFiles( | 94 void BundleData::GetOutputsAsSourceFiles( |
| 83 const Settings* settings, | 95 const Settings* settings, |
| 84 std::vector<SourceFile>* outputs_as_source) const { | 96 SourceFiles* outputs_as_source) const { |
| 85 for (const BundleFileRule& file_rule : file_rules_) { | 97 for (const BundleFileRule& file_rule : file_rules_) { |
| 86 for (const SourceFile& source : file_rule.sources()) { | 98 for (const SourceFile& source : file_rule.sources()) { |
| 87 outputs_as_source->push_back( | 99 outputs_as_source->push_back( |
| 88 file_rule.ApplyPatternToSource(settings, *this, source)); | 100 file_rule.ApplyPatternToSource(settings, *this, source)); |
| 89 } | 101 } |
| 90 } | 102 } |
| 91 | 103 |
| 92 if (!asset_catalog_sources_.empty()) | 104 if (!asset_catalog_sources_.empty()) |
| 93 outputs_as_source->push_back(GetCompiledAssetCatalogPath()); | 105 outputs_as_source->push_back(GetCompiledAssetCatalogPath()); |
| 94 } | 106 } |
| 95 | 107 |
| 96 SourceFile BundleData::GetCompiledAssetCatalogPath() const { | 108 SourceFile BundleData::GetCompiledAssetCatalogPath() const { |
| 97 DCHECK(!asset_catalog_sources_.empty()); | 109 DCHECK(!asset_catalog_sources_.empty()); |
| 98 std::string assets_car_path = resources_dir_ + "/Assets.car"; | 110 std::string assets_car_path = resources_dir_ + "/Assets.car"; |
| 99 return SourceFile(SourceFile::SWAP_IN, &assets_car_path); | 111 return SourceFile(SourceFile::SWAP_IN, &assets_car_path); |
| 100 } | 112 } |
| OLD | NEW |