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/functions.h" | 5 #include "tools/gn/functions.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 const char kDeclareArgs_Help[] = | 337 const char kDeclareArgs_Help[] = |
338 "declare_args: Declare build arguments.\n" | 338 "declare_args: Declare build arguments.\n" |
339 "\n" | 339 "\n" |
340 " Introduces the given arguments into the current scope. If they are\n" | 340 " Introduces the given arguments into the current scope. If they are\n" |
341 " not specified on the command line or in a toolchain's arguments,\n" | 341 " not specified on the command line or in a toolchain's arguments,\n" |
342 " the default values given in the declare_args block will be used.\n" | 342 " the default values given in the declare_args block will be used.\n" |
343 " However, these defaults will not override command-line values.\n" | 343 " However, these defaults will not override command-line values.\n" |
344 "\n" | 344 "\n" |
345 " See also \"gn help buildargs\" for an overview.\n" | 345 " See also \"gn help buildargs\" for an overview.\n" |
346 "\n" | 346 "\n" |
347 "Example:\n" | 347 " The precise behavior of declare args is:\n" |
| 348 "\n" |
| 349 " 1. The declare_arg block executes. Any variables in the enclosing\n" |
| 350 " scope are available for reading.\n" |
| 351 "\n" |
| 352 " 2. At the end of executing the block, any variables set within that\n" |
| 353 " scope are saved globally as build arguments, with their current\n" |
| 354 " values being saved as the \"default value\" for that argument.\n" |
| 355 "\n" |
| 356 " 3. User-defined overrides are applied. Anything set in \"gn args\"\n" |
| 357 " now overrides any default values. The resulting set of variables\n" |
| 358 " is promoted to be readable from the following code in the file.\n" |
| 359 "\n" |
| 360 " This has some ramifications that may not be obvious:\n" |
| 361 "\n" |
| 362 " - You should not perform difficult work inside a declare_args block\n" |
| 363 " since this only sets a default value that may be discarded. In\n" |
| 364 " particular, don't use the result of exec_script() to set the\n" |
| 365 " default value. If you want to have a script-defined default, set\n" |
| 366 " some default \"undefined\" value like [], \"\", or -1, and after\n" |
| 367 " the declare_args block, call exec_script if the value is unset by\n" |
| 368 " the user.\n" |
| 369 "\n" |
| 370 " - Any code inside of the declare_args block will see the default\n" |
| 371 " values of previous variables defined in the block rather than\n" |
| 372 " the user-overridden value. This can be surprising because you will\n" |
| 373 " be used to seeing the overridden value. If you need to make the\n" |
| 374 " default value of one arg dependent on the possibly-overridden\n" |
| 375 " value of another, write two separate declare_args blocks:\n" |
| 376 "\n" |
| 377 " declare_args() {\n" |
| 378 " enable_foo = true\n" |
| 379 " }\n" |
| 380 " declare_args() {\n" |
| 381 " # Bar defaults to same user-overridden state as foo.\n" |
| 382 " enable_bar = enable_foo\n" |
| 383 " }\n" |
| 384 "\n" |
| 385 "Example\n" |
| 386 "\n" |
348 " declare_args() {\n" | 387 " declare_args() {\n" |
349 " enable_teleporter = true\n" | 388 " enable_teleporter = true\n" |
350 " enable_doom_melon = false\n" | 389 " enable_doom_melon = false\n" |
351 " }\n" | 390 " }\n" |
352 "\n" | 391 "\n" |
353 " If you want to override the (default disabled) Doom Melon:\n" | 392 " If you want to override the (default disabled) Doom Melon:\n" |
354 " gn --args=\"enable_doom_melon=true enable_teleporter=false\"\n" | 393 " gn --args=\"enable_doom_melon=true enable_teleporter=false\"\n" |
355 " This also sets the teleporter, but it's already defaulted to on so\n" | 394 " This also sets the teleporter, but it's already defaulted to on so\n" |
356 " it will have no effect.\n"; | 395 " it will have no effect.\n"; |
357 | 396 |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } | 913 } |
875 | 914 |
876 // Otherwise it's a no-block function. | 915 // Otherwise it's a no-block function. |
877 if (!VerifyNoBlockForFunctionCall(function, block, err)) | 916 if (!VerifyNoBlockForFunctionCall(function, block, err)) |
878 return Value(); | 917 return Value(); |
879 return found_function->second.no_block_runner(scope, function, | 918 return found_function->second.no_block_runner(scope, function, |
880 args.list_value(), err); | 919 args.list_value(), err); |
881 } | 920 } |
882 | 921 |
883 } // namespace functions | 922 } // namespace functions |
OLD | NEW |