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/output_file.h" | 9 #include "tools/gn/output_file.h" |
9 #include "tools/gn/settings.h" | 10 #include "tools/gn/settings.h" |
10 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // Return directory of |path| without the trailing directory separator. | 15 // Return directory of |path| without the trailing directory separator. |
15 base::StringPiece FindDirNoTrailingSeparator(const base::StringPiece& path) { | 16 base::StringPiece FindDirNoTrailingSeparator(const base::StringPiece& path) { |
16 base::StringPiece::size_type pos = path.find_last_of("/\\"); | 17 base::StringPiece::size_type pos = path.find_last_of("/\\"); |
17 if (pos == base::StringPiece::npos) | 18 if (pos == base::StringPiece::npos) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 SourceFiles* outputs_as_source) const { | 97 SourceFiles* outputs_as_source) const { |
97 for (const BundleFileRule& file_rule : file_rules_) { | 98 for (const BundleFileRule& file_rule : file_rules_) { |
98 for (const SourceFile& source : file_rule.sources()) { | 99 for (const SourceFile& source : file_rule.sources()) { |
99 outputs_as_source->push_back( | 100 outputs_as_source->push_back( |
100 file_rule.ApplyPatternToSource(settings, *this, source)); | 101 file_rule.ApplyPatternToSource(settings, *this, source)); |
101 } | 102 } |
102 } | 103 } |
103 | 104 |
104 if (!asset_catalog_sources_.empty()) | 105 if (!asset_catalog_sources_.empty()) |
105 outputs_as_source->push_back(GetCompiledAssetCatalogPath()); | 106 outputs_as_source->push_back(GetCompiledAssetCatalogPath()); |
| 107 |
| 108 if (!root_dir_.empty()) |
| 109 outputs_as_source->push_back(GetBundleRootDirOutput(settings)); |
106 } | 110 } |
107 | 111 |
108 SourceFile BundleData::GetCompiledAssetCatalogPath() const { | 112 SourceFile BundleData::GetCompiledAssetCatalogPath() const { |
109 DCHECK(!asset_catalog_sources_.empty()); | 113 DCHECK(!asset_catalog_sources_.empty()); |
110 std::string assets_car_path = resources_dir_ + "/Assets.car"; | 114 std::string assets_car_path = resources_dir_ + "/Assets.car"; |
111 return SourceFile(SourceFile::SWAP_IN, &assets_car_path); | 115 return SourceFile(SourceFile::SWAP_IN, &assets_car_path); |
112 } | 116 } |
| 117 |
| 118 SourceFile BundleData::GetBundleRootDirOutput(const Settings* settings) const { |
| 119 const SourceDir& build_dir = settings->build_settings()->build_dir(); |
| 120 std::string bundle_root_relative = RebasePath(root_dir(), build_dir); |
| 121 |
| 122 size_t first_component = bundle_root_relative.find('/'); |
| 123 if (first_component != std::string::npos) { |
| 124 base::StringPiece outermost_bundle_dir = |
| 125 base::StringPiece(bundle_root_relative).substr(0, first_component); |
| 126 std::string return_value(build_dir.value()); |
| 127 outermost_bundle_dir.AppendToString(&return_value); |
| 128 return SourceFile(SourceFile::SWAP_IN, &return_value); |
| 129 } |
| 130 return SourceFile(root_dir()); |
| 131 } |
OLD | NEW |