Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: tools/gn/ninja_action_target_writer.cc

Issue 1430043002: Support script response files in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comment, random build fix Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/functions_target.cc ('k') | tools/gn/ninja_action_target_writer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/ninja_action_target_writer.cc
diff --git a/tools/gn/ninja_action_target_writer.cc b/tools/gn/ninja_action_target_writer.cc
index e2440a49c869548e1ccf18c53d96379c725a70ff..d0edc34ff1c502dc86a3e83781bcb19a535e4f1f 100644
--- a/tools/gn/ninja_action_target_writer.cc
+++ b/tools/gn/ninja_action_target_writer.cc
@@ -105,52 +105,42 @@ std::string NinjaActionTargetWriter::WriteRuleDefinition() {
EscapeOptions args_escape_options;
args_escape_options.mode = ESCAPE_NINJA_COMMAND;
- if (settings_->IsWin()) {
- // Send through gyp-win-tool and use a response file.
+ out_ << "rule " << custom_rule_name << std::endl;
+
+ if (target_->action_values().uses_rsp_file()) {
+ // Needs a response file. The unique_name part is for action_foreach so
+ // each invocation of the rule gets a different response file. This isn't
+ // strictly necessary for regular one-shot actions, but it's easier to
+ // just always define unique_name.
std::string rspfile = custom_rule_name;
if (!target_->sources().empty())
rspfile += ".$unique_name";
rspfile += ".rsp";
-
- out_ << "rule " << custom_rule_name << std::endl;
- out_ << " command = ";
- path_output_.WriteFile(out_, settings_->build_settings()->python_path());
- // TODO(brettw) this hardcodes "environment.x86" which is something that
- // the Chrome Windows toolchain writes. We should have a way to invoke
- // python without requiring this gyp_win_tool thing.
- out_ << " gyp-win-tool action-wrapper environment.x86 " << rspfile
- << std::endl;
- out_ << " description = ACTION " << target_label << std::endl;
- out_ << " restat = 1" << std::endl;
out_ << " rspfile = " << rspfile << std::endl;
- // The build command goes in the rsp file.
- out_ << " rspfile_content = ";
- path_output_.WriteFile(out_, settings_->build_settings()->python_path());
- out_ << " ";
- path_output_.WriteFile(out_, target_->action_values().script());
- for (const auto& arg : args.list()) {
+ // Response file contents.
+ out_ << " rspfile_content =";
+ for (const auto& arg :
+ target_->action_values().rsp_file_contents().list()) {
out_ << " ";
SubstitutionWriter::WriteWithNinjaVariables(
arg, args_escape_options, out_);
}
out_ << std::endl;
- } else {
- // Posix can execute Python directly.
- out_ << "rule " << custom_rule_name << std::endl;
- out_ << " command = ";
- path_output_.WriteFile(out_, settings_->build_settings()->python_path());
+ }
+
+ out_ << " command = ";
+ path_output_.WriteFile(out_, settings_->build_settings()->python_path());
+ out_ << " ";
+ path_output_.WriteFile(out_, target_->action_values().script());
+ for (const auto& arg : args.list()) {
out_ << " ";
- path_output_.WriteFile(out_, target_->action_values().script());
- for (const auto& arg : args.list()) {
- out_ << " ";
- SubstitutionWriter::WriteWithNinjaVariables(
- arg, args_escape_options, out_);
- }
- out_ << std::endl;
- out_ << " description = ACTION " << target_label << std::endl;
- out_ << " restat = 1" << std::endl;
+ SubstitutionWriter::WriteWithNinjaVariables(
+ arg, args_escape_options, out_);
}
+ out_ << std::endl;
+ out_ << " description = ACTION " << target_label << std::endl;
+ out_ << " restat = 1" << std::endl;
return custom_rule_name;
}
@@ -165,9 +155,6 @@ void NinjaActionTargetWriter::WriteSourceRules(
// they will get pasted into the real command line.
args_escape_options.inhibit_quoting = true;
- const std::vector<SubstitutionType>& args_substitutions_used =
- target_->action_values().args().required_types();
-
const Target::FileList& sources = target_->sources();
for (size_t i = 0; i < sources.size(); i++) {
out_ << "build";
@@ -185,12 +172,22 @@ void NinjaActionTargetWriter::WriteSourceRules(
}
out_ << std::endl;
- // Windows needs a unique ID for the response file.
- if (target_->settings()->IsWin())
+ // Response files require a unique name be defined.
+ if (target_->action_values().uses_rsp_file())
out_ << " unique_name = " << i << std::endl;
+ // The required types is the union of the args and response file. This
+ // might theoretically duplicate a definition if the same substitution is
+ // used in both the args and the reponse file. However, this should be
+ // very unusual (normally the substitutions will go in one place or the
+ // other) and the redundant assignment won't bother Ninja.
+ SubstitutionWriter::WriteNinjaVariablesForSource(
+ settings_, sources[i],
+ target_->action_values().args().required_types(),
+ args_escape_options, out_);
SubstitutionWriter::WriteNinjaVariablesForSource(
- settings_, sources[i], args_substitutions_used,
+ settings_, sources[i],
+ target_->action_values().rsp_file_contents().required_types(),
args_escape_options, out_);
if (target_->action_values().has_depfile()) {
« no previous file with comments | « tools/gn/functions_target.cc ('k') | tools/gn/ninja_action_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698