| 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/filesystem_utils.h" | 8 #include "tools/gn/filesystem_utils.h" |
| 9 #include "tools/gn/output_file.h" | 9 #include "tools/gn/output_file.h" |
| 10 #include "tools/gn/settings.h" | 10 #include "tools/gn/settings.h" |
| 11 #include "tools/gn/substitution_writer.h" |
| 11 #include "tools/gn/target.h" | 12 #include "tools/gn/target.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Return directory of |path| without the trailing directory separator. | 16 // Return directory of |path| without the trailing directory separator. |
| 16 base::StringPiece FindDirNoTrailingSeparator(const base::StringPiece& path) { | 17 base::StringPiece FindDirNoTrailingSeparator(const base::StringPiece& path) { |
| 17 base::StringPiece::size_type pos = path.find_last_of("/\\"); | 18 base::StringPiece::size_type pos = path.find_last_of("/\\"); |
| 18 if (pos == base::StringPiece::npos) | 19 if (pos == base::StringPiece::npos) |
| 19 return base::StringPiece(); | 20 return base::StringPiece(); |
| 20 return base::StringPiece(path.data(), pos); | 21 return base::StringPiece(path.data(), pos); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 GetSourceFiles(&owning_target->sources()); | 76 GetSourceFiles(&owning_target->sources()); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void BundleData::GetSourceFiles(SourceFiles* sources) const { | 79 void BundleData::GetSourceFiles(SourceFiles* sources) const { |
| 79 for (const BundleFileRule& file_rule : file_rules_) { | 80 for (const BundleFileRule& file_rule : file_rules_) { |
| 80 sources->insert(sources->end(), file_rule.sources().begin(), | 81 sources->insert(sources->end(), file_rule.sources().begin(), |
| 81 file_rule.sources().end()); | 82 file_rule.sources().end()); |
| 82 } | 83 } |
| 83 sources->insert(sources->end(), asset_catalog_sources_.begin(), | 84 sources->insert(sources->end(), asset_catalog_sources_.begin(), |
| 84 asset_catalog_sources_.end()); | 85 asset_catalog_sources_.end()); |
| 86 if (!code_signing_script_.is_null()) { |
| 87 sources->insert(sources->end(), code_signing_sources_.begin(), |
| 88 code_signing_sources_.end()); |
| 89 } |
| 85 } | 90 } |
| 86 | 91 |
| 87 void BundleData::GetOutputFiles(const Settings* settings, | 92 void BundleData::GetOutputFiles(const Settings* settings, |
| 88 OutputFiles* outputs) const { | 93 OutputFiles* outputs) const { |
| 89 SourceFiles outputs_as_sources; | 94 SourceFiles outputs_as_sources; |
| 90 GetOutputsAsSourceFiles(settings, &outputs_as_sources); | 95 GetOutputsAsSourceFiles(settings, &outputs_as_sources); |
| 91 for (const SourceFile& source_file : outputs_as_sources) | 96 for (const SourceFile& source_file : outputs_as_sources) |
| 92 outputs->push_back(OutputFile(settings->build_settings(), source_file)); | 97 outputs->push_back(OutputFile(settings->build_settings(), source_file)); |
| 93 } | 98 } |
| 94 | 99 |
| 95 void BundleData::GetOutputsAsSourceFiles( | 100 void BundleData::GetOutputsAsSourceFiles( |
| 96 const Settings* settings, | 101 const Settings* settings, |
| 97 SourceFiles* outputs_as_source) const { | 102 SourceFiles* outputs_as_source) const { |
| 98 for (const BundleFileRule& file_rule : file_rules_) { | 103 for (const BundleFileRule& file_rule : file_rules_) { |
| 99 for (const SourceFile& source : file_rule.sources()) { | 104 for (const SourceFile& source : file_rule.sources()) { |
| 100 outputs_as_source->push_back( | 105 outputs_as_source->push_back( |
| 101 file_rule.ApplyPatternToSource(settings, *this, source)); | 106 file_rule.ApplyPatternToSource(settings, *this, source)); |
| 102 } | 107 } |
| 103 } | 108 } |
| 104 | 109 |
| 105 if (!asset_catalog_sources_.empty()) | 110 if (!asset_catalog_sources_.empty()) |
| 106 outputs_as_source->push_back(GetCompiledAssetCatalogPath()); | 111 outputs_as_source->push_back(GetCompiledAssetCatalogPath()); |
| 107 | 112 |
| 113 if (!code_signing_script_.is_null()) { |
| 114 std::vector<SourceFile> code_signing_output_files; |
| 115 SubstitutionWriter::GetListAsSourceFiles(code_signing_outputs_, |
| 116 &code_signing_output_files); |
| 117 outputs_as_source->insert(outputs_as_source->end(), |
| 118 code_signing_output_files.begin(), |
| 119 code_signing_output_files.end()); |
| 120 } |
| 121 |
| 108 if (!root_dir_.is_null()) | 122 if (!root_dir_.is_null()) |
| 109 outputs_as_source->push_back(GetBundleRootDirOutput(settings)); | 123 outputs_as_source->push_back(GetBundleRootDirOutput(settings)); |
| 110 } | 124 } |
| 111 | 125 |
| 112 SourceFile BundleData::GetCompiledAssetCatalogPath() const { | 126 SourceFile BundleData::GetCompiledAssetCatalogPath() const { |
| 113 DCHECK(!asset_catalog_sources_.empty()); | 127 DCHECK(!asset_catalog_sources_.empty()); |
| 114 std::string assets_car_path = resources_dir_.value() + "/Assets.car"; | 128 std::string assets_car_path = resources_dir_.value() + "/Assets.car"; |
| 115 return SourceFile(SourceFile::SWAP_IN, &assets_car_path); | 129 return SourceFile(SourceFile::SWAP_IN, &assets_car_path); |
| 116 } | 130 } |
| 117 | 131 |
| 118 SourceFile BundleData::GetBundleRootDirOutput(const Settings* settings) const { | 132 SourceFile BundleData::GetBundleRootDirOutput(const Settings* settings) const { |
| 119 const SourceDir& build_dir = settings->build_settings()->build_dir(); | 133 const SourceDir& build_dir = settings->build_settings()->build_dir(); |
| 120 std::string bundle_root_relative = RebasePath(root_dir().value(), build_dir); | 134 std::string bundle_root_relative = RebasePath(root_dir().value(), build_dir); |
| 121 | 135 |
| 122 size_t first_component = bundle_root_relative.find('/'); | 136 size_t first_component = bundle_root_relative.find('/'); |
| 123 if (first_component != std::string::npos) { | 137 if (first_component != std::string::npos) { |
| 124 base::StringPiece outermost_bundle_dir = | 138 base::StringPiece outermost_bundle_dir = |
| 125 base::StringPiece(bundle_root_relative).substr(0, first_component); | 139 base::StringPiece(bundle_root_relative).substr(0, first_component); |
| 126 std::string return_value(build_dir.value()); | 140 std::string return_value(build_dir.value()); |
| 127 outermost_bundle_dir.AppendToString(&return_value); | 141 outermost_bundle_dir.AppendToString(&return_value); |
| 128 return SourceFile(SourceFile::SWAP_IN, &return_value); | 142 return SourceFile(SourceFile::SWAP_IN, &return_value); |
| 129 } | 143 } |
| 130 return SourceFile(root_dir().value()); | 144 return SourceFile(root_dir().value()); |
| 131 } | 145 } |
| 132 | 146 |
| 133 SourceDir BundleData::GetBundleRootDirOutputAsDir( | 147 SourceDir BundleData::GetBundleRootDirOutputAsDir( |
| 134 const Settings* settings) const { | 148 const Settings* settings) const { |
| 135 return SourceDir(GetBundleRootDirOutput(settings).value()); | 149 return SourceDir(GetBundleRootDirOutput(settings).value()); |
| 136 } | 150 } |
| OLD | NEW |