OLD | NEW |
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/target.h" |
10 #include "tools/gn/test_with_scope.h" | 10 #include "tools/gn/test_with_scope.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class TestingNinjaTargetWriter : public NinjaTargetWriter { | 14 class TestingNinjaTargetWriter : public NinjaTargetWriter { |
15 public: | 15 public: |
16 TestingNinjaTargetWriter(const Target* target, | 16 TestingNinjaTargetWriter(const Target* target, |
17 const Toolchain* toolchain, | 17 const Toolchain* toolchain, |
18 std::ostream& out) | 18 std::ostream& out) |
19 : NinjaTargetWriter(target, out) { | 19 : NinjaTargetWriter(target, out) { |
20 } | 20 } |
21 | 21 |
22 virtual void Run() OVERRIDE {} | 22 virtual void Run() OVERRIDE {} |
23 | 23 |
24 // Make this public so the test can call it. | 24 // Make this public so the test can call it. |
25 std::string WriteInputDepsStampAndGetDep( | 25 OutputFile WriteInputDepsStampAndGetDep( |
26 const std::vector<const Target*>& extra_hard_deps) { | 26 const std::vector<const Target*>& extra_hard_deps) { |
27 return NinjaTargetWriter::WriteInputDepsStampAndGetDep(extra_hard_deps); | 27 return NinjaTargetWriter::WriteInputDepsStampAndGetDep(extra_hard_deps); |
28 } | 28 } |
29 }; | 29 }; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) { | 33 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) { |
34 TestWithScope setup; | 34 TestWithScope setup; |
35 | 35 |
(...skipping 22 matching lines...) Expand all Loading... |
58 action.deps().push_back(LabelTargetPair(&target)); | 58 action.deps().push_back(LabelTargetPair(&target)); |
59 | 59 |
60 base_target.OnResolved(); | 60 base_target.OnResolved(); |
61 target.OnResolved(); | 61 target.OnResolved(); |
62 action.OnResolved(); | 62 action.OnResolved(); |
63 | 63 |
64 // Input deps for the base (should be only the script itself). | 64 // Input deps for the base (should be only the script itself). |
65 { | 65 { |
66 std::ostringstream stream; | 66 std::ostringstream stream; |
67 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); | 67 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); |
68 std::string dep = | 68 OutputFile dep = |
69 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 69 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
70 | 70 |
71 EXPECT_EQ(" | obj/foo/base.inputdeps.stamp", dep); | 71 EXPECT_EQ("obj/foo/base.inputdeps.stamp", dep.value()); |
72 EXPECT_EQ("build obj/foo/base.inputdeps.stamp: stamp " | 72 EXPECT_EQ("build obj/foo/base.inputdeps.stamp: stamp " |
73 "../../foo/script.py\n", | 73 "../../foo/script.py\n", |
74 stream.str()); | 74 stream.str()); |
75 } | 75 } |
76 | 76 |
77 // Input deps for the target (should depend on the base). | 77 // Input deps for the target (should depend on the base). |
78 { | 78 { |
79 std::ostringstream stream; | 79 std::ostringstream stream; |
80 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); | 80 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); |
81 std::string dep = | 81 OutputFile dep = |
82 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 82 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
83 | 83 |
84 EXPECT_EQ(" | obj/foo/target.inputdeps.stamp", dep); | 84 EXPECT_EQ("obj/foo/target.inputdeps.stamp", dep.value()); |
85 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " | 85 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " |
86 "../../foo/input.txt obj/foo/base.stamp\n", | 86 "../../foo/input.txt obj/foo/base.stamp\n", |
87 stream.str()); | 87 stream.str()); |
88 } | 88 } |
89 | 89 |
90 // Input deps for action which should depend on the base since its a hard dep | 90 // Input deps for action which should depend on the base since its a hard dep |
91 // that is a (indirect) dependency, as well as the the action source. | 91 // that is a (indirect) dependency, as well as the the action source. |
92 { | 92 { |
93 std::ostringstream stream; | 93 std::ostringstream stream; |
94 TestingNinjaTargetWriter writer(&action, setup.toolchain(), stream); | 94 TestingNinjaTargetWriter writer(&action, setup.toolchain(), stream); |
95 std::string dep = | 95 OutputFile dep = |
96 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 96 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
97 | 97 |
98 EXPECT_EQ(" | obj/foo/action.inputdeps.stamp", dep); | 98 EXPECT_EQ("obj/foo/action.inputdeps.stamp", dep.value()); |
99 EXPECT_EQ("build obj/foo/action.inputdeps.stamp: stamp ../../foo/script.py " | 99 EXPECT_EQ("build obj/foo/action.inputdeps.stamp: stamp ../../foo/script.py " |
100 "../../foo/action_source.txt obj/foo/base.stamp\n", | 100 "../../foo/action_source.txt obj/foo/base.stamp\n", |
101 stream.str()); | 101 stream.str()); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 // Tests WriteInputDepsStampAndGetDep when toolchain deps are present. | 105 // Tests WriteInputDepsStampAndGetDep when toolchain deps are present. |
106 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) { | 106 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) { |
107 TestWithScope setup; | 107 TestWithScope setup; |
108 | 108 |
109 // 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 |
110 // 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 |
111 // 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 |
112 // toolchain, and the toolchain depends on this target). | 112 // toolchain, and the toolchain depends on this target). |
113 Target toolchain_dep_target(setup.settings(), | 113 Target toolchain_dep_target(setup.settings(), |
114 Label(SourceDir("//foo/"), "setup")); | 114 Label(SourceDir("//foo/"), "setup")); |
115 toolchain_dep_target.set_output_type(Target::ACTION); | 115 toolchain_dep_target.set_output_type(Target::ACTION); |
116 toolchain_dep_target.SetToolchain(setup.toolchain()); | 116 toolchain_dep_target.SetToolchain(setup.toolchain()); |
117 toolchain_dep_target.OnResolved(); | 117 toolchain_dep_target.OnResolved(); |
118 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); | 118 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); |
119 | 119 |
120 // Make a binary target | 120 // Make a binary target |
121 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); | 121 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); |
122 target.set_output_type(Target::EXECUTABLE); | 122 target.set_output_type(Target::EXECUTABLE); |
123 target.SetToolchain(setup.toolchain()); | 123 target.SetToolchain(setup.toolchain()); |
124 target.OnResolved(); | 124 target.OnResolved(); |
125 | 125 |
126 std::ostringstream stream; | 126 std::ostringstream stream; |
127 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); | 127 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); |
128 std::string dep = | 128 OutputFile dep = |
129 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 129 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
130 | 130 |
131 EXPECT_EQ(" | obj/foo/target.inputdeps.stamp", dep); | 131 EXPECT_EQ("obj/foo/target.inputdeps.stamp", dep.value()); |
132 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " | 132 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " |
133 "obj/foo/setup.stamp\n", | 133 "obj/foo/setup.stamp\n", |
134 stream.str()); | 134 stream.str()); |
135 } | 135 } |
OLD | NEW |