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

Side by Side Diff: tools/gn/gyp_script_target_writer.cc

Issue 80463004: GN generator for GYP actions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/gyp_script_target_writer.h ('k') | tools/gn/gyp_script_target_writer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "tools/gn/gyp_script_target_writer.h"
6
7 #include "tools/gn/builder_record.h"
8 #include "tools/gn/err.h"
9 #include "tools/gn/file_template.h"
10 #include "tools/gn/filesystem_utils.h"
11 #include "tools/gn/settings.h"
12 #include "tools/gn/target.h"
13
14 // Write script targets as GYP actions that just invoke Ninja. This allows us
15 // to not have to worry about duplicating the precise GN script execution
16 // semantices in GYP for each platform (GYP varies a bit).
17
18 GypScriptTargetWriter::GypScriptTargetWriter(const TargetGroup& group,
19 const SourceDir& gyp_dir,
20 std::ostream& out)
21 : GypTargetWriter(group.debug->item()->AsTarget(), gyp_dir, out) {
22 }
23
24 GypScriptTargetWriter::~GypScriptTargetWriter() {
25 }
26
27 void GypScriptTargetWriter::Run() {
28 int indent = 4;
29 std::string name = helper_.GetNameForTarget(target_);
30
31 // Put the ninja build for this script target in this directory.
32 SourceDir ninja_dir(GetTargetOutputDir(target_).value() + name + "_ninja/");
33
34 Indent(indent) << "{\n";
35
36 Indent(indent + kExtraIndent) << "'target_name': '" << name << "',\n";
37 Indent(indent + kExtraIndent) << "'type': 'none',\n";
38 Indent(indent + kExtraIndent) << "'actions': [{\n";
39
40 Indent(indent + kExtraIndent * 2) << "'action_name': '" << name
41 << " action',\n";
42
43 Indent(indent + kExtraIndent * 2) << "'action': [\n";
44 Indent(indent + kExtraIndent * 3) << "'ninja',\n";
45 Indent(indent + kExtraIndent * 3) << "'-C', '";
46 path_output_.WriteDir(out_, ninja_dir, PathOutput::DIR_NO_LAST_SLASH);
47 out_ << "',\n";
48 Indent(indent + kExtraIndent * 3) << "'" << name << "',\n";
49 Indent(indent + kExtraIndent * 2) << "],\n";
50
51 WriteActionInputs(indent + kExtraIndent * 2);
52 WriteActionOutputs(indent + kExtraIndent * 2);
53
54 Indent(indent + kExtraIndent) << "}],\n";
55 Indent(indent) << "},\n";
56 }
57
58 void GypScriptTargetWriter::WriteActionInputs(int indent) {
59 Indent(indent) << "'inputs': [\n";
60
61 // Write everything that should be considered an input for dependency
62 // purposes, which is all sources as well as the prereqs.
63 const Target::FileList& sources = target_->sources();
64 for (size_t i = 0; i < sources.size(); i++) {
65 Indent(indent + kExtraIndent) << "'";
66 path_output_.WriteFile(out_, sources[i]);
67 out_ << "',\n";
68 }
69
70 const Target::FileList& prereqs = target_->source_prereqs();
71 for (size_t i = 0; i < prereqs.size(); i++) {
72 Indent(indent + kExtraIndent) << "'";
73 path_output_.WriteFile(out_, prereqs[i]);
74 out_ << "',\n";
75 }
76
77 Indent(indent) << "],\n";
78 }
79
80 void GypScriptTargetWriter::WriteActionOutputs(int indent) {
81 Indent(indent) << "'outputs': [\n";
82
83 const Target::FileList& sources = target_->sources();
84 if (sources.empty()) {
85 // Just write outputs directly if there are no sources.
86 const Target::FileList& output = target_->script_values().outputs();
87 for (size_t output_i = 0; output_i < output.size(); output_i++) {
88 Indent(indent + kExtraIndent) << "'";
89 path_output_.WriteFile(out_, output[output_i]);
90 out_ << "',\n";
91 }
92 } else {
93 // There are sources, the outputs should be a template to apply to each.
94 FileTemplate output_template = FileTemplate::GetForTargetOutputs(target_);
95
96 std::vector<std::string> output;
97 for (size_t source_i = 0; source_i < sources.size(); source_i++) {
98 output_template.ApplyString(sources[source_i].value(), &output);
99 for (size_t output_i = 0; output_i < output.size(); output_i++) {
100 Indent(indent + kExtraIndent) << "'";
101 path_output_.WriteFile(out_, SourceFile(output[output_i]));
102 out_ << "',\n";
103 }
104 }
105 }
106
107 Indent(indent) << "],\n";
108 }
OLDNEW
« no previous file with comments | « tools/gn/gyp_script_target_writer.h ('k') | tools/gn/gyp_script_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698