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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 " are relative to the build output directory. There must always be\n" | 474 " are relative to the build output directory. There must always be\n" |
475 " at least one output file. There can be more than one output (a\n" | 475 " at least one output file. There can be more than one output (a\n" |
476 " linker might produce a library and an import library, for\n" | 476 " linker might produce a library and an import library, for\n" |
477 " example).\n" | 477 " example).\n" |
478 "\n" | 478 "\n" |
479 " This array just declares to GN what files the tool will\n" | 479 " This array just declares to GN what files the tool will\n" |
480 " produce. It is your responsibility to specify the tool command\n" | 480 " produce. It is your responsibility to specify the tool command\n" |
481 " that actually produces these files.\n" | 481 " that actually produces these files.\n" |
482 "\n" | 482 "\n" |
483 " If you specify more than one output for shared library links,\n" | 483 " If you specify more than one output for shared library links,\n" |
484 " you should consider setting link_output and depend_output.\n" | 484 " you should consider setting link_output, depend_output, and\n" |
485 " Otherwise, the first entry in the outputs list should always be\n" | 485 " runtime_link_output. Otherwise, the first entry in the\n" |
486 " the main output which will be linked to.\n" | 486 " outputs list should always be the main output which will be\n" |
487 " linked to.\n" | |
487 "\n" | 488 "\n" |
488 " Example for a compiler tool that produces .obj files:\n" | 489 " Example for a compiler tool that produces .obj files:\n" |
489 " outputs = [\n" | 490 " outputs = [\n" |
490 " \"{{source_out_dir}}/{{source_name_part}}.obj\"\n" | 491 " \"{{source_out_dir}}/{{source_name_part}}.obj\"\n" |
491 " ]\n" | 492 " ]\n" |
492 "\n" | 493 "\n" |
493 " Example for a linker tool that produces a .dll and a .lib. The\n" | 494 " Example for a linker tool that produces a .dll and a .lib. The\n" |
494 " use of {{output_extension}} rather than hardcoding \".dll\"\n" | 495 " use of {{output_extension}} rather than hardcoding \".dll\"\n" |
495 " allows the extension of the library to be overridden on a\n" | 496 " allows the extension of the library to be overridden on a\n" |
496 " target-by-target basis, but in this example, it always\n" | 497 " target-by-target basis, but in this example, it always\n" |
497 " produces a \".lib\" import library:\n" | 498 " produces a \".lib\" import library:\n" |
498 " outputs = [\n" | 499 " outputs = [\n" |
499 " \"{{root_out_dir}}/{{target_output_name}}" | 500 " \"{{root_out_dir}}/{{target_output_name}}" |
500 "{{output_extension}}\",\n" | 501 "{{output_extension}}\",\n" |
501 " \"{{root_out_dir}}/{{target_output_name}}.lib\",\n" | 502 " \"{{root_out_dir}}/{{target_output_name}}.lib\",\n" |
502 " ]\n" | 503 " ]\n" |
503 "\n" | 504 "\n" |
504 " link_output [string with substitutions]\n" | 505 " link_output [string with substitutions]\n" |
505 " depend_output [string with substitutions]\n" | 506 " depend_output [string with substitutions]\n" |
507 " runtime_link_output [string with substitutions]\n" | |
506 " Valid for: \"solink\" only (optional)\n" | 508 " Valid for: \"solink\" only (optional)\n" |
507 "\n" | 509 "\n" |
508 " These two files specify which of the outputs from the solink\n" | 510 " These three files specify which of the outputs from the solink\n" |
509 " tool should be used for linking and dependency tracking. These\n" | 511 " tool should be used for linking and dependency tracking. These\n" |
510 " should match entries in the \"outputs\". If unspecified, the\n" | 512 " should match entries in the \"outputs\". If unspecified, the\n" |
511 " first item in the \"outputs\" array will be used for both. See\n" | 513 " first item in the \"outputs\" array will be used for all. See\n" |
512 " \"Separate linking and dependencies for shared libraries\"\n" | 514 " \"Separate linking and dependencies for shared libraries\"\n" |
513 " below for more.\n" | 515 " below for more. If link_output is set but runtime_link_output\n" |
516 " is not set, runtime_link_output defaults to link_output\n" | |
Dirk Pranke
2016/02/11 02:18:08
Nit: Add a trailing period.
Nico
2016/02/11 02:23:41
Done.
| |
514 "\n" | 517 "\n" |
515 " On Windows, where the tools produce a .dll shared library and\n" | 518 " On Windows, where the tools produce a .dll shared library and\n" |
516 " a .lib import library, you will want both of these to be the\n" | 519 " a .lib import library, you will want both of these to be the\n" |
Dirk Pranke
2016/02/11 02:18:08
Nit: maybe reword this as "you will want the first
Nico
2016/02/11 02:23:41
Done.
| |
517 " import library. On Linux, if you're not doing the separate\n" | 520 " import library, while runtime_link_output should be set to the\n" |
518 " linking/dependency optimization, both of these should be the\n" | 521 " .dll file. On Linux, if you're not doing the separate\n" |
522 " linking/dependency optimization, all of these should be the\n" | |
519 " .so output.\n" | 523 " .so output.\n" |
520 "\n" | 524 "\n" |
521 " output_prefix [string]\n" | 525 " output_prefix [string]\n" |
522 " Valid for: Linker tools (optional)\n" | 526 " Valid for: Linker tools (optional)\n" |
523 "\n" | 527 "\n" |
524 " Prefix to use for the output name. Defaults to empty. This\n" | 528 " Prefix to use for the output name. Defaults to empty. This\n" |
525 " prefix will be prepended to the name of the target (or the\n" | 529 " prefix will be prepended to the name of the target (or the\n" |
526 " output_name if one is manually specified for it) if the prefix\n" | 530 " output_name if one is manually specified for it) if the prefix\n" |
527 " is not already there. The result will show up in the\n" | 531 " is not already there. The result will show up in the\n" |
528 " {{output_name}} substitution pattern.\n" | 532 " {{output_name}} substitution pattern.\n" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 scoped_ptr<Tool> tool(new Tool); | 824 scoped_ptr<Tool> tool(new Tool); |
821 | 825 |
822 if (!ReadPattern(&block_scope, "command", subst_validator, tool.get(), | 826 if (!ReadPattern(&block_scope, "command", subst_validator, tool.get(), |
823 &Tool::set_command, err) || | 827 &Tool::set_command, err) || |
824 !ReadOutputExtension(&block_scope, tool.get(), err) || | 828 !ReadOutputExtension(&block_scope, tool.get(), err) || |
825 !ReadPattern(&block_scope, "depfile", subst_validator, tool.get(), | 829 !ReadPattern(&block_scope, "depfile", subst_validator, tool.get(), |
826 &Tool::set_depfile, err) || | 830 &Tool::set_depfile, err) || |
827 !ReadDepsFormat(&block_scope, tool.get(), err) || | 831 !ReadDepsFormat(&block_scope, tool.get(), err) || |
828 !ReadPattern(&block_scope, "description", subst_validator, tool.get(), | 832 !ReadPattern(&block_scope, "description", subst_validator, tool.get(), |
829 &Tool::set_description, err) || | 833 &Tool::set_description, err) || |
830 !ReadString(&block_scope, "lib_switch", tool.get(), | 834 !ReadString(&block_scope, "lib_switch", tool.get(), &Tool::set_lib_switch, |
831 &Tool::set_lib_switch, err) || | 835 err) || |
832 !ReadString(&block_scope, "lib_dir_switch", tool.get(), | 836 !ReadString(&block_scope, "lib_dir_switch", tool.get(), |
833 &Tool::set_lib_dir_switch, err) || | 837 &Tool::set_lib_dir_switch, err) || |
834 !ReadPattern(&block_scope, "link_output", subst_validator, tool.get(), | 838 !ReadPattern(&block_scope, "link_output", subst_validator, tool.get(), |
835 &Tool::set_link_output, err) || | 839 &Tool::set_link_output, err) || |
836 !ReadPattern(&block_scope, "depend_output", subst_validator, tool.get(), | 840 !ReadPattern(&block_scope, "depend_output", subst_validator, tool.get(), |
837 &Tool::set_depend_output, err) || | 841 &Tool::set_depend_output, err) || |
842 !ReadPattern(&block_scope, "runtime_link_output", subst_validator, | |
843 tool.get(), &Tool::set_runtime_link_output, err) || | |
838 !ReadString(&block_scope, "output_prefix", tool.get(), | 844 !ReadString(&block_scope, "output_prefix", tool.get(), |
839 &Tool::set_output_prefix, err) || | 845 &Tool::set_output_prefix, err) || |
840 !ReadPrecompiledHeaderType(&block_scope, tool.get(), err) || | 846 !ReadPrecompiledHeaderType(&block_scope, tool.get(), err) || |
841 !ReadBool(&block_scope, "restat", tool.get(), &Tool::set_restat, err) || | 847 !ReadBool(&block_scope, "restat", tool.get(), &Tool::set_restat, err) || |
842 !ReadPattern(&block_scope, "rspfile", subst_validator, tool.get(), | 848 !ReadPattern(&block_scope, "rspfile", subst_validator, tool.get(), |
843 &Tool::set_rspfile, err) || | 849 &Tool::set_rspfile, err) || |
844 !ReadPattern(&block_scope, "rspfile_content", subst_validator, tool.get(), | 850 !ReadPattern(&block_scope, "rspfile_content", subst_validator, tool.get(), |
845 &Tool::set_rspfile_content, err)) { | 851 &Tool::set_rspfile_content, err)) { |
846 return Value(); | 852 return Value(); |
847 } | 853 } |
848 | 854 |
849 if (tool_type != Toolchain::TYPE_COPY && tool_type != Toolchain::TYPE_STAMP) { | 855 if (tool_type != Toolchain::TYPE_COPY && tool_type != Toolchain::TYPE_STAMP) { |
850 // All tools except the copy and stamp tools should have outputs. The copy | 856 // All tools except the copy and stamp tools should have outputs. The copy |
851 // and stamp tool's outputs are generated internally. | 857 // and stamp tool's outputs are generated internally. |
852 if (!ReadOutputs(&block_scope, function, subst_output_validator, | 858 if (!ReadOutputs(&block_scope, function, subst_output_validator, |
853 tool.get(), err)) | 859 tool.get(), err)) |
854 return Value(); | 860 return Value(); |
855 } | 861 } |
856 | 862 |
857 // Validate that the link_output and depend_output refer to items in the | 863 // Validate that the link_output, depend_output, and runtime_link_output |
858 // outputs and aren't defined for irrelevant tool types. | 864 // refer to items in the outputs and aren't defined for irrelevant tool |
865 // types. | |
859 if (!tool->link_output().empty()) { | 866 if (!tool->link_output().empty()) { |
860 if (tool_type != Toolchain::TYPE_SOLINK && | 867 if (tool_type != Toolchain::TYPE_SOLINK && |
861 tool_type != Toolchain::TYPE_SOLINK_MODULE) { | 868 tool_type != Toolchain::TYPE_SOLINK_MODULE) { |
862 *err = Err(function, "This tool specifies a link_output.", | 869 *err = Err(function, "This tool specifies a link_output.", |
863 "This is only valid for solink and solink_module tools."); | 870 "This is only valid for solink and solink_module tools."); |
864 return Value(); | 871 return Value(); |
865 } | 872 } |
866 if (!IsPatternInOutputList(tool->outputs(), tool->link_output())) { | 873 if (!IsPatternInOutputList(tool->outputs(), tool->link_output())) { |
867 *err = Err(function, "This tool's link_output is bad.", | 874 *err = Err(function, "This tool's link_output is bad.", |
868 "It must match one of the outputs."); | 875 "It must match one of the outputs."); |
(...skipping 12 matching lines...) Expand all Loading... | |
881 "It must match one of the outputs."); | 888 "It must match one of the outputs."); |
882 return Value(); | 889 return Value(); |
883 } | 890 } |
884 } | 891 } |
885 if ((!tool->link_output().empty() && tool->depend_output().empty()) || | 892 if ((!tool->link_output().empty() && tool->depend_output().empty()) || |
886 (tool->link_output().empty() && !tool->depend_output().empty())) { | 893 (tool->link_output().empty() && !tool->depend_output().empty())) { |
887 *err = Err(function, "Both link_output and depend_output should either " | 894 *err = Err(function, "Both link_output and depend_output should either " |
888 "be specified or they should both be empty."); | 895 "be specified or they should both be empty."); |
889 return Value(); | 896 return Value(); |
890 } | 897 } |
898 if (!tool->runtime_link_output().empty()) { | |
899 if (tool_type != Toolchain::TYPE_SOLINK && | |
900 tool_type != Toolchain::TYPE_SOLINK_MODULE) { | |
901 *err = Err(function, "This tool specifies a runtime_link_output.", | |
902 "This is only valid for solink and solink_module tools."); | |
903 return Value(); | |
904 } | |
905 if (!IsPatternInOutputList(tool->outputs(), tool->runtime_link_output())) { | |
906 *err = Err(function, "This tool's runtime_link_output is bad.", | |
907 "It must match one of the outputs."); | |
908 return Value(); | |
909 } | |
910 } | |
891 | 911 |
892 // Make sure there weren't any vars set in this tool that were unused. | 912 // Make sure there weren't any vars set in this tool that were unused. |
893 if (!block_scope.CheckForUnusedVars(err)) | 913 if (!block_scope.CheckForUnusedVars(err)) |
894 return Value(); | 914 return Value(); |
895 | 915 |
896 toolchain->SetTool(tool_type, std::move(tool)); | 916 toolchain->SetTool(tool_type, std::move(tool)); |
897 return Value(); | 917 return Value(); |
898 } | 918 } |
899 | 919 |
900 // toolchain_args -------------------------------------------------------------- | 920 // toolchain_args -------------------------------------------------------------- |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 return Value(); | 987 return Value(); |
968 | 988 |
969 Scope::KeyValueMap values; | 989 Scope::KeyValueMap values; |
970 block_scope.GetCurrentScopeValues(&values); | 990 block_scope.GetCurrentScopeValues(&values); |
971 toolchain->args() = values; | 991 toolchain->args() = values; |
972 | 992 |
973 return Value(); | 993 return Value(); |
974 } | 994 } |
975 | 995 |
976 } // namespace functions | 996 } // namespace functions |
OLD | NEW |