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" |
11 #include "tools/gn/label.h" | |
12 #include "tools/gn/label_ptr.h" | |
11 #include "tools/gn/parse_tree.h" | 13 #include "tools/gn/parse_tree.h" |
12 #include "tools/gn/scheduler.h" | 14 #include "tools/gn/scheduler.h" |
13 #include "tools/gn/scope.h" | 15 #include "tools/gn/scope.h" |
14 #include "tools/gn/settings.h" | 16 #include "tools/gn/settings.h" |
15 #include "tools/gn/tool.h" | 17 #include "tools/gn/tool.h" |
16 #include "tools/gn/toolchain.h" | 18 #include "tools/gn/toolchain.h" |
17 #include "tools/gn/value_extractors.h" | 19 #include "tools/gn/value_extractors.h" |
18 #include "tools/gn/variables.h" | 20 #include "tools/gn/variables.h" |
19 | 21 |
20 namespace functions { | 22 namespace functions { |
(...skipping 29 matching lines...) Expand all Loading... | |
50 const Value* v = scope->GetValue(var, true); | 52 const Value* v = scope->GetValue(var, true); |
51 if (!v) | 53 if (!v) |
52 return true; // Not present is fine. | 54 return true; // Not present is fine. |
53 if (!v->VerifyTypeIs(Value::STRING, err)) | 55 if (!v->VerifyTypeIs(Value::STRING, err)) |
54 return false; | 56 return false; |
55 | 57 |
56 (tool->*set)(v->string_value()); | 58 (tool->*set)(v->string_value()); |
57 return true; | 59 return true; |
58 } | 60 } |
59 | 61 |
62 // Reads the given label from the scope (if present) and puts the result into | |
63 // dest. If the value is not a label, sets the error and returns false. | |
64 bool ReadLabel(Scope* scope, | |
65 const char* var, | |
66 Tool* tool, | |
67 const ParseNode* origin, | |
68 const Label& current_toolchain, | |
69 void (Tool::*set)(const LabelPtrPair<Pool>&), | |
70 Err* err) { | |
71 const Value* v = scope->GetValue(var, true); | |
72 if (!v) | |
73 return true; // Not present is fine. | |
74 | |
75 Label label = Label::Resolve(scope->GetSourceDir(), | |
76 current_toolchain, | |
77 *v, err); | |
78 if (err->has_error()) | |
79 return false; | |
80 | |
81 LabelPtrPair<Pool> pair(label); | |
82 pair.origin = origin; | |
83 | |
84 (tool->*set)(pair); | |
85 return true; | |
86 } | |
87 | |
60 // Calls the given validate function on each type in the list. On failure, | 88 // Calls the given validate function on each type in the list. On failure, |
61 // sets the error, blame the value, and return false. | 89 // sets the error, blame the value, and return false. |
62 bool ValidateSubstitutionList(const std::vector<SubstitutionType>& list, | 90 bool ValidateSubstitutionList(const std::vector<SubstitutionType>& list, |
63 bool (*validate)(SubstitutionType), | 91 bool (*validate)(SubstitutionType), |
64 const Value* origin, | 92 const Value* origin, |
65 Err* err) { | 93 Err* err) { |
66 for (const auto& cur_type : list) { | 94 for (const auto& cur_type : list) { |
67 if (!validate(cur_type)) { | 95 if (!validate(cur_type)) { |
68 *err = Err(*origin, "Pattern not valid here.", | 96 *err = Err(*origin, "Pattern not valid here.", |
69 "You used the pattern " + std::string(kSubstitutionNames[cur_type]) + | 97 "You used the pattern " + std::string(kSubstitutionNames[cur_type]) + |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 "\n" | 539 "\n" |
512 " Example for a linker tool that produces a .dll and a .lib. The\n" | 540 " Example for a linker tool that produces a .dll and a .lib. The\n" |
513 " use of {{target_output_name}}, {{output_extension}} and\n" | 541 " use of {{target_output_name}}, {{output_extension}} and\n" |
514 " {{output_dir}} allows the target to override these values.\n" | 542 " {{output_dir}} allows the target to override these values.\n" |
515 " outputs = [\n" | 543 " outputs = [\n" |
516 " \"{{output_dir}}/{{target_output_name}}" | 544 " \"{{output_dir}}/{{target_output_name}}" |
517 "{{output_extension}}\",\n" | 545 "{{output_extension}}\",\n" |
518 " \"{{output_dir}}/{{target_output_name}}.lib\",\n" | 546 " \"{{output_dir}}/{{target_output_name}}.lib\",\n" |
519 " ]\n" | 547 " ]\n" |
520 "\n" | 548 "\n" |
549 " pool [label, optional]\n" | |
550 "\n" | |
551 " Label of the pool to use for the tool. Pool are used to limit\n" | |
Dirk Pranke
2016/05/25 02:04:52
Nit: "Pools are used" or "A pool is used"
sdefresne
2016/05/26 15:38:37
Done.
| |
552 " the number of task to launch simultaneously during the build.\n" | |
Dirk Pranke
2016/05/25 02:04:52
Nit: "number of tasks". In fact, I'd probably writ
sdefresne
2016/05/26 15:38:37
Done.
| |
553 "\n" | |
554 " See also \"gn help pool\".\n" | |
555 "\n" | |
521 " link_output [string with substitutions]\n" | 556 " link_output [string with substitutions]\n" |
522 " depend_output [string with substitutions]\n" | 557 " depend_output [string with substitutions]\n" |
523 " runtime_link_output [string with substitutions]\n" | 558 " runtime_link_output [string with substitutions]\n" |
524 " Valid for: \"solink\" only (optional)\n" | 559 " Valid for: \"solink\" only (optional)\n" |
525 "\n" | 560 "\n" |
526 " These three files specify which of the outputs from the solink\n" | 561 " These three files specify which of the outputs from the solink\n" |
527 " tool should be used for linking and dependency tracking. These\n" | 562 " tool should be used for linking and dependency tracking. These\n" |
528 " should match entries in the \"outputs\". If unspecified, the\n" | 563 " should match entries in the \"outputs\". If unspecified, the\n" |
529 " first item in the \"outputs\" array will be used for all. See\n" | 564 " first item in the \"outputs\" array will be used for all. See\n" |
530 " \"Separate linking and dependencies for shared libraries\"\n" | 565 " \"Separate linking and dependencies for shared libraries\"\n" |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 tool.get(), &Tool::set_runtime_link_output, err) || | 936 tool.get(), &Tool::set_runtime_link_output, err) || |
902 !ReadString(&block_scope, "output_prefix", tool.get(), | 937 !ReadString(&block_scope, "output_prefix", tool.get(), |
903 &Tool::set_output_prefix, err) || | 938 &Tool::set_output_prefix, err) || |
904 !ReadPattern(&block_scope, "default_output_dir", subst_validator, | 939 !ReadPattern(&block_scope, "default_output_dir", subst_validator, |
905 tool.get(), &Tool::set_default_output_dir, err) || | 940 tool.get(), &Tool::set_default_output_dir, err) || |
906 !ReadPrecompiledHeaderType(&block_scope, tool.get(), err) || | 941 !ReadPrecompiledHeaderType(&block_scope, tool.get(), err) || |
907 !ReadBool(&block_scope, "restat", tool.get(), &Tool::set_restat, err) || | 942 !ReadBool(&block_scope, "restat", tool.get(), &Tool::set_restat, err) || |
908 !ReadPattern(&block_scope, "rspfile", subst_validator, tool.get(), | 943 !ReadPattern(&block_scope, "rspfile", subst_validator, tool.get(), |
909 &Tool::set_rspfile, err) || | 944 &Tool::set_rspfile, err) || |
910 !ReadPattern(&block_scope, "rspfile_content", subst_validator, tool.get(), | 945 !ReadPattern(&block_scope, "rspfile_content", subst_validator, tool.get(), |
911 &Tool::set_rspfile_content, err)) { | 946 &Tool::set_rspfile_content, err) || |
947 !ReadLabel(&block_scope, "pool", tool.get(), function, toolchain->label(), | |
948 &Tool::set_pool_label_pair, err)) { | |
912 return Value(); | 949 return Value(); |
913 } | 950 } |
914 | 951 |
915 if (tool_type != Toolchain::TYPE_COPY && | 952 if (tool_type != Toolchain::TYPE_COPY && |
916 tool_type != Toolchain::TYPE_STAMP && | 953 tool_type != Toolchain::TYPE_STAMP && |
917 tool_type != Toolchain::TYPE_COPY_BUNDLE_DATA && | 954 tool_type != Toolchain::TYPE_COPY_BUNDLE_DATA && |
918 tool_type != Toolchain::TYPE_COMPILE_XCASSETS) { | 955 tool_type != Toolchain::TYPE_COMPILE_XCASSETS) { |
919 // All tools should have outputs, except the copy, stamp, copy_bundle_data | 956 // All tools should have outputs, except the copy, stamp, copy_bundle_data |
920 // and compile_xcassets tools that generate their outputs internally. | 957 // and compile_xcassets tools that generate their outputs internally. |
921 if (!ReadOutputs(&block_scope, function, subst_output_validator, | 958 if (!ReadOutputs(&block_scope, function, subst_output_validator, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 return Value(); | 1087 return Value(); |
1051 | 1088 |
1052 Scope::KeyValueMap values; | 1089 Scope::KeyValueMap values; |
1053 block_scope.GetCurrentScopeValues(&values); | 1090 block_scope.GetCurrentScopeValues(&values); |
1054 toolchain->args() = values; | 1091 toolchain->args() = values; |
1055 | 1092 |
1056 return Value(); | 1093 return Value(); |
1057 } | 1094 } |
1058 | 1095 |
1059 } // namespace functions | 1096 } // namespace functions |
OLD | NEW |