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

Unified Diff: tools/gn/ninja_script_target_writer.cc

Issue 55633002: GN: Add ability to specify a depfile for custom targets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months 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
Index: tools/gn/ninja_script_target_writer.cc
diff --git a/tools/gn/ninja_script_target_writer.cc b/tools/gn/ninja_script_target_writer.cc
index 1b8358cd79839f9ce948525c750acf1ef11e880e..47f23811bfb2a50c74a45197d9fedebc40cfabe0 100644
--- a/tools/gn/ninja_script_target_writer.cc
+++ b/tools/gn/ninja_script_target_writer.cc
@@ -36,7 +36,9 @@ void NinjaScriptTargetWriter::Run() {
} else {
// No sources, write a rule that invokes the script once with the
// outputs as outputs, and the data as inputs.
- out_ << "build";
+ out_ << "build ";
brettw 2013/11/04 05:22:14 I've been standardizing on the guy who's appending
koz (OOO until 15th September) 2013/11/06 07:29:11 Done.
+ if (target_->script_values().has_depfile())
+ WriteDepfile(SourceFile());
const Target::FileList& outputs = target_->script_values().outputs();
for (size_t i = 0; i < outputs.size(); i++) {
OutputFile output_path(
@@ -47,6 +49,11 @@ void NinjaScriptTargetWriter::Run() {
path_output_.WriteFile(out_, output_path);
}
out_ << ": " << custom_rule_name << implicit_deps << std::endl;
+ if (target_->script_values().has_depfile()) {
+ out_ << " depfile = ";
+ WriteDepfile(SourceFile());
+ out_ << std::endl;
+ }
}
out_ << std::endl;
@@ -144,6 +151,12 @@ void NinjaScriptTargetWriter::WriteSourceRules(
if (args_template.has_substitutions())
WriteArgsSubstitutions(sources[i], args_template);
+
+ if (target_->script_values().has_depfile()) {
+ out_ << " depfile = ";
+ WriteDepfile(sources[i]);
+ out_ << std::endl;
+ }
}
}
@@ -165,6 +178,12 @@ void NinjaScriptTargetWriter::WriteOutputFilesForBuildLine(
const FileTemplate& output_template,
const SourceFile& source,
std::vector<OutputFile>* output_files) {
+ // If there is a depfile specified we need to list it as the first output as
+ // that is what ninja will expect the depfile to refer to itself as.
+ if (target_->script_values().has_depfile()) {
+ out_ << " ";
+ WriteDepfile(source);
+ }
std::vector<std::string> output_template_result;
output_template.ApplyString(source.value(), &output_template_result);
for (size_t out_i = 0; out_i < output_template_result.size(); out_i++) {
@@ -174,3 +193,18 @@ void NinjaScriptTargetWriter::WriteOutputFilesForBuildLine(
path_output_.WriteFile(out_, output_path);
}
}
+
+void NinjaScriptTargetWriter::WriteDepfile(const SourceFile& source) {
+ std::vector<std::string> result;
+ GetDepfileTemplate().ApplyString(source.value(), &result);
+ path_output_.WriteFile(out_, OutputFile(result[0]));
+}
+
+FileTemplate NinjaScriptTargetWriter::GetDepfileTemplate() const {
+ std::vector<std::string> template_args;
+ std::string depfile_relative_to_build_dir =
+ RemovePrefix(target_->script_values().depfile().value(),
+ settings_->build_settings()->build_dir().value());
+ template_args.push_back(depfile_relative_to_build_dir);
+ return FileTemplate(template_args);
+}

Powered by Google App Engine
This is Rietveld 408576698