summaryrefslogtreecommitdiffstats
path: root/tools/gn/ninja_copy_target_writer.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-18 22:02:50 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-18 22:02:50 +0000
commitb90c75afa26473fae4e6c2333beb241b7da27203 (patch)
treebc4f2383ca103e063dcf1d724c85172ca25e3b5d /tools/gn/ninja_copy_target_writer.cc
parentebad924529462695b44cb0090d568a808ce83365 (diff)
downloadchromium_src-b90c75afa26473fae4e6c2333beb241b7da27203.zip
chromium_src-b90c75afa26473fae4e6c2333beb241b7da27203.tar.gz
chromium_src-b90c75afa26473fae4e6c2333beb241b7da27203.tar.bz2
Update GN copy file rule.
This merges the syntax of the script and copy file rules and adds lots of documentation. In doing this I realized that the template handling and escaping was bad in the script rules, so I did a bunch of work and added much better tests. BUG=288991 R=scottmg@chromium.org Review URL: https://codereview.chromium.org/23536068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gn/ninja_copy_target_writer.cc')
-rw-r--r--tools/gn/ninja_copy_target_writer.cc42
1 files changed, 15 insertions, 27 deletions
diff --git a/tools/gn/ninja_copy_target_writer.cc b/tools/gn/ninja_copy_target_writer.cc
index d4a65ab..aae8e6d 100644
--- a/tools/gn/ninja_copy_target_writer.cc
+++ b/tools/gn/ninja_copy_target_writer.cc
@@ -5,6 +5,7 @@
#include "tools/gn/ninja_copy_target_writer.h"
#include "base/strings/string_util.h"
+#include "tools/gn/file_template.h"
#include "tools/gn/string_utils.h"
NinjaCopyTargetWriter::NinjaCopyTargetWriter(const Target* target,
@@ -16,32 +17,24 @@ NinjaCopyTargetWriter::~NinjaCopyTargetWriter() {
}
void NinjaCopyTargetWriter::Run() {
- // The dest dir should be inside the output dir so we can just remove the
- // prefix and get ninja-relative paths.
- const std::string& output_dir =
- settings_->build_settings()->build_dir().value();
- const std::string& dest_dir = target_->destdir().value();
- DCHECK(StartsWithASCII(dest_dir, output_dir, true));
- std::string relative_dest_dir(&dest_dir[output_dir.size()],
- dest_dir.size() - output_dir.size());
+ CHECK(target_->script_values().outputs().size() == 1);
+ FileTemplate output_template(GetOutputTemplate());
- const Target::FileList& sources = target_->sources();
- std::vector<OutputFile> dest_files;
- dest_files.reserve(sources.size());
+ std::vector<OutputFile> output_files;
- // Write out rules for each file copied.
- for (size_t i = 0; i < sources.size(); i++) {
- const SourceFile& input_file = sources[i];
+ for (size_t i = 0; i < target_->sources().size(); i++) {
+ const SourceFile& input_file = target_->sources()[i];
- // The files should have the same name but in the dest dir.
- base::StringPiece name_part = FindFilename(&input_file.value());
- OutputFile dest_file(relative_dest_dir);
- AppendStringPiece(&dest_file.value(), name_part);
+ // Make the output file from the template.
+ std::vector<std::string> template_result;
+ output_template.ApplyString(input_file.value(), &template_result);
+ CHECK(template_result.size() == 1);
+ OutputFile output_file(template_result[0]);
- dest_files.push_back(dest_file);
+ output_files.push_back(output_file);
out_ << "build ";
- path_output_.WriteFile(out_, dest_file);
+ path_output_.WriteFile(out_, output_file);
out_ << ": copy ";
path_output_.WriteFile(out_, input_file);
out_ << std::endl;
@@ -53,14 +46,9 @@ void NinjaCopyTargetWriter::Run() {
out_ << ": "
<< helper_.GetRulePrefix(target_->settings()->toolchain())
<< "stamp";
- for (size_t i = 0; i < dest_files.size(); i++) {
+ for (size_t i = 0; i < output_files.size(); i++) {
out_ << " ";
- path_output_.WriteFile(out_, dest_files[i]);
+ path_output_.WriteFile(out_, output_files[i]);
}
out_ << std::endl;
-
- // TODO(brettw) need some kind of stamp file for depending on this, as well
- // as order_only=prebuild.
- // TODO(brettw) also need to write out the dependencies of this rule (maybe
- // we're copying output files around).
}