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

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

Issue 1155713006: GN: Make file/dir resolving return errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 const Settings* settings = scope->settings(); 128 const Settings* settings = scope->settings();
129 const BuildSettings* build_settings = settings->build_settings(); 129 const BuildSettings* build_settings = settings->build_settings();
130 const SourceDir& cur_dir = scope->GetSourceDir(); 130 const SourceDir& cur_dir = scope->GetSourceDir();
131 131
132 if (!CheckExecScriptPermissions(build_settings, function, err)) 132 if (!CheckExecScriptPermissions(build_settings, function, err))
133 return Value(); 133 return Value();
134 134
135 // Find the python script to run. 135 // Find the python script to run.
136 if (!args[0].VerifyTypeIs(Value::STRING, err)) 136 SourceFile script_source =
137 cur_dir.ResolveRelativeFile(args[0], err,
138 scope->settings()->build_settings()->root_path_utf8());
139 if (err->has_error())
137 return Value(); 140 return Value();
138 SourceFile script_source =
139 cur_dir.ResolveRelativeFile(args[0].string_value(),
140 scope->settings()->build_settings()->root_path_utf8());
141 base::FilePath script_path = build_settings->GetFullPath(script_source); 141 base::FilePath script_path = build_settings->GetFullPath(script_source);
142 if (!build_settings->secondary_source_path().empty() && 142 if (!build_settings->secondary_source_path().empty() &&
143 !base::PathExists(script_path)) { 143 !base::PathExists(script_path)) {
144 // Fall back to secondary source root when the file doesn't exist. 144 // Fall back to secondary source root when the file doesn't exist.
145 script_path = build_settings->GetFullPathSecondary(script_source); 145 script_path = build_settings->GetFullPathSecondary(script_source);
146 } 146 }
147 147
148 ScopedTrace trace(TraceItem::TRACE_SCRIPT_EXECUTE, script_source.value()); 148 ScopedTrace trace(TraceItem::TRACE_SCRIPT_EXECUTE, script_source.value());
149 trace.SetToolchain(settings->toolchain_label()); 149 trace.SetToolchain(settings->toolchain_label());
150 150
151 // Add all dependencies of this script, including the script itself, to the 151 // Add all dependencies of this script, including the script itself, to the
152 // build deps. 152 // build deps.
153 g_scheduler->AddGenDependency(script_path); 153 g_scheduler->AddGenDependency(script_path);
154 if (args.size() == 4) { 154 if (args.size() == 4) {
155 const Value& deps_value = args[3]; 155 const Value& deps_value = args[3];
156 if (!deps_value.VerifyTypeIs(Value::LIST, err)) 156 if (!deps_value.VerifyTypeIs(Value::LIST, err))
157 return Value(); 157 return Value();
158 158
159 for (const auto& dep : deps_value.list_value()) { 159 for (const auto& dep : deps_value.list_value()) {
160 if (!dep.VerifyTypeIs(Value::STRING, err)) 160 if (!dep.VerifyTypeIs(Value::STRING, err))
161 return Value(); 161 return Value();
162 g_scheduler->AddGenDependency( 162 g_scheduler->AddGenDependency(
163 build_settings->GetFullPath(cur_dir.ResolveRelativeFile( 163 build_settings->GetFullPath(cur_dir.ResolveRelativeFile(
164 dep.string_value(), 164 dep, err,
165 scope->settings()->build_settings()->root_path_utf8()))); 165 scope->settings()->build_settings()->root_path_utf8())));
166 if (err->has_error())
167 return Value();
166 } 168 }
167 } 169 }
168 170
169 // Make the command line. 171 // Make the command line.
170 const base::FilePath& python_path = build_settings->python_path(); 172 const base::FilePath& python_path = build_settings->python_path();
171 base::CommandLine cmdline(python_path); 173 base::CommandLine cmdline(python_path);
172 cmdline.AppendArgPath(script_path); 174 cmdline.AppendArgPath(script_path);
173 175
174 if (args.size() >= 2) { 176 if (args.size() >= 2) {
175 // Optional command-line arguments to the script. 177 // Optional command-line arguments to the script.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 msg); 242 msg);
241 return Value(); 243 return Value();
242 } 244 }
243 245
244 // Default to None value for the input conversion if unspecified. 246 // Default to None value for the input conversion if unspecified.
245 return ConvertInputToValue(scope->settings(), output, function, 247 return ConvertInputToValue(scope->settings(), output, function,
246 args.size() >= 3 ? args[2] : Value(), err); 248 args.size() >= 3 ? args[2] : Value(), err);
247 } 249 }
248 250
249 } // namespace functions 251 } // namespace functions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698