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

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

Issue 2481423002: Convert gn docstrings to C++11 raw strings. (Closed)
Patch Set: Tweaks Created 4 years, 1 month 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 "tools/gn/functions.h" 5 #include "tools/gn/functions.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <iostream> 8 #include <iostream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 174 }
175 175
176 namespace functions { 176 namespace functions {
177 177
178 // assert ---------------------------------------------------------------------- 178 // assert ----------------------------------------------------------------------
179 179
180 const char kAssert[] = "assert"; 180 const char kAssert[] = "assert";
181 const char kAssert_HelpShort[] = 181 const char kAssert_HelpShort[] =
182 "assert: Assert an expression is true at generation time."; 182 "assert: Assert an expression is true at generation time.";
183 const char kAssert_Help[] = 183 const char kAssert_Help[] =
184 "assert: Assert an expression is true at generation time.\n" 184 R"(assert: Assert an expression is true at generation time.
185 "\n" 185
186 " assert(<condition> [, <error string>])\n" 186 assert(<condition> [, <error string>])
187 "\n" 187
188 " If the condition is false, the build will fail with an error. If the\n" 188 If the condition is false, the build will fail with an error. If the
189 " optional second argument is provided, that string will be printed\n" 189 optional second argument is provided, that string will be printed
190 " with the error message.\n" 190 with the error message.
191 "\n" 191
192 "Examples:\n" 192 Examples
193 " assert(is_win)\n" 193
194 " assert(defined(sources), \"Sources must be defined\")\n"; 194 assert(is_win)
195 assert(defined(sources), "Sources must be defined");)";
195 196
196 Value RunAssert(Scope* scope, 197 Value RunAssert(Scope* scope,
197 const FunctionCallNode* function, 198 const FunctionCallNode* function,
198 const std::vector<Value>& args, 199 const std::vector<Value>& args,
199 Err* err) { 200 Err* err) {
200 if (args.size() != 1 && args.size() != 2) { 201 if (args.size() != 1 && args.size() != 2) {
201 *err = Err(function->function(), "Wrong number of arguments.", 202 *err = Err(function->function(), "Wrong number of arguments.",
202 "assert() takes one or two argument, " 203 "assert() takes one or two argument, "
203 "were you expecting somethig else?"); 204 "were you expecting somethig else?");
204 } else if (args[0].type() != Value::BOOLEAN) { 205 } else if (args[0].type() != Value::BOOLEAN) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 239 }
239 return Value(); 240 return Value();
240 } 241 }
241 242
242 // config ---------------------------------------------------------------------- 243 // config ----------------------------------------------------------------------
243 244
244 const char kConfig[] = "config"; 245 const char kConfig[] = "config";
245 const char kConfig_HelpShort[] = 246 const char kConfig_HelpShort[] =
246 "config: Defines a configuration object."; 247 "config: Defines a configuration object.";
247 const char kConfig_Help[] = 248 const char kConfig_Help[] =
248 "config: Defines a configuration object.\n" 249 R"(config: Defines a configuration object.
249 "\n" 250
250 " Configuration objects can be applied to targets and specify sets of\n" 251 Configuration objects can be applied to targets and specify sets of compiler
251 " compiler flags, includes, defines, etc. They provide a way to\n" 252 flags, includes, defines, etc. They provide a way to conveniently group sets
252 " conveniently group sets of this configuration information.\n" 253 of this configuration information.
253 "\n" 254
254 " A config is referenced by its label just like a target.\n" 255 A config is referenced by its label just like a target.
255 "\n" 256
256 " The values in a config are additive only. If you want to remove a flag\n" 257 The values in a config are additive only. If you want to remove a flag you
257 " you need to remove the corresponding config that sets it. The final\n" 258 need to remove the corresponding config that sets it. The final set of flags,
258 " set of flags, defines, etc. for a target is generated in this order:\n" 259 defines, etc. for a target is generated in this order:
259 "\n" 260
260 " 1. The values specified directly on the target (rather than using a\n" 261 1. The values specified directly on the target (rather than using a config.
261 " config.\n" 262 2. The configs specified in the target's "configs" list, in order.
262 " 2. The configs specified in the target's \"configs\" list, in order.\n" 263 3. Public_configs from a breadth-first traversal of the dependency tree in
263 " 3. Public_configs from a breadth-first traversal of the dependency\n" 264 the order that the targets appear in "deps".
264 " tree in the order that the targets appear in \"deps\".\n" 265 4. All dependent configs from a breadth-first traversal of the dependency
265 " 4. All dependent configs from a breadth-first traversal of the\n" 266 tree in the order that the targets appear in "deps".
266 " dependency tree in the order that the targets appear in \"deps\".\n" 267
267 "\n" 268 Variables valid in a config definition
268 "Variables valid in a config definition\n" 269 )"
269 "\n" 270
270 CONFIG_VALUES_VARS_HELP 271 CONFIG_VALUES_VARS_HELP
271 " Nested configs: configs\n" 272
272 "\n" 273 R"( Nested configs: configs
273 "Variables on a target used to apply configs\n" 274
274 "\n" 275 Variables on a target used to apply configs
275 " all_dependent_configs, configs, public_configs\n" 276
276 "\n" 277 all_dependent_configs, configs, public_configs
277 "Example\n" 278
278 "\n" 279 Example
279 " config(\"myconfig\") {\n" 280
280 " includes = [ \"include/common\" ]\n" 281 config("myconfig") {
281 " defines = [ \"ENABLE_DOOM_MELON\" ]\n" 282 includes = [ "include/common" ]
282 " }\n" 283 defines = [ "ENABLE_DOOM_MELON" ]
283 "\n" 284 }
284 " executable(\"mything\") {\n" 285
285 " configs = [ \":myconfig\" ]\n" 286 executable("mything") {
286 " }\n"; 287 configs = [ ":myconfig" ]
288 })";
287 289
288 Value RunConfig(const FunctionCallNode* function, 290 Value RunConfig(const FunctionCallNode* function,
289 const std::vector<Value>& args, 291 const std::vector<Value>& args,
290 Scope* scope, 292 Scope* scope,
291 Err* err) { 293 Err* err) {
292 NonNestableBlock non_nestable(scope, function, "config"); 294 NonNestableBlock non_nestable(scope, function, "config");
293 if (!non_nestable.Enter(err)) 295 if (!non_nestable.Enter(err))
294 return Value(); 296 return Value();
295 297
296 if (!EnsureSingleStringArg(function, args, err) || 298 if (!EnsureSingleStringArg(function, args, err) ||
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 337
336 return Value(); 338 return Value();
337 } 339 }
338 340
339 // declare_args ---------------------------------------------------------------- 341 // declare_args ----------------------------------------------------------------
340 342
341 const char kDeclareArgs[] = "declare_args"; 343 const char kDeclareArgs[] = "declare_args";
342 const char kDeclareArgs_HelpShort[] = 344 const char kDeclareArgs_HelpShort[] =
343 "declare_args: Declare build arguments."; 345 "declare_args: Declare build arguments.";
344 const char kDeclareArgs_Help[] = 346 const char kDeclareArgs_Help[] =
345 "declare_args: Declare build arguments.\n" 347 R"(declare_args: Declare build arguments.
346 "\n" 348
347 " Introduces the given arguments into the current scope. If they are\n" 349 Introduces the given arguments into the current scope. If they are not
348 " not specified on the command line or in a toolchain's arguments,\n" 350 specified on the command line or in a toolchain's arguments, the default
349 " the default values given in the declare_args block will be used.\n" 351 values given in the declare_args block will be used. However, these defaults
350 " However, these defaults will not override command-line values.\n" 352 will not override command-line values.
351 "\n" 353
352 " See also \"gn help buildargs\" for an overview.\n" 354 See also "gn help buildargs" for an overview.
353 "\n" 355
354 " The precise behavior of declare args is:\n" 356 The precise behavior of declare args is:
355 "\n" 357
356 " 1. The declare_arg block executes. Any variables in the enclosing\n" 358 1. The declare_arg block executes. Any variables in the enclosing scope are
357 " scope are available for reading.\n" 359 available for reading.
358 "\n" 360
359 " 2. At the end of executing the block, any variables set within that\n" 361 2. At the end of executing the block, any variables set within that scope
360 " scope are saved globally as build arguments, with their current\n" 362 are saved globally as build arguments, with their current values being
361 " values being saved as the \"default value\" for that argument.\n" 363 saved as the "default value" for that argument.
362 "\n" 364
363 " 3. User-defined overrides are applied. Anything set in \"gn args\"\n" 365 3. User-defined overrides are applied. Anything set in "gn args" now
364 " now overrides any default values. The resulting set of variables\n" 366 overrides any default values. The resulting set of variables is promoted
365 " is promoted to be readable from the following code in the file.\n" 367 to be readable from the following code in the file.
366 "\n" 368
367 " This has some ramifications that may not be obvious:\n" 369 This has some ramifications that may not be obvious:
368 "\n" 370
369 " - You should not perform difficult work inside a declare_args block\n" 371 - You should not perform difficult work inside a declare_args block since
370 " since this only sets a default value that may be discarded. In\n" 372 this only sets a default value that may be discarded. In particular,
371 " particular, don't use the result of exec_script() to set the\n" 373 don't use the result of exec_script() to set the default value. If you
372 " default value. If you want to have a script-defined default, set\n" 374 want to have a script-defined default, set some default "undefined" value
373 " some default \"undefined\" value like [], \"\", or -1, and after\n" 375 like [], "", or -1, and after the declare_args block, call exec_script if
374 " the declare_args block, call exec_script if the value is unset by\n" 376 the value is unset by the user.
375 " the user.\n" 377
376 "\n" 378 - Any code inside of the declare_args block will see the default values of
377 " - Any code inside of the declare_args block will see the default\n" 379 previous variables defined in the block rather than the user-overridden
378 " values of previous variables defined in the block rather than\n" 380 value. This can be surprising because you will be used to seeing the
379 " the user-overridden value. This can be surprising because you will\n" 381 overridden value. If you need to make the default value of one arg
380 " be used to seeing the overridden value. If you need to make the\n" 382 dependent on the possibly-overridden value of another, write two separate
381 " default value of one arg dependent on the possibly-overridden\n" 383 declare_args blocks:
382 " value of another, write two separate declare_args blocks:\n" 384
383 "\n" 385 declare_args() {
384 " declare_args() {\n" 386 enable_foo = true
385 " enable_foo = true\n" 387 }
386 " }\n" 388 declare_args() {
387 " declare_args() {\n" 389 # Bar defaults to same user-overridden state as foo.
388 " # Bar defaults to same user-overridden state as foo.\n" 390 enable_bar = enable_foo
389 " enable_bar = enable_foo\n" 391 }
390 " }\n" 392
391 "\n" 393 Example
392 "Example\n" 394
393 "\n" 395 declare_args() {
394 " declare_args() {\n" 396 enable_teleporter = true
395 " enable_teleporter = true\n" 397 enable_doom_melon = false
396 " enable_doom_melon = false\n" 398 }
397 " }\n" 399
398 "\n" 400 If you want to override the (default disabled) Doom Melon:
399 " If you want to override the (default disabled) Doom Melon:\n" 401 gn --args="enable_doom_melon=true enable_teleporter=false"
400 " gn --args=\"enable_doom_melon=true enable_teleporter=false\"\n" 402 This also sets the teleporter, but it's already defaulted to on so it will
401 " This also sets the teleporter, but it's already defaulted to on so\n" 403 have no effect.)";
402 " it will have no effect.\n";
403 404
404 Value RunDeclareArgs(Scope* scope, 405 Value RunDeclareArgs(Scope* scope,
405 const FunctionCallNode* function, 406 const FunctionCallNode* function,
406 const std::vector<Value>& args, 407 const std::vector<Value>& args,
407 BlockNode* block, 408 BlockNode* block,
408 Err* err) { 409 Err* err) {
409 NonNestableBlock non_nestable(scope, function, "declare_args"); 410 NonNestableBlock non_nestable(scope, function, "declare_args");
410 if (!non_nestable.Enter(err)) 411 if (!non_nestable.Enter(err))
411 return Value(); 412 return Value();
412 413
(...skipping 11 matching lines...) Expand all
424 values, scope, err); 425 values, scope, err);
425 return Value(); 426 return Value();
426 } 427 }
427 428
428 // defined --------------------------------------------------------------------- 429 // defined ---------------------------------------------------------------------
429 430
430 const char kDefined[] = "defined"; 431 const char kDefined[] = "defined";
431 const char kDefined_HelpShort[] = 432 const char kDefined_HelpShort[] =
432 "defined: Returns whether an identifier is defined."; 433 "defined: Returns whether an identifier is defined.";
433 const char kDefined_Help[] = 434 const char kDefined_Help[] =
434 "defined: Returns whether an identifier is defined.\n" 435 R"(defined: Returns whether an identifier is defined.
435 "\n" 436
436 " Returns true if the given argument is defined. This is most useful in\n" 437 Returns true if the given argument is defined. This is most useful in
437 " templates to assert that the caller set things up properly.\n" 438 templates to assert that the caller set things up properly.
438 "\n" 439
439 " You can pass an identifier:\n" 440 You can pass an identifier:
440 " defined(foo)\n" 441 defined(foo)
441 " which will return true or false depending on whether foo is defined in\n" 442 which will return true or false depending on whether foo is defined in the
442 " the current scope.\n" 443 current scope.
443 "\n" 444
444 " You can also check a named scope:\n" 445 You can also check a named scope:
445 " defined(foo.bar)\n" 446 defined(foo.bar)
446 " which will return true or false depending on whether bar is defined in\n" 447 which will return true or false depending on whether bar is defined in the
447 " the named scope foo. It will throw an error if foo is not defined or\n" 448 named scope foo. It will throw an error if foo is not defined or is not a
448 " is not a scope.\n" 449 scope.
449 "\n" 450
450 "Example:\n" 451 Example
451 "\n" 452
452 " template(\"mytemplate\") {\n" 453 template("mytemplate") {
453 " # To help users call this template properly...\n" 454 # To help users call this template properly...
454 " assert(defined(invoker.sources), \"Sources must be defined\")\n" 455 assert(defined(invoker.sources), "Sources must be defined")
455 "\n" 456
456 " # If we want to accept an optional \"values\" argument, we don't\n" 457 # If we want to accept an optional "values" argument, we don't
457 " # want to dereference something that may not be defined.\n" 458 # want to dereference something that may not be defined.
458 " if (defined(invoker.values)) {\n" 459 if (defined(invoker.values)) {
459 " values = invoker.values\n" 460 values = invoker.values
460 " } else {\n" 461 } else {
461 " values = \"some default value\"\n" 462 values = "some default value"
462 " }\n" 463 }
463 " }\n"; 464 })";
464 465
465 Value RunDefined(Scope* scope, 466 Value RunDefined(Scope* scope,
466 const FunctionCallNode* function, 467 const FunctionCallNode* function,
467 const ListNode* args_list, 468 const ListNode* args_list,
468 Err* err) { 469 Err* err) {
469 const auto& args_vector = args_list->contents(); 470 const auto& args_vector = args_list->contents();
470 if (args_vector.size() != 1) { 471 if (args_vector.size() != 1) {
471 *err = Err(function, "Wrong number of arguments to defined().", 472 *err = Err(function, "Wrong number of arguments to defined().",
472 "Expecting exactly one."); 473 "Expecting exactly one.");
473 return Value(); 474 return Value();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 "It should be of the form defined(foo) or defined(foo.bar)."); 507 "It should be of the form defined(foo) or defined(foo.bar).");
507 return Value(); 508 return Value();
508 } 509 }
509 510
510 // getenv ---------------------------------------------------------------------- 511 // getenv ----------------------------------------------------------------------
511 512
512 const char kGetEnv[] = "getenv"; 513 const char kGetEnv[] = "getenv";
513 const char kGetEnv_HelpShort[] = 514 const char kGetEnv_HelpShort[] =
514 "getenv: Get an environment variable."; 515 "getenv: Get an environment variable.";
515 const char kGetEnv_Help[] = 516 const char kGetEnv_Help[] =
516 "getenv: Get an environment variable.\n" 517 R"(getenv: Get an environment variable.
517 "\n" 518
518 " value = getenv(env_var_name)\n" 519 value = getenv(env_var_name)
519 "\n" 520
520 " Returns the value of the given enironment variable. If the value is\n" 521 Returns the value of the given enironment variable. If the value is not
521 " not found, it will try to look up the variable with the \"opposite\"\n" 522 found, it will try to look up the variable with the "opposite" case (based on
522 " case (based on the case of the first letter of the variable), but\n" 523 the case of the first letter of the variable), but is otherwise
523 " is otherwise case-sensitive.\n" 524 case-sensitive.
524 "\n" 525
525 " If the environment variable is not found, the empty string will be\n" 526 If the environment variable is not found, the empty string will be returned.
526 " returned. Note: it might be nice to extend this if we had the concept\n" 527 Note: it might be nice to extend this if we had the concept of "none" in the
527 " of \"none\" in the language to indicate lookup failure.\n" 528 language to indicate lookup failure.
528 "\n" 529
529 "Example:\n" 530 Example
530 "\n" 531
531 " home_dir = getenv(\"HOME\")\n"; 532 home_dir = getenv("HOME"))";
532 533
533 Value RunGetEnv(Scope* scope, 534 Value RunGetEnv(Scope* scope,
534 const FunctionCallNode* function, 535 const FunctionCallNode* function,
535 const std::vector<Value>& args, 536 const std::vector<Value>& args,
536 Err* err) { 537 Err* err) {
537 if (!EnsureSingleStringArg(function, args, err)) 538 if (!EnsureSingleStringArg(function, args, err))
538 return Value(); 539 return Value();
539 540
540 std::unique_ptr<base::Environment> env(base::Environment::Create()); 541 std::unique_ptr<base::Environment> env(base::Environment::Create());
541 542
542 std::string result; 543 std::string result;
543 if (!env->GetVar(args[0].string_value().c_str(), &result)) 544 if (!env->GetVar(args[0].string_value().c_str(), &result))
544 return Value(function, ""); // Not found, return empty string. 545 return Value(function, ""); // Not found, return empty string.
545 return Value(function, result); 546 return Value(function, result);
546 } 547 }
547 548
548 // import ---------------------------------------------------------------------- 549 // import ----------------------------------------------------------------------
549 550
550 const char kImport[] = "import"; 551 const char kImport[] = "import";
551 const char kImport_HelpShort[] = 552 const char kImport_HelpShort[] =
552 "import: Import a file into the current scope."; 553 "import: Import a file into the current scope.";
553 const char kImport_Help[] = 554 const char kImport_Help[] =
554 "import: Import a file into the current scope.\n" 555 R"(import: Import a file into the current scope.
555 "\n" 556
556 " The import command loads the rules and variables resulting from\n" 557 The import command loads the rules and variables resulting from executing the
557 " executing the given file into the current scope.\n" 558 given file into the current scope.
558 "\n" 559
559 " By convention, imported files are named with a .gni extension.\n" 560 By convention, imported files are named with a .gni extension.
560 "\n" 561
561 " An import is different than a C++ \"include\". The imported file is\n" 562 An import is different than a C++ "include". The imported file is executed in
562 " executed in a standalone environment from the caller of the import\n" 563 a standalone environment from the caller of the import command. The results
563 " command. The results of this execution are cached for other files that\n" 564 of this execution are cached for other files that import the same .gni file.
564 " import the same .gni file.\n" 565
565 "\n" 566 Note that you can not import a BUILD.gn file that's otherwise used in the
566 " Note that you can not import a BUILD.gn file that's otherwise used\n" 567 build. Files must either be imported or implicitly loaded as a result of deps
567 " in the build. Files must either be imported or implicitly loaded as\n" 568 rules, but not both.
568 " a result of deps rules, but not both.\n" 569
569 "\n" 570 The imported file's scope will be merged with the scope at the point import
570 " The imported file's scope will be merged with the scope at the point\n" 571 was called. If there is a conflict (both the current scope and the imported
571 " import was called. If there is a conflict (both the current scope and\n" 572 file define some variable or rule with the same name but different value), a
572 " the imported file define some variable or rule with the same name but\n" 573 runtime error will be thrown. Therefore, it's good practice to minimize the
573 " different value), a runtime error will be thrown. Therefore, it's good\n" 574 stuff that an imported file defines.
574 " practice to minimize the stuff that an imported file defines.\n" 575
575 "\n" 576 Variables and templates beginning with an underscore '_' are considered
576 " Variables and templates beginning with an underscore '_' are\n" 577 private and will not be imported. Imported files can use such variables for
577 " considered private and will not be imported. Imported files can use\n" 578 internal computation without affecting other files.
578 " such variables for internal computation without affecting other files.\n" 579
579 "\n" 580 Examples
580 "Examples:\n" 581
581 "\n" 582 import("//build/rules/idl_compilation_rule.gni")
582 " import(\"//build/rules/idl_compilation_rule.gni\")\n" 583
583 "\n" 584 # Looks in the current directory.
584 " # Looks in the current directory.\n" 585 import("my_vars.gni"))";
585 " import(\"my_vars.gni\")\n";
586 586
587 Value RunImport(Scope* scope, 587 Value RunImport(Scope* scope,
588 const FunctionCallNode* function, 588 const FunctionCallNode* function,
589 const std::vector<Value>& args, 589 const std::vector<Value>& args,
590 Err* err) { 590 Err* err) {
591 if (!EnsureSingleStringArg(function, args, err)) 591 if (!EnsureSingleStringArg(function, args, err))
592 return Value(); 592 return Value();
593 593
594 const SourceDir& input_dir = scope->GetSourceDir(); 594 const SourceDir& input_dir = scope->GetSourceDir();
595 SourceFile import_file = 595 SourceFile import_file =
596 input_dir.ResolveRelativeFile(args[0], err, 596 input_dir.ResolveRelativeFile(args[0], err,
597 scope->settings()->build_settings()->root_path_utf8()); 597 scope->settings()->build_settings()->root_path_utf8());
598 if (!err->has_error()) { 598 if (!err->has_error()) {
599 scope->settings()->import_manager().DoImport(import_file, function, 599 scope->settings()->import_manager().DoImport(import_file, function,
600 scope, err); 600 scope, err);
601 } 601 }
602 return Value(); 602 return Value();
603 } 603 }
604 604
605 // set_sources_assignment_filter ----------------------------------------------- 605 // set_sources_assignment_filter -----------------------------------------------
606 606
607 const char kSetSourcesAssignmentFilter[] = "set_sources_assignment_filter"; 607 const char kSetSourcesAssignmentFilter[] = "set_sources_assignment_filter";
608 const char kSetSourcesAssignmentFilter_HelpShort[] = 608 const char kSetSourcesAssignmentFilter_HelpShort[] =
609 "set_sources_assignment_filter: Set a pattern to filter source files."; 609 "set_sources_assignment_filter: Set a pattern to filter source files.";
610 const char kSetSourcesAssignmentFilter_Help[] = 610 const char kSetSourcesAssignmentFilter_Help[] =
611 "set_sources_assignment_filter: Set a pattern to filter source files.\n" 611 R"(set_sources_assignment_filter: Set a pattern to filter source files.
612 "\n" 612
613 " The sources assignment filter is a list of patterns that remove files\n" 613 The sources assignment filter is a list of patterns that remove files from
614 " from the list implicitly whenever the \"sources\" variable is\n" 614 the list implicitly whenever the "sources" variable is assigned to. This will
615 " assigned to. This will do nothing for non-lists.\n" 615 do nothing for non-lists.
616 "\n" 616
617 " This is intended to be used to globally filter out files with\n" 617 This is intended to be used to globally filter out files with
618 " platform-specific naming schemes when they don't apply, for example\n" 618 platform-specific naming schemes when they don't apply, for example you may
619 " you may want to filter out all \"*_win.cc\" files on non-Windows\n" 619 want to filter out all "*_win.cc" files on non-Windows platforms.
620 " platforms.\n" 620
621 "\n" 621 Typically this will be called once in the master build config script to set
622 " Typically this will be called once in the master build config script\n" 622 up the filter for the current platform. Subsequent calls will overwrite the
623 " to set up the filter for the current platform. Subsequent calls will\n" 623 previous values.
624 " overwrite the previous values.\n" 624
625 "\n" 625 If you want to bypass the filter and add a file even if it might be filtered
626 " If you want to bypass the filter and add a file even if it might\n" 626 out, call set_sources_assignment_filter([]) to clear the list of filters.
627 " be filtered out, call set_sources_assignment_filter([]) to clear the\n" 627 This will apply until the current scope exits
628 " list of filters. This will apply until the current scope exits\n" 628
629 "\n" 629 How to use patterns
630 "How to use patterns\n" 630
631 "\n" 631 File patterns are VERY limited regular expressions. They must match the
632 " File patterns are VERY limited regular expressions. They must match\n" 632 entire input string to be counted as a match. In regular expression parlance,
633 " the entire input string to be counted as a match. In regular\n" 633 there is an implicit "^...$" surrounding your input. If you want to match a
634 " expression parlance, there is an implicit \"^...$\" surrounding your\n" 634 substring, you need to use wildcards at the beginning and end.
635 " input. If you want to match a substring, you need to use wildcards at\n" 635
636 " the beginning and end.\n" 636 There are only two special tokens understood by the pattern matcher.
637 "\n" 637 Everything else is a literal.
638 " There are only two special tokens understood by the pattern matcher.\n" 638
639 " Everything else is a literal.\n" 639 - "*" Matches zero or more of any character. It does not depend on the
640 "\n" 640 preceding character (in regular expression parlance it is equivalent to
641 " * Matches zero or more of any character. It does not depend on the\n" 641 ".*").
642 " preceding character (in regular expression parlance it is\n" 642
643 " equivalent to \".*\").\n" 643 - "\b" Matches a path boundary. This will match the beginning or end of a
644 "\n" 644 string, or a slash.
645 " \\b Matches a path boundary. This will match the beginning or end of\n" 645
646 " a string, or a slash.\n" 646 Pattern examples
647 "\n" 647
648 "Pattern examples\n" 648 "*asdf*"
649 "\n" 649 Matches a string containing "asdf" anywhere.
650 " \"*asdf*\"\n" 650
651 " Matches a string containing \"asdf\" anywhere.\n" 651 "asdf"
652 "\n" 652 Matches only the exact string "asdf".
653 " \"asdf\"\n" 653
654 " Matches only the exact string \"asdf\".\n" 654 "*.cc"
655 "\n" 655 Matches strings ending in the literal ".cc".
656 " \"*.cc\"\n" 656
657 " Matches strings ending in the literal \".cc\".\n" 657 "\bwin/*"
658 "\n" 658 Matches "win/foo" and "foo/win/bar.cc" but not "iwin/foo".
659 " \"\\bwin/*\"\n" 659
660 " Matches \"win/foo\" and \"foo/win/bar.cc\" but not \"iwin/foo\".\n" 660 Sources assignment example
661 "\n" 661
662 "Sources assignment example\n" 662 # Filter out all _win files.
663 "\n" 663 set_sources_assignment_filter([ "*_win.cc", "*_win.h" ])
664 " # Filter out all _win files.\n" 664 sources = [ "a.cc", "b_win.cc" ]
665 " set_sources_assignment_filter([ \"*_win.cc\", \"*_win.h\" ])\n" 665 print(sources)
666 " sources = [ \"a.cc\", \"b_win.cc\" ]\n" 666 # Will print [ "a.cc" ]. b_win one was filtered out.)";
667 " print(sources)\n"
668 " # Will print [ \"a.cc\" ]. b_win one was filtered out.\n";
669 667
670 Value RunSetSourcesAssignmentFilter(Scope* scope, 668 Value RunSetSourcesAssignmentFilter(Scope* scope,
671 const FunctionCallNode* function, 669 const FunctionCallNode* function,
672 const std::vector<Value>& args, 670 const std::vector<Value>& args,
673 Err* err) { 671 Err* err) {
674 if (args.size() != 1) { 672 if (args.size() != 1) {
675 *err = Err(function, "set_sources_assignment_filter takes one argument."); 673 *err = Err(function, "set_sources_assignment_filter takes one argument.");
676 } else { 674 } else {
677 std::unique_ptr<PatternList> f(new PatternList); 675 std::unique_ptr<PatternList> f(new PatternList);
678 f->SetFromValue(args[0], err); 676 f->SetFromValue(args[0], err);
679 if (!err->has_error()) 677 if (!err->has_error())
680 scope->set_sources_assignment_filter(std::move(f)); 678 scope->set_sources_assignment_filter(std::move(f));
681 } 679 }
682 return Value(); 680 return Value();
683 } 681 }
684 682
685 // pool ------------------------------------------------------------------------ 683 // pool ------------------------------------------------------------------------
686 684
687 const char kPool[] = "pool"; 685 const char kPool[] = "pool";
688 const char kPool_HelpShort[] = 686 const char kPool_HelpShort[] =
689 "pool: Defines a pool object."; 687 "pool: Defines a pool object.";
690 const char kPool_Help[] = 688 const char kPool_Help[] =
691 "pool: Defines a pool object.\n" 689 R"*(pool: Defines a pool object.
692 "\n" 690
693 " Pool objects can be applied to a tool to limit the parallelism of the\n" 691 Pool objects can be applied to a tool to limit the parallelism of the
694 " build. This object has a single property \"depth\" corresponding to\n" 692 build. This object has a single property "depth" corresponding to
695 " the number of tasks that may run simultaneously.\n" 693 the number of tasks that may run simultaneously.
696 "\n" 694
697 " As the file containing the pool definition may be executed in the\n" 695 As the file containing the pool definition may be executed in the
698 " context of more than one toolchain it is recommended to specify an\n" 696 context of more than one toolchain it is recommended to specify an
699 " explicit toolchain when defining and referencing a pool.\n" 697 explicit toolchain when defining and referencing a pool.
700 "\n" 698
701 " A pool is referenced by its label just like a target.\n" 699 A pool is referenced by its label just like a target.
702 "\n" 700
703 "Variables\n" 701 Variables
704 "\n" 702
705 " depth*\n" 703 depth*
706 " * = required\n" 704 * = required
707 "\n" 705
708 "Example\n" 706 Example
709 "\n" 707
710 " if (current_toolchain == default_toolchain) {\n" 708 if (current_toolchain == default_toolchain) {
711 " pool(\"link_pool\") {\n" 709 pool("link_pool") {
712 " depth = 1\n" 710 depth = 1
713 " }\n" 711 }
714 " }\n" 712 }
715 "\n" 713
716 " toolchain(\"toolchain\") {\n" 714 toolchain("toolchain") {
717 " tool(\"link\") {\n" 715 tool("link") {
718 " command = \"...\"\n" 716 command = "..."
719 " pool = \":link_pool($default_toolchain)\")\n" 717 pool = ":link_pool($default_toolchain)")
720 " }\n" 718 }
721 " }\n"; 719 })*";
722 720
723 const char kDepth[] = "depth"; 721 const char kDepth[] = "depth";
724 722
725 Value RunPool(const FunctionCallNode* function, 723 Value RunPool(const FunctionCallNode* function,
726 const std::vector<Value>& args, 724 const std::vector<Value>& args,
727 Scope* scope, 725 Scope* scope,
728 Err* err) { 726 Err* err) {
729 NonNestableBlock non_nestable(scope, function, "pool"); 727 NonNestableBlock non_nestable(scope, function, "pool");
730 if (!non_nestable.Enter(err)) 728 if (!non_nestable.Enter(err))
731 return Value(); 729 return Value();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 767
770 return Value(); 768 return Value();
771 } 769 }
772 770
773 // print ----------------------------------------------------------------------- 771 // print -----------------------------------------------------------------------
774 772
775 const char kPrint[] = "print"; 773 const char kPrint[] = "print";
776 const char kPrint_HelpShort[] = 774 const char kPrint_HelpShort[] =
777 "print: Prints to the console."; 775 "print: Prints to the console.";
778 const char kPrint_Help[] = 776 const char kPrint_Help[] =
779 "print: Prints to the console.\n" 777 R"(print: Prints to the console.
780 "\n" 778
781 " Prints all arguments to the console separated by spaces. A newline is\n" 779 Prints all arguments to the console separated by spaces. A newline is
782 " automatically appended to the end.\n" 780 automatically appended to the end.
783 "\n" 781
784 " This function is intended for debugging. Note that build files are run\n" 782 This function is intended for debugging. Note that build files are run in
785 " in parallel so you may get interleaved prints. A buildfile may also\n" 783 parallel so you may get interleaved prints. A buildfile may also be executed
786 " be executed more than once in parallel in the context of different\n" 784 more than once in parallel in the context of different toolchains so the
787 " toolchains so the prints from one file may be duplicated or\n" 785 prints from one file may be duplicated or
788 " interleaved with itself.\n" 786 interleaved with itself.
789 "\n" 787
790 "Examples:\n" 788 Examples
791 " print(\"Hello world\")\n" 789
792 "\n" 790 print("Hello world")
793 " print(sources, deps)\n"; 791
792 print(sources, deps))";
794 793
795 Value RunPrint(Scope* scope, 794 Value RunPrint(Scope* scope,
796 const FunctionCallNode* function, 795 const FunctionCallNode* function,
797 const std::vector<Value>& args, 796 const std::vector<Value>& args,
798 Err* err) { 797 Err* err) {
799 std::string output; 798 std::string output;
800 for (size_t i = 0; i < args.size(); i++) { 799 for (size_t i = 0; i < args.size(); i++) {
801 if (i != 0) 800 if (i != 0)
802 output.push_back(' '); 801 output.push_back(' ');
803 output.append(args[i].ToString(false)); 802 output.append(args[i].ToString(false));
804 } 803 }
805 output.push_back('\n'); 804 output.push_back('\n');
806 805
807 const BuildSettings::PrintCallback& cb = 806 const BuildSettings::PrintCallback& cb =
808 scope->settings()->build_settings()->print_callback(); 807 scope->settings()->build_settings()->print_callback();
809 if (cb.is_null()) 808 if (cb.is_null())
810 printf("%s", output.c_str()); 809 printf("%s", output.c_str());
811 else 810 else
812 cb.Run(output); 811 cb.Run(output);
813 812
814 return Value(); 813 return Value();
815 } 814 }
816 815
817 // split_list ------------------------------------------------------------------ 816 // split_list ------------------------------------------------------------------
818 817
819 const char kSplitList[] = "split_list"; 818 const char kSplitList[] = "split_list";
820 const char kSplitList_HelpShort[] = 819 const char kSplitList_HelpShort[] =
821 "split_list: Splits a list into N different sub-lists."; 820 "split_list: Splits a list into N different sub-lists.";
822 const char kSplitList_Help[] = 821 const char kSplitList_Help[] =
823 "split_list: Splits a list into N different sub-lists.\n" 822 R"(split_list: Splits a list into N different sub-lists.
824 "\n" 823
825 " result = split_list(input, n)\n" 824 result = split_list(input, n)
826 "\n" 825
827 " Given a list and a number N, splits the list into N sub-lists of\n" 826 Given a list and a number N, splits the list into N sub-lists of
828 " approximately equal size. The return value is a list of the sub-lists.\n" 827 approximately equal size. The return value is a list of the sub-lists. The
829 " The result will always be a list of size N. If N is greater than the\n" 828 result will always be a list of size N. If N is greater than the number of
830 " number of elements in the input, it will be padded with empty lists.\n" 829 elements in the input, it will be padded with empty lists.
831 "\n" 830
832 " The expected use is to divide source files into smaller uniform\n" 831 The expected use is to divide source files into smaller uniform chunks.
833 " chunks.\n" 832
834 "\n" 833 Example
835 "Example\n" 834
836 "\n" 835 The code:
837 " The code:\n" 836 mylist = [1, 2, 3, 4, 5, 6]
838 " mylist = [1, 2, 3, 4, 5, 6]\n" 837 print(split_list(mylist, 3))
839 " print(split_list(mylist, 3))\n" 838
840 "\n" 839 Will print:
841 " Will print:\n" 840 [[1, 2], [3, 4], [5, 6])";
842 " [[1, 2], [3, 4], [5, 6]\n";
843 Value RunSplitList(Scope* scope, 841 Value RunSplitList(Scope* scope,
844 const FunctionCallNode* function, 842 const FunctionCallNode* function,
845 const ListNode* args_list, 843 const ListNode* args_list,
846 Err* err) { 844 Err* err) {
847 const auto& args_vector = args_list->contents(); 845 const auto& args_vector = args_list->contents();
848 if (args_vector.size() != 2) { 846 if (args_vector.size() != 2) {
849 *err = Err(function, "Wrong number of arguments to split_list().", 847 *err = Err(function, "Wrong number of arguments to split_list().",
850 "Expecting exactly two."); 848 "Expecting exactly two.");
851 return Value(); 849 return Value();
852 } 850 }
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 } 1097 }
1100 1098
1101 // Otherwise it's a no-block function. 1099 // Otherwise it's a no-block function.
1102 if (!VerifyNoBlockForFunctionCall(function, block, err)) 1100 if (!VerifyNoBlockForFunctionCall(function, block, err))
1103 return Value(); 1101 return Value();
1104 return found_function->second.no_block_runner(scope, function, 1102 return found_function->second.no_block_runner(scope, function,
1105 args.list_value(), err); 1103 args.list_value(), err);
1106 } 1104 }
1107 1105
1108 } // namespace functions 1106 } // namespace functions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698