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

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

Issue 440333002: Support more configurability in GN toolchains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unsigned check Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/ninja_target_writer.cc ('k') | tools/gn/ninja_toolchain_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <sstream> 5 #include <sstream>
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "tools/gn/ninja_target_writer.h" 8 #include "tools/gn/ninja_target_writer.h"
9 #include "tools/gn/target.h"
9 #include "tools/gn/test_with_scope.h" 10 #include "tools/gn/test_with_scope.h"
10 11
11 namespace { 12 namespace {
12 13
13 class TestingNinjaTargetWriter : public NinjaTargetWriter { 14 class TestingNinjaTargetWriter : public NinjaTargetWriter {
14 public: 15 public:
15 TestingNinjaTargetWriter(const Target* target, 16 TestingNinjaTargetWriter(const Target* target,
16 const Toolchain* toolchain, 17 const Toolchain* toolchain,
17 std::ostream& out) 18 std::ostream& out)
18 : NinjaTargetWriter(target, toolchain, out) { 19 : NinjaTargetWriter(target, out) {
19 } 20 }
20 21
21 virtual void Run() OVERRIDE {} 22 virtual void Run() OVERRIDE {}
22 23
23 // Make this public so the test can call it. 24 // Make this public so the test can call it.
24 std::string WriteInputDepsStampAndGetDep( 25 std::string WriteInputDepsStampAndGetDep(
25 const std::vector<const Target*>& extra_hard_deps) { 26 const std::vector<const Target*>& extra_hard_deps) {
26 return NinjaTargetWriter::WriteInputDepsStampAndGetDep(extra_hard_deps); 27 return NinjaTargetWriter::WriteInputDepsStampAndGetDep(extra_hard_deps);
27 } 28 }
28 }; 29 };
29 30
30 } // namespace 31 } // namespace
31 32
32 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) { 33 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) {
33 TestWithScope setup; 34 TestWithScope setup;
34 35
35 // Make a base target that's a hard dep (action). 36 // Make a base target that's a hard dep (action).
36 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base")); 37 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base"));
37 base_target.set_output_type(Target::ACTION); 38 base_target.set_output_type(Target::ACTION);
39 base_target.SetToolchain(setup.toolchain());
38 base_target.action_values().set_script(SourceFile("//foo/script.py")); 40 base_target.action_values().set_script(SourceFile("//foo/script.py"));
39 41
40 // Dependent target that also includes a source prerequisite (should get 42 // Dependent target that also includes a source prerequisite (should get
41 // included) and a source (should not be included). 43 // included) and a source (should not be included).
42 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); 44 Target target(setup.settings(), Label(SourceDir("//foo/"), "target"));
43 target.set_output_type(Target::EXECUTABLE); 45 target.set_output_type(Target::EXECUTABLE);
46 target.SetToolchain(setup.toolchain());
44 target.inputs().push_back(SourceFile("//foo/input.txt")); 47 target.inputs().push_back(SourceFile("//foo/input.txt"));
45 target.sources().push_back(SourceFile("//foo/source.txt")); 48 target.sources().push_back(SourceFile("//foo/source.txt"));
46 target.deps().push_back(LabelTargetPair(&base_target)); 49 target.deps().push_back(LabelTargetPair(&base_target));
47 50
48 // Dependent action to test that action sources will be treated the same as 51 // Dependent action to test that action sources will be treated the same as
49 // inputs. 52 // inputs.
50 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); 53 Target action(setup.settings(), Label(SourceDir("//foo/"), "action"));
51 action.set_output_type(Target::ACTION); 54 action.set_output_type(Target::ACTION);
55 action.SetToolchain(setup.toolchain());
52 action.action_values().set_script(SourceFile("//foo/script.py")); 56 action.action_values().set_script(SourceFile("//foo/script.py"));
53 action.sources().push_back(SourceFile("//foo/action_source.txt")); 57 action.sources().push_back(SourceFile("//foo/action_source.txt"));
54 action.deps().push_back(LabelTargetPair(&target)); 58 action.deps().push_back(LabelTargetPair(&target));
55 59
56 base_target.OnResolved(); 60 base_target.OnResolved();
57 target.OnResolved(); 61 target.OnResolved();
58 action.OnResolved(); 62 action.OnResolved();
59 63
60 // Input deps for the base (should be only the script itself). 64 // Input deps for the base (should be only the script itself).
61 { 65 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) { 106 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) {
103 TestWithScope setup; 107 TestWithScope setup;
104 108
105 // Toolchain dependency. Here we make a target in the same toolchain for 109 // Toolchain dependency. Here we make a target in the same toolchain for
106 // simplicity, but in real life (using the Builder) this would be rejected 110 // simplicity, but in real life (using the Builder) this would be rejected
107 // because it would be a circular dependency (the target depends on its 111 // because it would be a circular dependency (the target depends on its
108 // toolchain, and the toolchain depends on this target). 112 // toolchain, and the toolchain depends on this target).
109 Target toolchain_dep_target(setup.settings(), 113 Target toolchain_dep_target(setup.settings(),
110 Label(SourceDir("//foo/"), "setup")); 114 Label(SourceDir("//foo/"), "setup"));
111 toolchain_dep_target.set_output_type(Target::ACTION); 115 toolchain_dep_target.set_output_type(Target::ACTION);
116 toolchain_dep_target.SetToolchain(setup.toolchain());
117 toolchain_dep_target.OnResolved();
112 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); 118 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target));
113 119
114 // Make a binary target 120 // Make a binary target
115 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); 121 Target target(setup.settings(), Label(SourceDir("//foo/"), "target"));
116 target.set_output_type(Target::EXECUTABLE); 122 target.set_output_type(Target::EXECUTABLE);
123 target.SetToolchain(setup.toolchain());
124 target.OnResolved();
117 125
118 std::ostringstream stream; 126 std::ostringstream stream;
119 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); 127 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream);
120 std::string dep = 128 std::string dep =
121 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); 129 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>());
122 130
123 EXPECT_EQ(" | obj/foo/target.inputdeps.stamp", dep); 131 EXPECT_EQ(" | obj/foo/target.inputdeps.stamp", dep);
124 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " 132 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp "
125 "obj/foo/setup.stamp\n", 133 "obj/foo/setup.stamp\n",
126 stream.str()); 134 stream.str());
127 } 135 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_target_writer.cc ('k') | tools/gn/ninja_toolchain_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698