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 <algorithm> | 5 #include <algorithm> |
6 #include <limits> | 6 #include <limits> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "tools/gn/err.h" | 9 #include "tools/gn/err.h" |
10 #include "tools/gn/functions.h" | 10 #include "tools/gn/functions.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 295 } |
296 | 296 |
297 } // namespace | 297 } // namespace |
298 | 298 |
299 // toolchain ------------------------------------------------------------------- | 299 // toolchain ------------------------------------------------------------------- |
300 | 300 |
301 const char kToolchain[] = "toolchain"; | 301 const char kToolchain[] = "toolchain"; |
302 const char kToolchain_HelpShort[] = | 302 const char kToolchain_HelpShort[] = |
303 "toolchain: Defines a toolchain."; | 303 "toolchain: Defines a toolchain."; |
304 const char kToolchain_Help[] = | 304 const char kToolchain_Help[] = |
305 "toolchain: Defines a toolchain.\n" | 305 R"*(toolchain: Defines a toolchain. |
306 "\n" | 306 |
307 " A toolchain is a set of commands and build flags used to compile the\n" | 307 A toolchain is a set of commands and build flags used to compile the source |
308 " source code. You can have more than one toolchain in use at once in\n" | 308 code. You can have more than one toolchain in use at once in a build. |
309 " a build.\n" | 309 |
310 "\n" | 310 Functions and variables |
311 "Functions and variables\n" | 311 |
312 "\n" | 312 tool() |
313 " tool()\n" | 313 The tool() function call specifies the commands commands to run for a given |
314 " The tool() function call specifies the commands commands to run for\n" | 314 step. See "gn help tool". |
315 " a given step. See \"gn help tool\".\n" | 315 |
316 "\n" | 316 toolchain_args |
317 " toolchain_args\n" | 317 Overrides for build arguments to pass to the toolchain when invoking it. |
318 " Overrides for build arguments to pass to the toolchain when invoking\n" | 318 This is a variable of type "scope" where the variable names correspond to |
319 " it. This is a variable of type \"scope\" where the variable names\n" | 319 variables in declare_args() blocks. |
320 " correspond to variables in declare_args() blocks.\n" | 320 |
321 "\n" | 321 When you specify a target using an alternate toolchain, the master build |
322 " When you specify a target using an alternate toolchain, the master\n" | 322 configuration file is re-interpreted in the context of that toolchain. |
323 " build configuration file is re-interpreted in the context of that\n" | 323 toolchain_args allows you to control the arguments passed into this |
324 " toolchain. toolchain_args allows you to control the arguments\n" | 324 alternate invocation of the build. |
325 " passed into this alternate invocation of the build.\n" | 325 |
326 "\n" | 326 Any default system arguments or arguments passed in via "gn args" will also |
327 " Any default system arguments or arguments passed in via \"gn args\"\n" | 327 be passed to the alternate invocation unless explicitly overridden by |
328 " will also be passed to the alternate invocation unless explicitly\n" | 328 toolchain_args. |
329 " overridden by toolchain_args.\n" | 329 |
330 "\n" | 330 The toolchain_args will be ignored when the toolchain being defined is the |
331 " The toolchain_args will be ignored when the toolchain being defined\n" | 331 default. In this case, it's expected you want the default argument values. |
332 " is the default. In this case, it's expected you want the default\n" | 332 |
333 " argument values.\n" | 333 See also "gn help buildargs" for an overview of these arguments. |
334 "\n" | 334 |
335 " See also \"gn help buildargs\" for an overview of these arguments.\n" | 335 deps |
336 "\n" | 336 Dependencies of this toolchain. These dependencies will be resolved before |
337 " deps\n" | 337 any target in the toolchain is compiled. To avoid circular dependencies |
338 " Dependencies of this toolchain. These dependencies will be resolved\n" | 338 these must be targets defined in another toolchain. |
339 " before any target in the toolchain is compiled. To avoid circular\n" | 339 |
340 " dependencies these must be targets defined in another toolchain.\n" | 340 This is expressed as a list of targets, and generally these targets will |
341 "\n" | 341 always specify a toolchain: |
342 " This is expressed as a list of targets, and generally these targets\n" | 342 deps = [ "//foo/bar:baz(//build/toolchain:bootstrap)" ] |
343 " will always specify a toolchain:\n" | 343 |
344 " deps = [ \"//foo/bar:baz(//build/toolchain:bootstrap)\" ]\n" | 344 This concept is somewhat inefficient to express in Ninja (it requires a lot |
345 "\n" | 345 of duplicate of rules) so should only be used when absolutely necessary. |
346 " This concept is somewhat inefficient to express in Ninja (it\n" | 346 |
347 " requires a lot of duplicate of rules) so should only be used when\n" | 347 Invoking targets in toolchains |
348 " absolutely necessary.\n" | 348 |
349 "\n" | 349 By default, when a target depends on another, there is an implicit toolchain |
350 "Invoking targets in toolchains:\n" | 350 label that is inherited, so the dependee has the same one as the dependent. |
351 "\n" | 351 |
352 " By default, when a target depends on another, there is an implicit\n" | 352 You can override this and refer to any other toolchain by explicitly |
353 " toolchain label that is inherited, so the dependee has the same one\n" | 353 labeling the toolchain to use. For example: |
354 " as the dependent.\n" | 354 data_deps = [ "//plugins:mine(//toolchains:plugin_toolchain)" ] |
355 "\n" | 355 The string "//build/toolchains:plugin_toolchain" is a label that identifies |
356 " You can override this and refer to any other toolchain by explicitly\n" | 356 the toolchain declaration for compiling the sources. |
357 " labeling the toolchain to use. For example:\n" | 357 |
358 " data_deps = [ \"//plugins:mine(//toolchains:plugin_toolchain)\" ]\n" | 358 To load a file in an alternate toolchain, GN does the following: |
359 " The string \"//build/toolchains:plugin_toolchain\" is a label that\n" | 359 |
360 " identifies the toolchain declaration for compiling the sources.\n" | 360 1. Loads the file with the toolchain definition in it (as determined by the |
361 "\n" | 361 toolchain label). |
362 " To load a file in an alternate toolchain, GN does the following:\n" | 362 2. Re-runs the master build configuration file, applying the arguments |
363 "\n" | 363 specified by the toolchain_args section of the toolchain definition. |
364 " 1. Loads the file with the toolchain definition in it (as determined\n" | 364 3. Loads the destination build file in the context of the configuration file |
365 " by the toolchain label).\n" | 365 in the previous step. |
366 " 2. Re-runs the master build configuration file, applying the\n" | 366 |
367 " arguments specified by the toolchain_args section of the toolchain\n" | 367 Example |
368 " definition.\n" | 368 |
369 " 3. Loads the destination build file in the context of the\n" | 369 toolchain("plugin_toolchain") { |
370 " configuration file in the previous step.\n" | 370 tool("cc") { |
371 "\n" | 371 command = "gcc {{source}}" |
372 "Example\n" | 372 ... |
373 "\n" | 373 } |
374 " toolchain(\"plugin_toolchain\") {\n" | 374 |
375 " tool(\"cc\") {\n" | 375 toolchain_args = { |
376 " command = \"gcc {{source}}\"\n" | 376 is_plugin = true |
377 " ...\n" | 377 is_32bit = true |
378 " }\n" | 378 is_64bit = false |
379 "\n" | 379 } |
380 " toolchain_args = {\n" | 380 }; |
381 " is_plugin = true\n" | 381 )*"; |
382 " is_32bit = true\n" | |
383 " is_64bit = false\n" | |
384 " }\n" | |
385 " }\n"; | |
386 | 382 |
387 Value RunToolchain(Scope* scope, | 383 Value RunToolchain(Scope* scope, |
388 const FunctionCallNode* function, | 384 const FunctionCallNode* function, |
389 const std::vector<Value>& args, | 385 const std::vector<Value>& args, |
390 BlockNode* block, | 386 BlockNode* block, |
391 Err* err) { | 387 Err* err) { |
392 NonNestableBlock non_nestable(scope, function, "toolchain"); | 388 NonNestableBlock non_nestable(scope, function, "toolchain"); |
393 if (!non_nestable.Enter(err)) | 389 if (!non_nestable.Enter(err)) |
394 return Value(); | 390 return Value(); |
395 | 391 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 collector->push_back(toolchain.release()); | 448 collector->push_back(toolchain.release()); |
453 return Value(); | 449 return Value(); |
454 } | 450 } |
455 | 451 |
456 // tool ------------------------------------------------------------------------ | 452 // tool ------------------------------------------------------------------------ |
457 | 453 |
458 const char kTool[] = "tool"; | 454 const char kTool[] = "tool"; |
459 const char kTool_HelpShort[] = | 455 const char kTool_HelpShort[] = |
460 "tool: Specify arguments to a toolchain tool."; | 456 "tool: Specify arguments to a toolchain tool."; |
461 const char kTool_Help[] = | 457 const char kTool_Help[] = |
462 "tool: Specify arguments to a toolchain tool.\n" | 458 R"(tool: Specify arguments to a toolchain tool. |
463 "\n" | 459 |
464 "Usage:\n" | 460 Usage |
465 "\n" | 461 |
466 " tool(<tool type>) {\n" | 462 tool(<tool type>) { |
467 " <tool variables...>\n" | 463 <tool variables...> |
468 " }\n" | 464 } |
469 "\n" | 465 |
470 "Tool types\n" | 466 Tool types |
471 "\n" | 467 |
472 " Compiler tools:\n" | 468 Compiler tools: |
473 " \"cc\": C compiler\n" | 469 "cc": C compiler |
474 " \"cxx\": C++ compiler\n" | 470 "cxx": C++ compiler |
475 " \"objc\": Objective C compiler\n" | 471 "objc": Objective C compiler |
476 " \"objcxx\": Objective C++ compiler\n" | 472 "objcxx": Objective C++ compiler |
477 " \"rc\": Resource compiler (Windows .rc files)\n" | 473 "rc": Resource compiler (Windows .rc files) |
478 " \"asm\": Assembler\n" | 474 "asm": Assembler |
479 "\n" | 475 |
480 " Linker tools:\n" | 476 Linker tools: |
481 " \"alink\": Linker for static libraries (archives)\n" | 477 "alink": Linker for static libraries (archives) |
482 " \"solink\": Linker for shared libraries\n" | 478 "solink": Linker for shared libraries |
483 " \"link\": Linker for executables\n" | 479 "link": Linker for executables |
484 "\n" | 480 |
485 " Other tools:\n" | 481 Other tools: |
486 " \"stamp\": Tool for creating stamp files\n" | 482 "stamp": Tool for creating stamp files |
487 " \"copy\": Tool to copy files.\n" | 483 "copy": Tool to copy files. |
488 "\n" | 484 |
489 " Platform specific tools:\n" | 485 Platform specific tools: |
490 " \"copy_bundle_data\": [iOS, OS X] Tool to copy files in a bundle.\n" | 486 "copy_bundle_data": [iOS, OS X] Tool to copy files in a bundle. |
491 " \"compile_xcassets\": [iOS, OS X] Tool to compile asset catalogs.\n" | 487 "compile_xcassets": [iOS, OS X] Tool to compile asset catalogs. |
492 "\n" | 488 |
493 "Tool variables\n" | 489 Tool variables |
494 "\n" | 490 |
495 " command [string with substitutions]\n" | 491 command [string with substitutions] |
496 " Valid for: all tools (required)\n" | 492 Valid for: all tools (required) |
497 "\n" | 493 |
498 " The command to run.\n" | 494 The command to run. |
499 "\n" | 495 |
500 " default_output_dir [string with substitutions]\n" | 496 default_output_dir [string with substitutions] |
501 " Valid for: linker tools\n" | 497 Valid for: linker tools |
502 "\n" | 498 |
503 " Default directory name for the output file relative to the\n" | 499 Default directory name for the output file relative to the |
504 " root_build_dir. It can contain other substitution patterns.\n" | 500 root_build_dir. It can contain other substitution patterns. This will |
505 " This will be the default value for the {{output_dir}} expansion\n" | 501 be the default value for the {{output_dir}} expansion (discussed below) |
506 " (discussed below) but will be overridden by the \"output_dir\"\n" | 502 but will be overridden by the "output_dir" variable in a target, if one |
507 " variable in a target, if one is specified.\n" | 503 is specified. |
508 "\n" | 504 |
509 " GN doesn't do anything with this string other than pass it\n" | 505 GN doesn't do anything with this string other than pass it along, |
510 " along, potentially with target-specific overrides. It is the\n" | 506 potentially with target-specific overrides. It is the tool's job to use |
511 " tool's job to use the expansion so that the files will be in\n" | 507 the expansion so that the files will be in the right place. |
512 " the right place.\n" | 508 |
513 "\n" | 509 default_output_extension [string] |
514 " default_output_extension [string]\n" | 510 Valid for: linker tools |
515 " Valid for: linker tools\n" | 511 |
516 "\n" | 512 Extension for the main output of a linkable tool. It includes the |
517 " Extension for the main output of a linkable tool. It includes\n" | 513 leading dot. This will be the default value for the |
518 " the leading dot. This will be the default value for the\n" | 514 {{output_extension}} expansion (discussed below) but will be overridden |
519 " {{output_extension}} expansion (discussed below) but will be\n" | 515 by by the "output extension" variable in a target, if one is specified. |
520 " overridden by by the \"output extension\" variable in a target,\n" | 516 Empty string means no extension. |
521 " if one is specified. Empty string means no extension.\n" | 517 |
522 "\n" | 518 GN doesn't actually do anything with this extension other than pass it |
523 " GN doesn't actually do anything with this extension other than\n" | 519 along, potentially with target-specific overrides. One would typically |
524 " pass it along, potentially with target-specific overrides. One\n" | 520 use the {{output_extension}} value in the "outputs" to read this value. |
525 " would typically use the {{output_extension}} value in the\n" | 521 |
526 " \"outputs\" to read this value.\n" | 522 Example: default_output_extension = ".exe" |
527 "\n" | 523 |
528 " Example: default_output_extension = \".exe\"\n" | 524 depfile [string with substitutions] |
529 "\n" | 525 Valid for: compiler tools (optional) |
530 " depfile [string with substitutions]\n" | 526 |
531 " Valid for: compiler tools (optional)\n" | 527 If the tool can write ".d" files, this specifies the name of the |
532 "\n" | 528 resulting file. These files are used to list header file dependencies |
533 " If the tool can write \".d\" files, this specifies the name of\n" | 529 (or other implicit input dependencies) that are discovered at build |
534 " the resulting file. These files are used to list header file\n" | 530 time. See also "depsformat". |
535 " dependencies (or other implicit input dependencies) that are\n" | 531 |
536 " discovered at build time. See also \"depsformat\".\n" | 532 Example: depfile = "{{output}}.d" |
537 "\n" | 533 |
538 " Example: depfile = \"{{output}}.d\"\n" | 534 depsformat [string] |
539 "\n" | 535 Valid for: compiler tools (when depfile is specified) |
540 " depsformat [string]\n" | 536 |
541 " Valid for: compiler tools (when depfile is specified)\n" | 537 Format for the deps outputs. This is either "gcc" or "msvc". See the |
542 "\n" | 538 ninja documentation for "deps" for more information. |
543 " Format for the deps outputs. This is either \"gcc\" or \"msvc\".\n" | 539 |
544 " See the ninja documentation for \"deps\" for more information.\n" | 540 Example: depsformat = "gcc" |
545 "\n" | 541 |
546 " Example: depsformat = \"gcc\"\n" | 542 description [string with substitutions, optional] |
547 "\n" | 543 Valid for: all tools |
548 " description [string with substitutions, optional]\n" | 544 |
549 " Valid for: all tools\n" | 545 What to print when the command is run. |
550 "\n" | 546 |
551 " What to print when the command is run.\n" | 547 Example: description = "Compiling {{source}}" |
552 "\n" | 548 |
553 " Example: description = \"Compiling {{source}}\"\n" | 549 lib_switch [string, optional, link tools only] |
554 "\n" | 550 lib_dir_switch [string, optional, link tools only] |
555 " lib_switch [string, optional, link tools only]\n" | 551 Valid for: Linker tools except "alink" |
556 " lib_dir_switch [string, optional, link tools only]\n" | 552 |
557 " Valid for: Linker tools except \"alink\"\n" | 553 These strings will be prepended to the libraries and library search |
558 "\n" | 554 directories, respectively, because linkers differ on how specify them. |
559 " These strings will be prepended to the libraries and library\n" | 555 If you specified: |
560 " search directories, respectively, because linkers differ on how\n" | 556 lib_switch = "-l" |
561 " specify them. If you specified:\n" | 557 lib_dir_switch = "-L" |
562 " lib_switch = \"-l\"\n" | 558 then the "{{libs}}" expansion for [ "freetype", "expat"] would be |
563 " lib_dir_switch = \"-L\"\n" | 559 "-lfreetype -lexpat". |
564 " then the \"{{libs}}\" expansion for [ \"freetype\", \"expat\"]\n" | 560 |
565 " would be \"-lfreetype -lexpat\".\n" | 561 outputs [list of strings with substitutions] |
566 "\n" | 562 Valid for: Linker and compiler tools (required) |
567 " outputs [list of strings with substitutions]\n" | 563 |
568 " Valid for: Linker and compiler tools (required)\n" | 564 An array of names for the output files the tool produces. These are |
569 "\n" | 565 relative to the build output directory. There must always be at least |
570 " An array of names for the output files the tool produces. These\n" | 566 one output file. There can be more than one output (a linker might |
571 " are relative to the build output directory. There must always be\n" | 567 produce a library and an import library, for example). |
572 " at least one output file. There can be more than one output (a\n" | 568 |
573 " linker might produce a library and an import library, for\n" | 569 This array just declares to GN what files the tool will produce. It is |
574 " example).\n" | 570 your responsibility to specify the tool command that actually produces |
575 "\n" | 571 these files. |
576 " This array just declares to GN what files the tool will\n" | 572 |
577 " produce. It is your responsibility to specify the tool command\n" | 573 If you specify more than one output for shared library links, you |
578 " that actually produces these files.\n" | 574 should consider setting link_output, depend_output, and |
579 "\n" | 575 runtime_outputs. |
580 " If you specify more than one output for shared library links,\n" | 576 |
581 " you should consider setting link_output, depend_output, and\n" | 577 Example for a compiler tool that produces .obj files: |
582 " runtime_outputs.\n" | 578 outputs = [ |
583 "\n" | 579 "{{source_out_dir}}/{{source_name_part}}.obj" |
584 " Example for a compiler tool that produces .obj files:\n" | 580 ] |
585 " outputs = [\n" | 581 |
586 " \"{{source_out_dir}}/{{source_name_part}}.obj\"\n" | 582 Example for a linker tool that produces a .dll and a .lib. The use of |
587 " ]\n" | 583 {{target_output_name}}, {{output_extension}} and {{output_dir}} allows |
588 "\n" | 584 the target to override these values. |
589 " Example for a linker tool that produces a .dll and a .lib. The\n" | 585 outputs = [ |
590 " use of {{target_output_name}}, {{output_extension}} and\n" | 586 "{{output_dir}}/{{target_output_name}}" |
591 " {{output_dir}} allows the target to override these values.\n" | 587 "{{output_extension}}", |
592 " outputs = [\n" | 588 "{{output_dir}}/{{target_output_name}}.lib", |
593 " \"{{output_dir}}/{{target_output_name}}" | 589 ] |
594 "{{output_extension}}\",\n" | 590 |
595 " \"{{output_dir}}/{{target_output_name}}.lib\",\n" | 591 pool [label, optional] |
596 " ]\n" | 592 |
597 "\n" | 593 Label of the pool to use for the tool. Pools are used to limit the |
598 " pool [label, optional]\n" | 594 number of tasks that can execute concurrently during the build. |
599 "\n" | 595 |
600 " Label of the pool to use for the tool. Pools are used to limit\n" | 596 See also "gn help pool". |
601 " the number of tasks that can execute concurrently during the\n" | 597 |
602 " build.\n" | 598 link_output [string with substitutions] |
603 "\n" | 599 depend_output [string with substitutions] |
604 " See also \"gn help pool\".\n" | 600 Valid for: "solink" only (optional) |
605 "\n" | 601 |
606 " link_output [string with substitutions]\n" | 602 These two files specify which of the outputs from the solink tool |
607 " depend_output [string with substitutions]\n" | 603 should be used for linking and dependency tracking. These should match |
608 " Valid for: \"solink\" only (optional)\n" | 604 entries in the "outputs". If unspecified, the first item in the |
609 "\n" | 605 "outputs" array will be used for all. See "Separate linking and |
610 " These two files specify which of the outputs from the solink\n" | 606 dependencies for shared libraries" below for more. |
611 " tool should be used for linking and dependency tracking. These\n" | 607 |
612 " should match entries in the \"outputs\". If unspecified, the\n" | 608 On Windows, where the tools produce a .dll shared library and a .lib |
613 " first item in the \"outputs\" array will be used for all. See\n" | 609 import library, you will want the first two to be the import library |
614 " \"Separate linking and dependencies for shared libraries\"\n" | 610 and the third one to be the .dll file. On Linux, if you're not doing |
615 " below for more.\n" | 611 the separate linking/dependency optimization, all of these should be |
616 "\n" | 612 the .so output. |
617 " On Windows, where the tools produce a .dll shared library and\n" | 613 |
618 " a .lib import library, you will want the first two to be the\n" | 614 output_prefix [string] |
619 " import library and the third one to be the .dll file.\n" | 615 Valid for: Linker tools (optional) |
620 " On Linux, if you're not doing the separate linking/dependency\n" | 616 |
621 " optimization, all of these should be the .so output.\n" | 617 Prefix to use for the output name. Defaults to empty. This prefix will |
622 "\n" | 618 be prepended to the name of the target (or the output_name if one is |
623 " output_prefix [string]\n" | 619 manually specified for it) if the prefix is not already there. The |
624 " Valid for: Linker tools (optional)\n" | 620 result will show up in the {{output_name}} substitution pattern. |
625 "\n" | 621 |
626 " Prefix to use for the output name. Defaults to empty. This\n" | 622 Individual targets can opt-out of the output prefix by setting: |
627 " prefix will be prepended to the name of the target (or the\n" | 623 output_prefix_override = true |
628 " output_name if one is manually specified for it) if the prefix\n" | 624 (see "gn help output_prefix_override"). |
629 " is not already there. The result will show up in the\n" | 625 |
630 " {{output_name}} substitution pattern.\n" | 626 This is typically used to prepend "lib" to libraries on |
631 "\n" | 627 Posix systems: |
632 " Individual targets can opt-out of the output prefix by setting:\n" | 628 output_prefix = "lib" |
633 " output_prefix_override = true\n" | 629 |
634 " (see \"gn help output_prefix_override\").\n" | 630 precompiled_header_type [string] |
635 "\n" | 631 Valid for: "cc", "cxx", "objc", "objcxx" |
636 " This is typically used to prepend \"lib\" to libraries on\n" | 632 |
637 " Posix systems:\n" | 633 Type of precompiled headers. If undefined or the empty string, |
638 " output_prefix = \"lib\"\n" | 634 precompiled headers will not be used for this tool. Otherwise use "gcc" |
639 "\n" | 635 or "msvc". |
640 " precompiled_header_type [string]\n" | 636 |
641 " Valid for: \"cc\", \"cxx\", \"objc\", \"objcxx\"\n" | 637 For precompiled headers to be used for a given target, the target (or a |
642 "\n" | 638 config applied to it) must also specify a "precompiled_header" and, for |
643 " Type of precompiled headers. If undefined or the empty string,\n" | 639 "msvc"-style headers, a "precompiled_source" value. If the type is |
644 " precompiled headers will not be used for this tool. Otherwise\n" | 640 "gcc", then both "precompiled_header" and "precompiled_source" must |
645 " use \"gcc\" or \"msvc\".\n" | 641 resolve to the same file, despite the different formats required for |
646 "\n" | 642 each." |
647 " For precompiled headers to be used for a given target, the\n" | 643 |
648 " target (or a config applied to it) must also specify a\n" | 644 See "gn help precompiled_header" for more. |
649 " \"precompiled_header\" and, for \"msvc\"-style headers, a\n" | 645 |
650 " \"precompiled_source\" value. If the type is \"gcc\", then both\n" | 646 restat [boolean] |
651 " \"precompiled_header\" and \"precompiled_source\" must resolve\n" | 647 Valid for: all tools (optional, defaults to false) |
652 " to the same file, despite the different formats required for each." | 648 |
653 "\n" | 649 Requests that Ninja check the file timestamp after this tool has run to |
654 " See \"gn help precompiled_header\" for more.\n" | 650 determine if anything changed. Set this if your tool has the ability to |
655 "\n" | 651 skip writing output if the output file has not changed. |
656 " restat [boolean]\n" | 652 |
657 " Valid for: all tools (optional, defaults to false)\n" | 653 Normally, Ninja will assume that when a tool runs the output be new and |
658 "\n" | 654 downstream dependents must be rebuild. When this is set to trye, Ninja |
659 " Requests that Ninja check the file timestamp after this tool has\n" | 655 can skip rebuilding downstream dependents for input changes that don't |
660 " run to determine if anything changed. Set this if your tool has\n" | 656 actually affect the output. |
661 " the ability to skip writing output if the output file has not\n" | 657 |
662 " changed.\n" | 658 Example: |
663 "\n" | 659 restat = true |
664 " Normally, Ninja will assume that when a tool runs the output\n" | 660 |
665 " be new and downstream dependents must be rebuild. When this is\n" | 661 rspfile [string with substitutions] |
666 " set to trye, Ninja can skip rebuilding downstream dependents for\n" | 662 Valid for: all tools (optional) |
667 " input changes that don't actually affect the output.\n" | 663 |
668 "\n" | 664 Name of the response file. If empty, no response file will be |
669 " Example:\n" | 665 used. See "rspfile_content". |
670 " restat = true\n" | 666 |
671 "\n" | 667 rspfile_content [string with substitutions] |
672 " rspfile [string with substitutions]\n" | 668 Valid for: all tools (required when "rspfile" is specified) |
673 " Valid for: all tools (optional)\n" | 669 |
674 "\n" | 670 The contents to be written to the response file. This may include all |
675 " Name of the response file. If empty, no response file will be\n" | 671 or part of the command to send to the tool which allows you to get |
676 " used. See \"rspfile_content\".\n" | 672 around OS command-line length limits. |
677 "\n" | 673 |
678 " rspfile_content [string with substitutions]\n" | 674 This example adds the inputs and libraries to a response file, but |
679 " Valid for: all tools (required when \"rspfile\" is specified)\n" | 675 passes the linker flags directly on the command line: |
680 "\n" | 676 tool("link") { |
681 " The contents to be written to the response file. This may\n" | 677 command = "link -o {{output}} {{ldflags}} @{{output}}.rsp" |
682 " include all or part of the command to send to the tool which\n" | 678 rspfile = "{{output}}.rsp" |
683 " allows you to get around OS command-line length limits.\n" | 679 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" |
684 "\n" | 680 } |
685 " This example adds the inputs and libraries to a response file,\n" | 681 |
686 " but passes the linker flags directly on the command line:\n" | 682 runtime_outputs [string list with substitutions] |
687 " tool(\"link\") {\n" | 683 Valid for: linker tools |
688 " command = \"link -o {{output}} {{ldflags}} @{{output}}.rsp\"\n" | 684 |
689 " rspfile = \"{{output}}.rsp\"\n" | 685 If specified, this list is the subset of the outputs that should be |
690 " rspfile_content = \"{{inputs}} {{solibs}} {{libs}}\"\n" | 686 added to runtime deps (see "gn help runtime_deps"). By default (if |
691 " }\n" | 687 runtime_outputs is empty or unspecified), it will be the link_output. |
692 "\n" | 688 |
693 " runtime_outputs [string list with substitutions]\n" | 689 Expansions for tool variables |
694 " Valid for: linker tools\n" | 690 |
695 "\n" | 691 All paths are relative to the root build directory, which is the current |
696 " If specified, this list is the subset of the outputs that should\n" | 692 directory for running all tools. These expansions are available to all tools: |
697 " be added to runtime deps (see \"gn help runtime_deps\"). By\n" | 693 |
698 " default (if runtime_outputs is empty or unspecified), it will be\n" | 694 {{label}} |
699 " the link_output.\n" | 695 The label of the current target. This is typically used in the |
700 "\n" | 696 "description" field for link tools. The toolchain will be omitted from |
701 "Expansions for tool variables\n" | 697 the label for targets in the default toolchain, and will be included |
702 "\n" | 698 for targets in other toolchains. |
703 " All paths are relative to the root build directory, which is the\n" | 699 |
704 " current directory for running all tools. These expansions are\n" | 700 {{label_name}} |
705 " available to all tools:\n" | 701 The short name of the label of the target. This is the part after the |
706 "\n" | 702 colon. For "//foo/bar:baz" this will be "baz". Unlike |
707 " {{label}}\n" | 703 {{target_output_name}}, this is not affected by the "output_prefix" in |
708 " The label of the current target. This is typically used in the\n" | 704 the tool or the "output_name" set on the target. |
709 " \"description\" field for link tools. The toolchain will be\n" | 705 |
710 " omitted from the label for targets in the default toolchain, and\n" | 706 {{output}} |
711 " will be included for targets in other toolchains.\n" | 707 The relative path and name of the output(s) of the current build step. |
712 "\n" | 708 If there is more than one output, this will expand to a list of all of |
713 " {{label_name}}\n" | 709 them. Example: "out/base/my_file.o" |
714 " The short name of the label of the target. This is the part\n" | 710 |
715 " after the colon. For \"//foo/bar:baz\" this will be \"baz\".\n" | 711 {{target_gen_dir}} |
716 " Unlike {{target_output_name}}, this is not affected by the\n" | 712 {{target_out_dir}} |
717 " \"output_prefix\" in the tool or the \"output_name\" set\n" | 713 The directory of the generated file and output directories, |
718 " on the target.\n" | 714 respectively, for the current target. There is no trailing slash. See |
719 "\n" | 715 also {{output_dir}} for linker tools. Example: "out/base/test" |
720 " {{output}}\n" | 716 |
721 " The relative path and name of the output(s) of the current\n" | 717 {{target_output_name}} |
722 " build step. If there is more than one output, this will expand\n" | 718 The short name of the current target with no path information, or the |
723 " to a list of all of them.\n" | 719 value of the "output_name" variable if one is specified in the target. |
724 " Example: \"out/base/my_file.o\"\n" | 720 This will include the "output_prefix" if any. See also {{label_name}}. |
725 "\n" | 721 |
726 " {{target_gen_dir}}\n" | 722 Example: "libfoo" for the target named "foo" and an output prefix for |
727 " {{target_out_dir}}\n" | 723 the linker tool of "lib". |
728 " The directory of the generated file and output directories,\n" | 724 |
729 " respectively, for the current target. There is no trailing\n" | 725 )" // String break to prevent overflowing the 16K max VC string length. |
730 " slash. See also {{output_dir}} for linker tools.\n" | 726 R"( Compiler tools have the notion of a single input and a single output, along |
731 " Example: \"out/base/test\"\n" | 727 with a set of compiler-specific flags. The following expansions are |
732 "\n" | 728 available: |
733 " {{target_output_name}}\n" | 729 |
734 " The short name of the current target with no path information,\n" | 730 {{asmflags}} |
735 " or the value of the \"output_name\" variable if one is specified\n" | 731 {{cflags}} |
736 " in the target. This will include the \"output_prefix\" if any.\n" | 732 {{cflags_c}} |
737 " See also {{label_name}}.\n" | 733 {{cflags_cc}} |
738 " Example: \"libfoo\" for the target named \"foo\" and an\n" | 734 {{cflags_objc}} |
739 " output prefix for the linker tool of \"lib\".\n" | 735 {{cflags_objcc}} |
740 "\n" | 736 {{defines}} |
741 " Compiler tools have the notion of a single input and a single output,\n" | 737 {{include_dirs}} |
742 " along with a set of compiler-specific flags. The following expansions\n" | 738 Strings correspond that to the processed flags/defines/include |
743 " are available:\n" | 739 directories specified for the target. |
744 "\n" | 740 Example: "--enable-foo --enable-bar" |
745 " {{asmflags}}\n" | 741 |
746 " {{cflags}}\n" | 742 Defines will be prefixed by "-D" and include directories will be |
747 " {{cflags_c}}\n" | 743 prefixed by "-I" (these work with Posix tools as well as Microsoft |
748 " {{cflags_cc}}\n" | 744 ones). |
749 " {{cflags_objc}}\n" | 745 |
750 " {{cflags_objcc}}\n" | 746 {{source}} |
751 " {{defines}}\n" | 747 The relative path and name of the current input file. |
752 " {{include_dirs}}\n" | 748 Example: "../../base/my_file.cc" |
753 " Strings correspond that to the processed flags/defines/include\n" | 749 |
754 " directories specified for the target.\n" | 750 {{source_file_part}} |
755 " Example: \"--enable-foo --enable-bar\"\n" | 751 The file part of the source including the extension (with no directory |
756 "\n" | 752 information). |
757 " Defines will be prefixed by \"-D\" and include directories will\n" | 753 Example: "foo.cc" |
758 " be prefixed by \"-I\" (these work with Posix tools as well as\n" | 754 |
759 " Microsoft ones).\n" | 755 {{source_name_part}} |
760 "\n" | 756 The filename part of the source file with no directory or extension. |
761 " {{source}}\n" | 757 Example: "foo" |
762 " The relative path and name of the current input file.\n" | 758 |
763 " Example: \"../../base/my_file.cc\"\n" | 759 {{source_gen_dir}} |
764 "\n" | 760 {{source_out_dir}} |
765 " {{source_file_part}}\n" | 761 The directory in the generated file and output directories, |
766 " The file part of the source including the extension (with no\n" | 762 respectively, for the current input file. If the source file is in the |
767 " directory information).\n" | 763 same directory as the target is declared in, they will will be the same |
768 " Example: \"foo.cc\"\n" | 764 as the "target" versions above. Example: "gen/base/test" |
769 "\n" | 765 |
770 " {{source_name_part}}\n" | 766 Linker tools have multiple inputs and (potentially) multiple outputs The |
771 " The filename part of the source file with no directory or\n" | 767 static library tool ("alink") is not considered a linker tool. The following |
772 " extension.\n" | 768 expansions are available: |
773 " Example: \"foo\"\n" | 769 |
774 "\n" | 770 {{inputs}} |
775 " {{source_gen_dir}}\n" | 771 {{inputs_newline}} |
776 " {{source_out_dir}}\n" | 772 Expands to the inputs to the link step. This will be a list of object |
777 " The directory in the generated file and output directories,\n" | 773 files and static libraries. |
778 " respectively, for the current input file. If the source file\n" | 774 Example: "obj/foo.o obj/bar.o obj/somelibrary.a" |
779 " is in the same directory as the target is declared in, they will\n" | 775 |
780 " will be the same as the \"target\" versions above.\n" | 776 The "_newline" version will separate the input files with newlines |
781 " Example: \"gen/base/test\"\n" | 777 instead of spaces. This is useful in response files: some linkers can |
782 "\n" | 778 take a "-filelist" flag which expects newline separated files, and some |
783 " Linker tools have multiple inputs and (potentially) multiple outputs\n" | 779 Microsoft tools have a fixed-sized buffer for parsing each line of a |
784 " The static library tool (\"alink\") is not considered a linker tool.\n" | 780 response file. |
785 " The following expansions are available:\n" | 781 |
786 "\n" | 782 {{ldflags}} |
787 " {{inputs}}\n" | 783 Expands to the processed set of ldflags and library search paths |
788 " {{inputs_newline}}\n" | 784 specified for the target. |
789 " Expands to the inputs to the link step. This will be a list of\n" | 785 Example: "-m64 -fPIC -pthread -L/usr/local/mylib" |
790 " object files and static libraries.\n" | 786 |
791 " Example: \"obj/foo.o obj/bar.o obj/somelibrary.a\"\n" | 787 {{libs}} |
792 "\n" | 788 Expands to the list of system libraries to link to. Each will be |
793 " The \"_newline\" version will separate the input files with\n" | 789 prefixed by the "lib_prefix". |
794 " newlines instead of spaces. This is useful in response files:\n" | 790 |
795 " some linkers can take a \"-filelist\" flag which expects newline\n" | 791 As a special case to support Mac, libraries with names ending in |
796 " separated files, and some Microsoft tools have a fixed-sized\n" | 792 ".framework" will be added to the {{libs}} with "-framework" preceeding |
797 " buffer for parsing each line of a response file.\n" | 793 it, and the lib prefix will be ignored. |
798 "\n" | 794 |
799 " {{ldflags}}\n" | 795 Example: "-lfoo -lbar" |
800 " Expands to the processed set of ldflags and library search paths\n" | 796 |
801 " specified for the target.\n" | 797 {{output_dir}} |
802 " Example: \"-m64 -fPIC -pthread -L/usr/local/mylib\"\n" | 798 The value of the "output_dir" variable in the target, or the the value |
803 "\n" | 799 of the "default_output_dir" value in the tool if the target does not |
804 " {{libs}}\n" | 800 override the output directory. This will be relative to the |
805 " Expands to the list of system libraries to link to. Each will\n" | 801 root_build_dir and will not end in a slash. Will be "." for output to |
806 " be prefixed by the \"lib_prefix\".\n" | 802 the root_build_dir. |
807 "\n" | 803 |
808 " As a special case to support Mac, libraries with names ending in\n" | 804 This is subtly different than {{target_out_dir}} which is defined by GN |
809 " \".framework\" will be added to the {{libs}} with \"-framework\"\n" | 805 based on the target's path and not overridable. {{output_dir}} is for |
810 " preceeding it, and the lib prefix will be ignored.\n" | 806 the final output, {{target_out_dir}} is generally for object files and |
811 "\n" | 807 other outputs. |
812 " Example: \"-lfoo -lbar\"\n" | 808 |
813 "\n" | 809 Usually {{output_dir}} would be defined in terms of either |
814 " {{output_dir}}\n" | 810 {{target_out_dir}} or {{root_out_dir}} |
815 " The value of the \"output_dir\" variable in the target, or the\n" | 811 |
816 " the value of the \"default_output_dir\" value in the tool if the\n" | 812 {{output_extension}} |
817 " target does not override the output directory. This will be\n" | 813 The value of the "output_extension" variable in the target, or the |
818 " relative to the root_build_dir and will not end in a slash.\n" | 814 value of the "default_output_extension" value in the tool if the target |
819 " Will be \".\" for output to the root_build_dir.\n" | 815 does not specify an output extension. |
820 "\n" | 816 Example: ".so" |
821 " This is subtly different than {{target_out_dir}} which is\n" | 817 |
822 " defined by GN based on the target's path and not overridable.\n" | 818 {{solibs}} |
823 " {{output_dir}} is for the final output, {{target_out_dir}} is\n" | 819 Extra libraries from shared library dependencide not specified in the |
824 " generally for object files and other outputs.\n" | 820 {{inputs}}. This is the list of link_output files from shared libraries |
825 "\n" | 821 (if the solink tool specifies a "link_output" variable separate from |
826 " Usually {{output_dir}} would be defined in terms of either\n" | 822 the "depend_output"). |
827 " {{target_out_dir}} or {{root_out_dir}}\n" | 823 |
828 "\n" | 824 These should generally be treated the same as libs by your tool. |
829 " {{output_extension}}\n" | 825 |
830 " The value of the \"output_extension\" variable in the target,\n" | 826 Example: "libfoo.so libbar.so" |
831 " or the value of the \"default_output_extension\" value in the\n" | 827 |
832 " tool if the target does not specify an output extension.\n" | 828 )" // String break to prevent overflowing the 16K max VC string length. |
833 " Example: \".so\"\n" | 829 R"( The static library ("alink") tool allows {{arflags}} plus the common tool |
834 "\n" | 830 substitutions. |
835 " {{solibs}}\n" | 831 |
836 " Extra libraries from shared library dependencide not specified\n" | 832 The copy tool allows the common compiler/linker substitutions, plus |
837 " in the {{inputs}}. This is the list of link_output files from\n" | 833 {{source}} which is the source of the copy. The stamp tool allows only the |
838 " shared libraries (if the solink tool specifies a \"link_output\"\n" | 834 common tool substitutions. |
839 " variable separate from the \"depend_output\").\n" | 835 |
840 "\n" | 836 The copy_bundle_data and compile_xcassets tools only allows the common tool |
841 " These should generally be treated the same as libs by your tool.\n" | 837 substitutions. Both tools are required to create iOS/OS X bundles and need |
842 " Example: \"libfoo.so libbar.so\"\n" | 838 only be defined on those platforms. |
843 "\n" | 839 |
844 " The static library (\"alink\") tool allows {{arflags}} plus the common\n" | 840 The copy_bundle_data tool will be called with one source and needs to copy |
845 " tool substitutions.\n" | 841 (optionally optimizing the data representation) to its output. It may be |
846 "\n" | 842 called with a directory as input and it needs to be recursively copied. |
847 " The copy tool allows the common compiler/linker substitutions, plus\n" | 843 |
848 " {{source}} which is the source of the copy. The stamp tool allows\n" | 844 The compile_xcassets tool will be called with one or more source (each an |
849 " only the common tool substitutions.\n" | 845 asset catalog) that needs to be compiled to a single output. The following |
850 "\n" | 846 substitutions are avaiable: |
851 " The copy_bundle_data and compile_xcassets tools only allows the common\n" | 847 |
852 " tool substitutions. Both tools are required to create iOS/OS X bundles\n" | 848 {{inputs}} |
853 " and need only be defined on those platforms.\n" | 849 Expands to the list of .xcassets to use as input to compile the asset |
854 "\n" | 850 catalog. |
855 " The copy_bundle_data tool will be called with one source and needs to\n" | 851 |
856 " copy (optionally optimizing the data representation) to its output. It\n" | 852 {{bundle_product_type}} |
857 " may be called with a directory as input and it needs to be recursively\n" | 853 Expands to the product_type of the bundle that will contain the |
858 " copied.\n" | 854 compiled asset catalog. Usually corresponds to the product_type |
859 "\n" | 855 property of the corresponding create_bundle target. |
860 " The compile_xcassets tool will be called with one or more source (each\n" | 856 |
861 " an asset catalog) that needs to be compiled to a single output. The\n" | 857 Separate linking and dependencies for shared libraries |
862 " following substitutions are avaiable:\n" | 858 |
863 "\n" | 859 Shared libraries are special in that not all changes to them require that |
864 " {{inputs}}\n" | 860 dependent targets be re-linked. If the shared library is changed but no |
865 " Expands to the list of .xcassets to use as input to compile the\n" | 861 imports or exports are different, dependent code needn't be relinked, which |
866 " asset catalog.\n" | 862 can speed up the build. |
867 "\n" | 863 |
868 " {{bundle_product_type}}\n" | 864 If your link step can output a list of exports from a shared library and |
869 " Expands to the product_type of the bundle that will contain the\n" | 865 writes the file only if the new one is different, the timestamp of this file |
870 " compiled asset catalog. Usually corresponds to the product_type\n" | 866 can be used for triggering re-links, while the actual shared library would be |
871 " property of the corresponding create_bundle target.\n" | 867 used for linking. |
872 "\n" | 868 |
873 "Separate linking and dependencies for shared libraries\n" | 869 You will need to specify |
874 "\n" | 870 restat = true |
875 " Shared libraries are special in that not all changes to them require\n" | 871 in the linker tool to make this work, so Ninja will detect if the timestamp |
876 " that dependent targets be re-linked. If the shared library is changed\n" | 872 of the dependency file has changed after linking (otherwise it will always |
877 " but no imports or exports are different, dependent code needn't be\n" | 873 assume that running a command updates the output): |
878 " relinked, which can speed up the build.\n" | 874 |
879 "\n" | 875 tool("solink") { |
880 " If your link step can output a list of exports from a shared library\n" | 876 command = "..." |
881 " and writes the file only if the new one is different, the timestamp of\n" | 877 outputs = [ |
882 " this file can be used for triggering re-links, while the actual shared\n" | 878 "{{output_dir}}/{{target_output_name}}{{output_extension}}", |
883 " library would be used for linking.\n" | 879 "{{output_dir}}/{{target_output_name}}" |
884 "\n" | 880 "{{output_extension}}.TOC", |
885 " You will need to specify\n" | 881 ] |
886 " restat = true\n" | 882 link_output = |
887 " in the linker tool to make this work, so Ninja will detect if the\n" | 883 "{{output_dir}}/{{target_output_name}}{{output_extension}}" |
888 " timestamp of the dependency file has changed after linking (otherwise\n" | 884 depend_output = |
889 " it will always assume that running a command updates the output):\n" | 885 "{{output_dir}}/{{target_output_name}}" |
890 "\n" | 886 "{{output_extension}}.TOC" |
891 " tool(\"solink\") {\n" | 887 restat = true |
892 " command = \"...\"\n" | 888 } |
893 " outputs = [\n" | 889 |
894 " \"{{output_dir}}/{{target_output_name}}{{output_extension}}\",\n" | 890 Example |
895 " \"{{output_dir}}/{{target_output_name}}" | 891 |
896 "{{output_extension}}.TOC\",\n" | 892 toolchain("my_toolchain") { |
897 " ]\n" | 893 # Put these at the top to apply to all tools below. |
898 " link_output =\n" | 894 lib_prefix = "-l" |
899 " \"{{output_dir}}/{{target_output_name}}{{output_extension}}\"\n" | 895 lib_dir_prefix = "-L" |
900 " depend_output =\n" | 896 |
901 " \"{{output_dir}}/{{target_output_name}}" | 897 tool("cc") { |
902 "{{output_extension}}.TOC\"\n" | 898 command = "gcc {{source}} -o {{output}}" |
903 " restat = true\n" | 899 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] |
904 " }\n" | 900 description = "GCC {{source}}" |
905 "\n" | 901 } |
906 "Example\n" | 902 tool("cxx") { |
907 "\n" | 903 command = "g++ {{source}} -o {{output}}" |
908 " toolchain(\"my_toolchain\") {\n" | 904 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] |
909 " # Put these at the top to apply to all tools below.\n" | 905 description = "G++ {{source}}" |
910 " lib_prefix = \"-l\"\n" | 906 } |
911 " lib_dir_prefix = \"-L\"\n" | 907 }; |
912 "\n" | 908 )"; |
913 " tool(\"cc\") {\n" | |
914 " command = \"gcc {{source}} -o {{output}}\"\n" | |
915 " outputs = [ \"{{source_out_dir}}/{{source_name_part}}.o\" ]\n" | |
916 " description = \"GCC {{source}}\"\n" | |
917 " }\n" | |
918 " tool(\"cxx\") {\n" | |
919 " command = \"g++ {{source}} -o {{output}}\"\n" | |
920 " outputs = [ \"{{source_out_dir}}/{{source_name_part}}.o\" ]\n" | |
921 " description = \"G++ {{source}}\"\n" | |
922 " }\n" | |
923 " }\n"; | |
924 | 909 |
925 Value RunTool(Scope* scope, | 910 Value RunTool(Scope* scope, |
926 const FunctionCallNode* function, | 911 const FunctionCallNode* function, |
927 const std::vector<Value>& args, | 912 const std::vector<Value>& args, |
928 BlockNode* block, | 913 BlockNode* block, |
929 Err* err) { | 914 Err* err) { |
930 // Find the toolchain definition we're executing inside of. The toolchain | 915 // Find the toolchain definition we're executing inside of. The toolchain |
931 // function will set a property pointing to it that we'll pick up. | 916 // function will set a property pointing to it that we'll pick up. |
932 Toolchain* toolchain = reinterpret_cast<Toolchain*>( | 917 Toolchain* toolchain = reinterpret_cast<Toolchain*>( |
933 scope->GetProperty(&kToolchainPropertyKey, nullptr)); | 918 scope->GetProperty(&kToolchainPropertyKey, nullptr)); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 | 1031 |
1047 // Make sure there weren't any vars set in this tool that were unused. | 1032 // Make sure there weren't any vars set in this tool that were unused. |
1048 if (!block_scope.CheckForUnusedVars(err)) | 1033 if (!block_scope.CheckForUnusedVars(err)) |
1049 return Value(); | 1034 return Value(); |
1050 | 1035 |
1051 toolchain->SetTool(tool_type, std::move(tool)); | 1036 toolchain->SetTool(tool_type, std::move(tool)); |
1052 return Value(); | 1037 return Value(); |
1053 } | 1038 } |
1054 | 1039 |
1055 } // namespace functions | 1040 } // namespace functions |
OLD | NEW |