| 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" |
| 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 the first two to be the\n" |
| 517 " import library. On Linux, if you're not doing the separate\n" | 520 " import library and the third one to be the .dll file.\n" |
| 518 " linking/dependency optimization, both of these should be the\n" | 521 " On Linux, if you're not doing the separate linking/dependency\n" |
| 519 " .so output.\n" | 522 " optimization, all of these should be the .so output.\n" |
| 520 "\n" | 523 "\n" |
| 521 " output_prefix [string]\n" | 524 " output_prefix [string]\n" |
| 522 " Valid for: Linker tools (optional)\n" | 525 " Valid for: Linker tools (optional)\n" |
| 523 "\n" | 526 "\n" |
| 524 " Prefix to use for the output name. Defaults to empty. This\n" | 527 " 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" | 528 " 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" | 529 " 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" | 530 " is not already there. The result will show up in the\n" |
| 528 " {{output_name}} substitution pattern.\n" | 531 " {{output_name}} substitution pattern.\n" |
| 529 "\n" | 532 "\n" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 scoped_ptr<Tool> tool(new Tool); | 823 scoped_ptr<Tool> tool(new Tool); |
| 821 | 824 |
| 822 if (!ReadPattern(&block_scope, "command", subst_validator, tool.get(), | 825 if (!ReadPattern(&block_scope, "command", subst_validator, tool.get(), |
| 823 &Tool::set_command, err) || | 826 &Tool::set_command, err) || |
| 824 !ReadOutputExtension(&block_scope, tool.get(), err) || | 827 !ReadOutputExtension(&block_scope, tool.get(), err) || |
| 825 !ReadPattern(&block_scope, "depfile", subst_validator, tool.get(), | 828 !ReadPattern(&block_scope, "depfile", subst_validator, tool.get(), |
| 826 &Tool::set_depfile, err) || | 829 &Tool::set_depfile, err) || |
| 827 !ReadDepsFormat(&block_scope, tool.get(), err) || | 830 !ReadDepsFormat(&block_scope, tool.get(), err) || |
| 828 !ReadPattern(&block_scope, "description", subst_validator, tool.get(), | 831 !ReadPattern(&block_scope, "description", subst_validator, tool.get(), |
| 829 &Tool::set_description, err) || | 832 &Tool::set_description, err) || |
| 830 !ReadString(&block_scope, "lib_switch", tool.get(), | 833 !ReadString(&block_scope, "lib_switch", tool.get(), &Tool::set_lib_switch, |
| 831 &Tool::set_lib_switch, err) || | 834 err) || |
| 832 !ReadString(&block_scope, "lib_dir_switch", tool.get(), | 835 !ReadString(&block_scope, "lib_dir_switch", tool.get(), |
| 833 &Tool::set_lib_dir_switch, err) || | 836 &Tool::set_lib_dir_switch, err) || |
| 834 !ReadPattern(&block_scope, "link_output", subst_validator, tool.get(), | 837 !ReadPattern(&block_scope, "link_output", subst_validator, tool.get(), |
| 835 &Tool::set_link_output, err) || | 838 &Tool::set_link_output, err) || |
| 836 !ReadPattern(&block_scope, "depend_output", subst_validator, tool.get(), | 839 !ReadPattern(&block_scope, "depend_output", subst_validator, tool.get(), |
| 837 &Tool::set_depend_output, err) || | 840 &Tool::set_depend_output, err) || |
| 841 !ReadPattern(&block_scope, "runtime_link_output", subst_validator, |
| 842 tool.get(), &Tool::set_runtime_link_output, err) || |
| 838 !ReadString(&block_scope, "output_prefix", tool.get(), | 843 !ReadString(&block_scope, "output_prefix", tool.get(), |
| 839 &Tool::set_output_prefix, err) || | 844 &Tool::set_output_prefix, err) || |
| 840 !ReadPrecompiledHeaderType(&block_scope, tool.get(), err) || | 845 !ReadPrecompiledHeaderType(&block_scope, tool.get(), err) || |
| 841 !ReadBool(&block_scope, "restat", tool.get(), &Tool::set_restat, err) || | 846 !ReadBool(&block_scope, "restat", tool.get(), &Tool::set_restat, err) || |
| 842 !ReadPattern(&block_scope, "rspfile", subst_validator, tool.get(), | 847 !ReadPattern(&block_scope, "rspfile", subst_validator, tool.get(), |
| 843 &Tool::set_rspfile, err) || | 848 &Tool::set_rspfile, err) || |
| 844 !ReadPattern(&block_scope, "rspfile_content", subst_validator, tool.get(), | 849 !ReadPattern(&block_scope, "rspfile_content", subst_validator, tool.get(), |
| 845 &Tool::set_rspfile_content, err)) { | 850 &Tool::set_rspfile_content, err)) { |
| 846 return Value(); | 851 return Value(); |
| 847 } | 852 } |
| 848 | 853 |
| 849 if (tool_type != Toolchain::TYPE_COPY && tool_type != Toolchain::TYPE_STAMP) { | 854 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 | 855 // All tools except the copy and stamp tools should have outputs. The copy |
| 851 // and stamp tool's outputs are generated internally. | 856 // and stamp tool's outputs are generated internally. |
| 852 if (!ReadOutputs(&block_scope, function, subst_output_validator, | 857 if (!ReadOutputs(&block_scope, function, subst_output_validator, |
| 853 tool.get(), err)) | 858 tool.get(), err)) |
| 854 return Value(); | 859 return Value(); |
| 855 } | 860 } |
| 856 | 861 |
| 857 // Validate that the link_output and depend_output refer to items in the | 862 // Validate that the link_output, depend_output, and runtime_link_output |
| 858 // outputs and aren't defined for irrelevant tool types. | 863 // refer to items in the outputs and aren't defined for irrelevant tool |
| 864 // types. |
| 859 if (!tool->link_output().empty()) { | 865 if (!tool->link_output().empty()) { |
| 860 if (tool_type != Toolchain::TYPE_SOLINK && | 866 if (tool_type != Toolchain::TYPE_SOLINK && |
| 861 tool_type != Toolchain::TYPE_SOLINK_MODULE) { | 867 tool_type != Toolchain::TYPE_SOLINK_MODULE) { |
| 862 *err = Err(function, "This tool specifies a link_output.", | 868 *err = Err(function, "This tool specifies a link_output.", |
| 863 "This is only valid for solink and solink_module tools."); | 869 "This is only valid for solink and solink_module tools."); |
| 864 return Value(); | 870 return Value(); |
| 865 } | 871 } |
| 866 if (!IsPatternInOutputList(tool->outputs(), tool->link_output())) { | 872 if (!IsPatternInOutputList(tool->outputs(), tool->link_output())) { |
| 867 *err = Err(function, "This tool's link_output is bad.", | 873 *err = Err(function, "This tool's link_output is bad.", |
| 868 "It must match one of the outputs."); | 874 "It must match one of the outputs."); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 881 "It must match one of the outputs."); | 887 "It must match one of the outputs."); |
| 882 return Value(); | 888 return Value(); |
| 883 } | 889 } |
| 884 } | 890 } |
| 885 if ((!tool->link_output().empty() && tool->depend_output().empty()) || | 891 if ((!tool->link_output().empty() && tool->depend_output().empty()) || |
| 886 (tool->link_output().empty() && !tool->depend_output().empty())) { | 892 (tool->link_output().empty() && !tool->depend_output().empty())) { |
| 887 *err = Err(function, "Both link_output and depend_output should either " | 893 *err = Err(function, "Both link_output and depend_output should either " |
| 888 "be specified or they should both be empty."); | 894 "be specified or they should both be empty."); |
| 889 return Value(); | 895 return Value(); |
| 890 } | 896 } |
| 897 if (!tool->runtime_link_output().empty()) { |
| 898 if (tool_type != Toolchain::TYPE_SOLINK && |
| 899 tool_type != Toolchain::TYPE_SOLINK_MODULE) { |
| 900 *err = Err(function, "This tool specifies a runtime_link_output.", |
| 901 "This is only valid for solink and solink_module tools."); |
| 902 return Value(); |
| 903 } |
| 904 if (!IsPatternInOutputList(tool->outputs(), tool->runtime_link_output())) { |
| 905 *err = Err(function, "This tool's runtime_link_output is bad.", |
| 906 "It must match one of the outputs."); |
| 907 return Value(); |
| 908 } |
| 909 } |
| 891 | 910 |
| 892 // Make sure there weren't any vars set in this tool that were unused. | 911 // Make sure there weren't any vars set in this tool that were unused. |
| 893 if (!block_scope.CheckForUnusedVars(err)) | 912 if (!block_scope.CheckForUnusedVars(err)) |
| 894 return Value(); | 913 return Value(); |
| 895 | 914 |
| 896 toolchain->SetTool(tool_type, std::move(tool)); | 915 toolchain->SetTool(tool_type, std::move(tool)); |
| 897 return Value(); | 916 return Value(); |
| 898 } | 917 } |
| 899 | 918 |
| 900 // toolchain_args -------------------------------------------------------------- | 919 // toolchain_args -------------------------------------------------------------- |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 return Value(); | 986 return Value(); |
| 968 | 987 |
| 969 Scope::KeyValueMap values; | 988 Scope::KeyValueMap values; |
| 970 block_scope.GetCurrentScopeValues(&values); | 989 block_scope.GetCurrentScopeValues(&values); |
| 971 toolchain->args() = values; | 990 toolchain->args() = values; |
| 972 | 991 |
| 973 return Value(); | 992 return Value(); |
| 974 } | 993 } |
| 975 | 994 |
| 976 } // namespace functions | 995 } // namespace functions |
| OLD | NEW |