| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/scope_per_file_provider.h" | 5 #include "tools/gn/scope_per_file_provider.h" |
| 6 | 6 |
| 7 #include "tools/gn/filesystem_utils.h" | 7 #include "tools/gn/filesystem_utils.h" |
| 8 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
| 9 #include "tools/gn/source_file.h" | 9 #include "tools/gn/source_file.h" |
| 10 #include "tools/gn/toolchain_manager.h" | 10 #include "tools/gn/toolchain_manager.h" |
| 11 #include "tools/gn/value.h" | 11 #include "tools/gn/value.h" |
| 12 | 12 #include "tools/gn/variables.h" |
| 13 const char* ScopePerFileProvider::kDefaultToolchain = | |
| 14 "default_toolchain"; | |
| 15 const char* ScopePerFileProvider::kPythonPath = | |
| 16 "python_path"; | |
| 17 const char* ScopePerFileProvider::kToolchain = | |
| 18 "toolchain"; | |
| 19 const char* ScopePerFileProvider::kRootOutputDirName = | |
| 20 "root_output_dir"; | |
| 21 const char* ScopePerFileProvider::kRootGenDirName = | |
| 22 "root_gen_dir"; | |
| 23 const char* ScopePerFileProvider::kTargetOutputDirName = | |
| 24 "target_output_dir"; | |
| 25 const char* ScopePerFileProvider::kTargetGenDirName = | |
| 26 "target_gen_dir"; | |
| 27 const char* ScopePerFileProvider::kRelativeRootOutputDirName = | |
| 28 "relative_root_output_dir"; | |
| 29 const char* ScopePerFileProvider::kRelativeRootGenDirName = | |
| 30 "relative_root_gen_dir"; | |
| 31 const char* ScopePerFileProvider::kRelativeTargetOutputDirName = | |
| 32 "relative_target_output_dir"; | |
| 33 const char* ScopePerFileProvider::kRelativeTargetGenDirName = | |
| 34 "relative_target_gen_dir"; | |
| 35 | 13 |
| 36 ScopePerFileProvider::ScopePerFileProvider(Scope* scope, | 14 ScopePerFileProvider::ScopePerFileProvider(Scope* scope, |
| 37 const SourceFile& source_file) | 15 const SourceFile& source_file) |
| 38 : ProgrammaticProvider(scope), | 16 : ProgrammaticProvider(scope), |
| 39 source_file_(source_file) { | 17 source_file_(source_file) { |
| 40 } | 18 } |
| 41 | 19 |
| 42 ScopePerFileProvider::~ScopePerFileProvider() { | 20 ScopePerFileProvider::~ScopePerFileProvider() { |
| 43 } | 21 } |
| 44 | 22 |
| 45 const Value* ScopePerFileProvider::GetProgrammaticValue( | 23 const Value* ScopePerFileProvider::GetProgrammaticValue( |
| 46 const base::StringPiece& ident) { | 24 const base::StringPiece& ident) { |
| 47 if (ident == kDefaultToolchain) | 25 if (ident == variables::kCurrentToolchain) |
| 26 return GetCurrentToolchain(); |
| 27 if (ident == variables::kDefaultToolchain) |
| 48 return GetDefaultToolchain(); | 28 return GetDefaultToolchain(); |
| 49 if (ident == kPythonPath) | 29 if (ident == variables::kPythonPath) |
| 50 return GetPythonPath(); | 30 return GetPythonPath(); |
| 51 | 31 |
| 52 if (ident == kTargetOutputDirName) | 32 if (ident == variables::kRelativeRootOutputDir) |
| 53 return GetTargetOutputDir(); | |
| 54 if (ident == kTargetGenDirName) | |
| 55 return GetTargetGenDir(); | |
| 56 | |
| 57 if (ident == kRelativeRootOutputDirName) | |
| 58 return GetRelativeRootOutputDir(); | 33 return GetRelativeRootOutputDir(); |
| 59 if (ident == kRelativeRootGenDirName) | 34 if (ident == variables::kRelativeRootGenDir) |
| 60 return GetRelativeRootGenDir(); | 35 return GetRelativeRootGenDir(); |
| 61 if (ident == kRelativeTargetOutputDirName) | 36 if (ident == variables::kRelativeTargetOutputDir) |
| 62 return GetRelativeTargetOutputDir(); | 37 return GetRelativeTargetOutputDir(); |
| 63 if (ident == kRelativeTargetGenDirName) | 38 if (ident == variables::kRelativeTargetGenDir) |
| 64 return GetRelativeTargetGenDir(); | 39 return GetRelativeTargetGenDir(); |
| 65 return NULL; | 40 return NULL; |
| 66 } | 41 } |
| 67 | 42 |
| 68 // static | 43 const Value* ScopePerFileProvider::GetCurrentToolchain() { |
| 69 Value ScopePerFileProvider::GetRootOutputDir(const Settings* settings) { | 44 if (!current_toolchain_) { |
| 70 return Value(NULL, GetRootOutputDirWithNoLastSlash(settings)); | 45 current_toolchain_.reset(new Value(NULL, |
| 71 } | 46 scope_->settings()->toolchain()->label().GetUserVisibleName(false))); |
| 72 | 47 } |
| 73 // static | 48 return current_toolchain_.get(); |
| 74 Value ScopePerFileProvider::GetRootGenDir(const Settings* settings) { | |
| 75 return Value(NULL, GetRootGenDirWithNoLastSlash(settings)); | |
| 76 } | 49 } |
| 77 | 50 |
| 78 const Value* ScopePerFileProvider::GetDefaultToolchain() { | 51 const Value* ScopePerFileProvider::GetDefaultToolchain() { |
| 79 if (!default_toolchain_) { | 52 if (!default_toolchain_) { |
| 80 const ToolchainManager& toolchain_manager = | 53 const ToolchainManager& toolchain_manager = |
| 81 scope_->settings()->build_settings()->toolchain_manager(); | 54 scope_->settings()->build_settings()->toolchain_manager(); |
| 82 default_toolchain_.reset(new Value(NULL, | 55 default_toolchain_.reset(new Value(NULL, |
| 83 toolchain_manager.GetDefaultToolchainUnlocked().GetUserVisibleName( | 56 toolchain_manager.GetDefaultToolchainUnlocked().GetUserVisibleName( |
| 84 false))); | 57 false))); |
| 85 } | 58 } |
| 86 return default_toolchain_.get(); | 59 return default_toolchain_.get(); |
| 87 } | 60 } |
| 88 | 61 |
| 89 const Value* ScopePerFileProvider::GetPythonPath() { | 62 const Value* ScopePerFileProvider::GetPythonPath() { |
| 90 if (!python_path_) { | 63 if (!python_path_) { |
| 91 python_path_.reset(new Value(NULL, | 64 python_path_.reset(new Value(NULL, |
| 92 FilePathToUTF8(scope_->settings()->build_settings()->python_path()))); | 65 FilePathToUTF8(scope_->settings()->build_settings()->python_path()))); |
| 93 } | 66 } |
| 94 return python_path_.get(); | 67 return python_path_.get(); |
| 95 } | 68 } |
| 96 | 69 |
| 97 const Value* ScopePerFileProvider::GetToolchain() { | |
| 98 if (!toolchain_) { | |
| 99 toolchain_.reset(new Value(NULL, | |
| 100 scope_->settings()->toolchain()->label().GetUserVisibleName(false))); | |
| 101 } | |
| 102 return toolchain_.get(); | |
| 103 } | |
| 104 | |
| 105 const Value* ScopePerFileProvider::GetTargetOutputDir() { | |
| 106 if (!target_output_dir_) { | |
| 107 target_output_dir_.reset(new Value(NULL, | |
| 108 GetRootOutputDirWithNoLastSlash(scope_->settings()) + | |
| 109 GetFileDirWithNoLastSlash())); | |
| 110 } | |
| 111 return target_output_dir_.get(); | |
| 112 } | |
| 113 | |
| 114 const Value* ScopePerFileProvider::GetTargetGenDir() { | |
| 115 if (!target_output_dir_) { | |
| 116 target_gen_dir_.reset(new Value(NULL, | |
| 117 GetRootGenDirWithNoLastSlash(scope_->settings()) + | |
| 118 GetFileDirWithNoLastSlash())); | |
| 119 } | |
| 120 return target_gen_dir_.get(); | |
| 121 } | |
| 122 | |
| 123 const Value* ScopePerFileProvider::GetRelativeRootOutputDir() { | 70 const Value* ScopePerFileProvider::GetRelativeRootOutputDir() { |
| 124 if (!relative_root_output_dir_) { | 71 if (!relative_root_output_dir_) { |
| 125 relative_root_output_dir_.reset(new Value(NULL, | 72 relative_root_output_dir_.reset(new Value(NULL, |
| 126 GetRelativeRootWithNoLastSlash() + | 73 GetRelativeRootWithNoLastSlash() + |
| 127 GetRootOutputDirWithNoLastSlash(scope_->settings()))); | 74 GetRootOutputDirWithNoLastSlash(scope_->settings()))); |
| 128 } | 75 } |
| 129 return relative_root_output_dir_.get(); | 76 return relative_root_output_dir_.get(); |
| 130 } | 77 } |
| 131 | 78 |
| 132 const Value* ScopePerFileProvider::GetRelativeRootGenDir() { | 79 const Value* ScopePerFileProvider::GetRelativeRootGenDir() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 157 } | 104 } |
| 158 return relative_target_gen_dir_.get(); | 105 return relative_target_gen_dir_.get(); |
| 159 } | 106 } |
| 160 | 107 |
| 161 // static | 108 // static |
| 162 std::string ScopePerFileProvider::GetRootOutputDirWithNoLastSlash( | 109 std::string ScopePerFileProvider::GetRootOutputDirWithNoLastSlash( |
| 163 const Settings* settings) { | 110 const Settings* settings) { |
| 164 const std::string& output_dir = | 111 const std::string& output_dir = |
| 165 settings->build_settings()->build_dir().value(); | 112 settings->build_settings()->build_dir().value(); |
| 166 CHECK(!output_dir.empty()); | 113 CHECK(!output_dir.empty()); |
| 167 return output_dir.substr(0, output_dir.size() - 1); | 114 return output_dir.substr(1, output_dir.size() - 1); |
| 168 } | 115 } |
| 169 | 116 |
| 170 // static | 117 // static |
| 171 std::string ScopePerFileProvider::GetRootGenDirWithNoLastSlash( | 118 std::string ScopePerFileProvider::GetRootGenDirWithNoLastSlash( |
| 172 const Settings* settings) { | 119 const Settings* settings) { |
| 173 return GetRootOutputDirWithNoLastSlash(settings) + "/gen"; | 120 return GetRootOutputDirWithNoLastSlash(settings) + "/gen"; |
| 174 } | 121 } |
| 175 | 122 |
| 176 std::string ScopePerFileProvider::GetFileDirWithNoLastSlash() const { | 123 std::string ScopePerFileProvider::GetFileDirWithNoLastSlash() const { |
| 177 std::string dir_value = source_file_.GetDir().value(); | 124 std::string dir_value = source_file_.GetDir().value(); |
| 178 return dir_value.substr(0, dir_value.size() - 1); | 125 return dir_value.substr(0, dir_value.size() - 1); |
| 179 } | 126 } |
| 180 | 127 |
| 181 std::string ScopePerFileProvider::GetRelativeRootWithNoLastSlash() const { | 128 std::string ScopePerFileProvider::GetRelativeRootWithNoLastSlash() const { |
| 182 std::string inverted = InvertDir(source_file_.GetDir()); | 129 std::string inverted = InvertDir(source_file_.GetDir()); |
| 183 if (inverted.empty()) | 130 if (inverted.empty()) |
| 184 return "."; | 131 return "."; |
| 185 return inverted.substr(0, inverted.size() - 1); | 132 return inverted.substr(0, inverted.size() - 1); |
| 186 } | 133 } |
| OLD | NEW |