| 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 = |
| 76 Label::Resolve(scope->GetSourceDir(), current_toolchain, *v, err); |
| 77 if (err->has_error()) |
| 78 return false; |
| 79 |
| 80 LabelPtrPair<Pool> pair(label); |
| 81 pair.origin = origin; |
| 82 |
| 83 (tool->*set)(pair); |
| 84 return true; |
| 85 } |
| 86 |
| 60 // Calls the given validate function on each type in the list. On failure, | 87 // Calls the given validate function on each type in the list. On failure, |
| 61 // sets the error, blame the value, and return false. | 88 // sets the error, blame the value, and return false. |
| 62 bool ValidateSubstitutionList(const std::vector<SubstitutionType>& list, | 89 bool ValidateSubstitutionList(const std::vector<SubstitutionType>& list, |
| 63 bool (*validate)(SubstitutionType), | 90 bool (*validate)(SubstitutionType), |
| 64 const Value* origin, | 91 const Value* origin, |
| 65 Err* err) { | 92 Err* err) { |
| 66 for (const auto& cur_type : list) { | 93 for (const auto& cur_type : list) { |
| 67 if (!validate(cur_type)) { | 94 if (!validate(cur_type)) { |
| 68 *err = Err(*origin, "Pattern not valid here.", | 95 *err = Err(*origin, "Pattern not valid here.", |
| 69 "You used the pattern " + std::string(kSubstitutionNames[cur_type]) + | 96 "You used the pattern " + std::string(kSubstitutionNames[cur_type]) + |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 "\n" | 538 "\n" |
| 512 " Example for a linker tool that produces a .dll and a .lib. The\n" | 539 " Example for a linker tool that produces a .dll and a .lib. The\n" |
| 513 " use of {{target_output_name}}, {{output_extension}} and\n" | 540 " use of {{target_output_name}}, {{output_extension}} and\n" |
| 514 " {{output_dir}} allows the target to override these values.\n" | 541 " {{output_dir}} allows the target to override these values.\n" |
| 515 " outputs = [\n" | 542 " outputs = [\n" |
| 516 " \"{{output_dir}}/{{target_output_name}}" | 543 " \"{{output_dir}}/{{target_output_name}}" |
| 517 "{{output_extension}}\",\n" | 544 "{{output_extension}}\",\n" |
| 518 " \"{{output_dir}}/{{target_output_name}}.lib\",\n" | 545 " \"{{output_dir}}/{{target_output_name}}.lib\",\n" |
| 519 " ]\n" | 546 " ]\n" |
| 520 "\n" | 547 "\n" |
| 548 " pool [label, optional]\n" |
| 549 "\n" |
| 550 " Label of the pool to use for the tool. Pools are used to limit\n" |
| 551 " the number of tasks that can execute concurrently during the\n" |
| 552 " build.\n" |
| 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, 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 |