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

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

Issue 2514333005: Add support for customizing GN's args text. (Closed)
Patch Set: update docs Created 3 years, 9 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
« no previous file with comments | « tools/gn/build_settings.cc ('k') | tools/gn/docs/reference.md » ('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 <stddef.h> 5 #include <stddef.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 Setup setup; 261 Setup setup;
262 // Don't fill build arguments. We're about to edit the file which supplies 262 // Don't fill build arguments. We're about to edit the file which supplies
263 // these in the first place. 263 // these in the first place.
264 setup.set_fill_arguments(false); 264 setup.set_fill_arguments(false);
265 if (!setup.DoSetup(build_dir, true)) 265 if (!setup.DoSetup(build_dir, true))
266 return 1; 266 return 1;
267 267
268 // Ensure the file exists. Need to normalize path separators since on 268 // Ensure the file exists. Need to normalize path separators since on
269 // Windows they can come out as forward slashes here, and that confuses some 269 // Windows they can come out as forward slashes here, and that confuses some
270 // of the commands. 270 // of the commands.
271 BuildSettings build_settings = setup.build_settings();
271 base::FilePath arg_file = 272 base::FilePath arg_file =
272 setup.build_settings().GetFullPath(setup.GetBuildArgFile()) 273 build_settings.GetFullPath(setup.GetBuildArgFile())
273 .NormalizePathSeparators(); 274 .NormalizePathSeparators();
274 if (!base::PathExists(arg_file)) { 275 if (!base::PathExists(arg_file)) {
275 std::string argfile_default_contents = 276 std::string argfile_default_contents =
276 "# Build arguments go here. Examples:\n" 277 "# Build arguments go here.\n"
277 "# is_component_build = true\n"
278 "# is_debug = false\n"
279 "# See \"gn args <out_dir> --list\" for available build " 278 "# See \"gn args <out_dir> --list\" for available build "
280 "arguments.\n"; 279 "arguments.\n";
280
281 SourceFile template_path = build_settings.arg_file_template_path();
282 if (!template_path.is_null()) {
283 base::FilePath full_path =
284 build_settings.GetFullPath(template_path).NormalizePathSeparators();
285 if (!base::PathExists(full_path)) {
286 Err err =
287 Err(Location(), std::string("Can't load arg_file_template:\n ") +
288 template_path.value());
289 err.PrintToStdout();
290 return 1;
291 }
292
293 // Ignore the return code; if the read fails (unlikely), we'll just
294 // use the default contents.
295 base::ReadFileToString(full_path, &argfile_default_contents);
296 }
281 #if defined(OS_WIN) 297 #if defined(OS_WIN)
282 // Use Windows lineendings for this file since it will often open in 298 // Use Windows lineendings for this file since it will often open in
283 // Notepad which can't handle Unix ones. 299 // Notepad which can't handle Unix ones.
284 base::ReplaceSubstringsAfterOffset( 300 base::ReplaceSubstringsAfterOffset(
285 &argfile_default_contents, 0, "\n", "\r\n"); 301 &argfile_default_contents, 0, "\n", "\r\n");
286 #endif 302 #endif
287 base::CreateDirectory(arg_file.DirName()); 303 base::CreateDirectory(arg_file.DirName());
288 base::WriteFile(arg_file, argfile_default_contents.c_str(), 304 base::WriteFile(arg_file, argfile_default_contents.c_str(),
289 static_cast<int>(argfile_default_contents.size())); 305 static_cast<int>(argfile_default_contents.size()));
290 } 306 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 "Or see \"gn help args\" for more variants.").PrintToStdout(); 384 "Or see \"gn help args\" for more variants.").PrintToStdout();
369 return 1; 385 return 1;
370 } 386 }
371 387
372 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchList)) 388 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchList))
373 return ListArgs(args[0]); 389 return ListArgs(args[0]);
374 return EditArgsFile(args[0]); 390 return EditArgsFile(args[0]);
375 } 391 }
376 392
377 } // namespace commands 393 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/build_settings.cc ('k') | tools/gn/docs/reference.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698