Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: tools/gn/scope_per_file_provider.cc

Issue 23606031: GN: Use build directory for CD for scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/scope_per_file_provider.h ('k') | tools/gn/scope_per_file_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "tools/gn/variables.h" 12 #include "tools/gn/variables.h"
13 13
14 ScopePerFileProvider::ScopePerFileProvider(Scope* scope) 14 ScopePerFileProvider::ScopePerFileProvider(Scope* scope)
15 : ProgrammaticProvider(scope) { 15 : ProgrammaticProvider(scope) {
16 } 16 }
17 17
18 ScopePerFileProvider::~ScopePerFileProvider() { 18 ScopePerFileProvider::~ScopePerFileProvider() {
19 } 19 }
20 20
21 const Value* ScopePerFileProvider::GetProgrammaticValue( 21 const Value* ScopePerFileProvider::GetProgrammaticValue(
22 const base::StringPiece& ident) { 22 const base::StringPiece& ident) {
23 if (ident == variables::kCurrentToolchain) 23 if (ident == variables::kCurrentToolchain)
24 return GetCurrentToolchain(); 24 return GetCurrentToolchain();
25 if (ident == variables::kDefaultToolchain) 25 if (ident == variables::kDefaultToolchain)
26 return GetDefaultToolchain(); 26 return GetDefaultToolchain();
27 if (ident == variables::kPythonPath) 27 if (ident == variables::kPythonPath)
28 return GetPythonPath(); 28 return GetPythonPath();
29 29
30 if (ident == variables::kRelativeBuildToSourceRootDir)
31 return GetRelativeBuildToSourceRootDir();
32 if (ident == variables::kRelativeRootOutputDir)
33 return GetRelativeRootOutputDir();
34 if (ident == variables::kRelativeRootGenDir)
35 return GetRelativeRootGenDir();
36 if (ident == variables::kRelativeSourceRootDir)
37 return GetRelativeSourceRootDir();
38 if (ident == variables::kRelativeTargetOutputDir)
39 return GetRelativeTargetOutputDir();
40 if (ident == variables::kRelativeTargetGenDir)
41 return GetRelativeTargetGenDir();
42 if (ident == variables::kRootGenDir) 30 if (ident == variables::kRootGenDir)
43 return GetRootGenDir(); 31 return GetRootGenDir();
32 if (ident == variables::kRootOutDir)
33 return GetRootOutDir();
44 if (ident == variables::kTargetGenDir) 34 if (ident == variables::kTargetGenDir)
45 return GetTargetGenDir(); 35 return GetTargetGenDir();
36 if (ident == variables::kTargetOutDir)
37 return GetTargetOutDir();
46 return NULL; 38 return NULL;
47 } 39 }
48 40
49 const Value* ScopePerFileProvider::GetCurrentToolchain() { 41 const Value* ScopePerFileProvider::GetCurrentToolchain() {
50 if (!current_toolchain_) { 42 if (!current_toolchain_) {
51 current_toolchain_.reset(new Value(NULL, 43 current_toolchain_.reset(new Value(NULL,
52 scope_->settings()->toolchain()->label().GetUserVisibleName(false))); 44 scope_->settings()->toolchain()->label().GetUserVisibleName(false)));
53 } 45 }
54 return current_toolchain_.get(); 46 return current_toolchain_.get();
55 } 47 }
(...skipping 10 matching lines...) Expand all
66 } 58 }
67 59
68 const Value* ScopePerFileProvider::GetPythonPath() { 60 const Value* ScopePerFileProvider::GetPythonPath() {
69 if (!python_path_) { 61 if (!python_path_) {
70 python_path_.reset(new Value(NULL, 62 python_path_.reset(new Value(NULL,
71 FilePathToUTF8(scope_->settings()->build_settings()->python_path()))); 63 FilePathToUTF8(scope_->settings()->build_settings()->python_path())));
72 } 64 }
73 return python_path_.get(); 65 return python_path_.get();
74 } 66 }
75 67
76 const Value* ScopePerFileProvider::GetRelativeBuildToSourceRootDir() {
77 if (!relative_build_to_source_root_dir_) {
78 const SourceDir& build_dir =
79 scope_->settings()->build_settings()->build_dir();
80 relative_build_to_source_root_dir_.reset(
81 new Value(NULL, InvertDirWithNoLastSlash(build_dir)));
82 }
83 return relative_build_to_source_root_dir_.get();
84 }
85
86 const Value* ScopePerFileProvider::GetRelativeRootOutputDir() {
87 if (!relative_root_output_dir_) {
88 relative_root_output_dir_.reset(new Value(NULL,
89 GetRelativeRootWithNoLastSlash() +
90 GetRootOutputDirWithNoLastSlash(scope_->settings())));
91 }
92 return relative_root_output_dir_.get();
93 }
94
95 const Value* ScopePerFileProvider::GetRelativeRootGenDir() {
96 if (!relative_root_gen_dir_) {
97 relative_root_gen_dir_.reset(new Value(NULL,
98 GetRelativeRootWithNoLastSlash() +
99 GetRootGenDirWithNoLastSlash(scope_->settings())));
100 }
101 return relative_root_gen_dir_.get();
102 }
103
104 const Value* ScopePerFileProvider::GetRelativeSourceRootDir() {
105 if (!relative_source_root_dir_) {
106 relative_source_root_dir_.reset(new Value(NULL,
107 GetRelativeRootWithNoLastSlash()));
108 }
109 return relative_source_root_dir_.get();
110 }
111
112 const Value* ScopePerFileProvider::GetRelativeTargetOutputDir() {
113 if (!relative_target_output_dir_) {
114 relative_target_output_dir_.reset(new Value(NULL,
115 GetRelativeRootWithNoLastSlash() +
116 GetRootOutputDirWithNoLastSlash(scope_->settings()) + "/obj" +
117 GetFileDirWithNoLastSlash()));
118 }
119 return relative_target_output_dir_.get();
120 }
121
122 const Value* ScopePerFileProvider::GetRelativeTargetGenDir() {
123 if (!relative_target_gen_dir_) {
124 relative_target_gen_dir_.reset(new Value(NULL,
125 GetRelativeRootWithNoLastSlash() +
126 GetRootGenDirWithNoLastSlash(scope_->settings()) +
127 GetFileDirWithNoLastSlash()));
128 }
129 return relative_target_gen_dir_.get();
130 }
131
132 const Value* ScopePerFileProvider::GetRootGenDir() { 68 const Value* ScopePerFileProvider::GetRootGenDir() {
133 if (!root_gen_dir_) { 69 if (!root_gen_dir_) {
134 root_gen_dir_.reset(new Value(NULL, 70 root_gen_dir_.reset(new Value(NULL,
135 "/" + GetRootGenDirWithNoLastSlash(scope_->settings()))); 71 "/" + GetRootGenDirWithNoLastSlash(scope_->settings())));
136 } 72 }
137 return root_gen_dir_.get(); 73 return root_gen_dir_.get();
138 } 74 }
139 75
76 const Value* ScopePerFileProvider::GetRootOutDir() {
77 if (!root_out_dir_) {
78 root_out_dir_.reset(new Value(NULL,
79 "/" + GetRootOutputDirWithNoLastSlash(scope_->settings())));
80 }
81 return root_out_dir_.get();
82 }
83
140 const Value* ScopePerFileProvider::GetTargetGenDir() { 84 const Value* ScopePerFileProvider::GetTargetGenDir() {
141 if (!target_gen_dir_) { 85 if (!target_gen_dir_) {
142 target_gen_dir_.reset(new Value(NULL, 86 target_gen_dir_.reset(new Value(NULL,
143 "/" + 87 "/" +
144 GetRootGenDirWithNoLastSlash(scope_->settings()) + 88 GetRootGenDirWithNoLastSlash(scope_->settings()) +
145 GetFileDirWithNoLastSlash())); 89 GetFileDirWithNoLastSlash()));
146 } 90 }
147 return target_gen_dir_.get(); 91 return target_gen_dir_.get();
148 } 92 }
149 93
94 const Value* ScopePerFileProvider::GetTargetOutDir() {
95 if (!target_out_dir_) {
96 target_out_dir_.reset(new Value(NULL,
97 "/" +
98 GetRootOutputDirWithNoLastSlash(scope_->settings()) + "/obj" +
99 GetFileDirWithNoLastSlash()));
100 }
101 return target_out_dir_.get();
102 }
103
150 // static 104 // static
151 std::string ScopePerFileProvider::GetRootOutputDirWithNoLastSlash( 105 std::string ScopePerFileProvider::GetRootOutputDirWithNoLastSlash(
152 const Settings* settings) { 106 const Settings* settings) {
153 const std::string& output_dir = 107 const std::string& output_dir =
154 settings->build_settings()->build_dir().value(); 108 settings->build_settings()->build_dir().value();
155 109
156 // Trim off a leading and trailing slash. So "//foo/bar/" -> /foo/bar". 110 // Trim off a leading and trailing slash. So "//foo/bar/" -> /foo/bar".
157 DCHECK(output_dir.size() > 2 && output_dir[0] == '/' && 111 DCHECK(output_dir.size() > 2 && output_dir[0] == '/' &&
158 output_dir[output_dir.size() - 1] == '/'); 112 output_dir[output_dir.size() - 1] == '/');
159 return output_dir.substr(1, output_dir.size() - 2); 113 return output_dir.substr(1, output_dir.size() - 2);
160 } 114 }
161 115
162 // static 116 // static
163 std::string ScopePerFileProvider::GetRootGenDirWithNoLastSlash( 117 std::string ScopePerFileProvider::GetRootGenDirWithNoLastSlash(
164 const Settings* settings) { 118 const Settings* settings) {
165 return GetRootOutputDirWithNoLastSlash(settings) + "/gen"; 119 return GetRootOutputDirWithNoLastSlash(settings) + "/gen";
166 } 120 }
167 121
168 std::string ScopePerFileProvider::GetFileDirWithNoLastSlash() const { 122 std::string ScopePerFileProvider::GetFileDirWithNoLastSlash() const {
169 const std::string& dir_value = scope_->GetSourceDir().value(); 123 const std::string& dir_value = scope_->GetSourceDir().value();
170 124
171 // Trim off a leading and trailing slash. So "//foo/bar/" -> /foo/bar". 125 // Trim off a leading and trailing slash. So "//foo/bar/" -> /foo/bar".
172 DCHECK(dir_value.size() > 2 && dir_value[0] == '/' && 126 DCHECK(dir_value.size() > 2 && dir_value[0] == '/' &&
173 dir_value[dir_value.size() - 1] == '/'); 127 dir_value[dir_value.size() - 1] == '/');
174 return dir_value.substr(1, dir_value.size() - 2); 128 return dir_value.substr(1, dir_value.size() - 2);
175 } 129 }
176
177 std::string ScopePerFileProvider::GetRelativeRootWithNoLastSlash() const {
178 return InvertDirWithNoLastSlash(scope_->GetSourceDir());
179 }
180
181 // static
182 std::string ScopePerFileProvider::InvertDirWithNoLastSlash(
183 const SourceDir& dir) {
184 std::string inverted = InvertDir(dir);
185 if (inverted.empty())
186 return ".";
187 return inverted.substr(0, inverted.size() - 1);
188 }
OLDNEW
« no previous file with comments | « tools/gn/scope_per_file_provider.h ('k') | tools/gn/scope_per_file_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698