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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 OutputFile 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 Err err; |
35 | 36 |
36 // Make a base target that's a hard dep (action). | 37 // Make a base target that's a hard dep (action). |
37 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base")); | 38 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base")); |
38 base_target.set_output_type(Target::ACTION); | 39 base_target.set_output_type(Target::ACTION); |
39 base_target.SetToolchain(setup.toolchain()); | 40 base_target.SetToolchain(setup.toolchain()); |
40 base_target.action_values().set_script(SourceFile("//foo/script.py")); | 41 base_target.action_values().set_script(SourceFile("//foo/script.py")); |
41 | 42 |
42 // Dependent target that also includes a source prerequisite (should get | 43 // Dependent target that also includes a source prerequisite (should get |
43 // included) and a source (should not be included). | 44 // included) and a source (should not be included). |
44 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); | 45 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); |
45 target.set_output_type(Target::EXECUTABLE); | 46 target.set_output_type(Target::EXECUTABLE); |
46 target.SetToolchain(setup.toolchain()); | 47 target.SetToolchain(setup.toolchain()); |
47 target.inputs().push_back(SourceFile("//foo/input.txt")); | 48 target.inputs().push_back(SourceFile("//foo/input.txt")); |
48 target.sources().push_back(SourceFile("//foo/source.txt")); | 49 target.sources().push_back(SourceFile("//foo/source.txt")); |
49 target.deps().push_back(LabelTargetPair(&base_target)); | 50 target.deps().push_back(LabelTargetPair(&base_target)); |
50 | 51 |
51 // Dependent action to test that action sources will be treated the same as | 52 // Dependent action to test that action sources will be treated the same as |
52 // inputs. | 53 // inputs. |
53 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); | 54 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); |
54 action.set_output_type(Target::ACTION); | 55 action.set_output_type(Target::ACTION); |
55 action.SetToolchain(setup.toolchain()); | 56 action.SetToolchain(setup.toolchain()); |
56 action.action_values().set_script(SourceFile("//foo/script.py")); | 57 action.action_values().set_script(SourceFile("//foo/script.py")); |
57 action.sources().push_back(SourceFile("//foo/action_source.txt")); | 58 action.sources().push_back(SourceFile("//foo/action_source.txt")); |
58 action.deps().push_back(LabelTargetPair(&target)); | 59 action.deps().push_back(LabelTargetPair(&target)); |
59 | 60 |
60 base_target.OnResolved(); | 61 ASSERT_TRUE(base_target.OnResolved(&err)); |
61 target.OnResolved(); | 62 ASSERT_TRUE(target.OnResolved(&err)); |
62 action.OnResolved(); | 63 ASSERT_TRUE(action.OnResolved(&err)); |
63 | 64 |
64 // Input deps for the base (should be only the script itself). | 65 // Input deps for the base (should be only the script itself). |
65 { | 66 { |
66 std::ostringstream stream; | 67 std::ostringstream stream; |
67 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); | 68 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); |
68 OutputFile dep = | 69 OutputFile dep = |
69 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 70 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
70 | 71 |
71 EXPECT_EQ("obj/foo/base.inputdeps.stamp", dep.value()); | 72 EXPECT_EQ("obj/foo/base.inputdeps.stamp", dep.value()); |
72 EXPECT_EQ("build obj/foo/base.inputdeps.stamp: stamp " | 73 EXPECT_EQ("build obj/foo/base.inputdeps.stamp: stamp " |
(...skipping 25 matching lines...) Expand all Loading... |
98 EXPECT_EQ("obj/foo/action.inputdeps.stamp", dep.value()); | 99 EXPECT_EQ("obj/foo/action.inputdeps.stamp", dep.value()); |
99 EXPECT_EQ("build obj/foo/action.inputdeps.stamp: stamp ../../foo/script.py " | 100 EXPECT_EQ("build obj/foo/action.inputdeps.stamp: stamp ../../foo/script.py " |
100 "../../foo/action_source.txt obj/foo/base.stamp\n", | 101 "../../foo/action_source.txt obj/foo/base.stamp\n", |
101 stream.str()); | 102 stream.str()); |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 // Tests WriteInputDepsStampAndGetDep when toolchain deps are present. | 106 // Tests WriteInputDepsStampAndGetDep when toolchain deps are present. |
106 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) { | 107 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) { |
107 TestWithScope setup; | 108 TestWithScope setup; |
| 109 Err err; |
108 | 110 |
109 // Toolchain dependency. Here we make a target in the same toolchain for | 111 // 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 | 112 // 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 | 113 // because it would be a circular dependency (the target depends on its |
112 // toolchain, and the toolchain depends on this target). | 114 // toolchain, and the toolchain depends on this target). |
113 Target toolchain_dep_target(setup.settings(), | 115 Target toolchain_dep_target(setup.settings(), |
114 Label(SourceDir("//foo/"), "setup")); | 116 Label(SourceDir("//foo/"), "setup")); |
115 toolchain_dep_target.set_output_type(Target::ACTION); | 117 toolchain_dep_target.set_output_type(Target::ACTION); |
116 toolchain_dep_target.SetToolchain(setup.toolchain()); | 118 toolchain_dep_target.SetToolchain(setup.toolchain()); |
117 toolchain_dep_target.OnResolved(); | 119 ASSERT_TRUE(toolchain_dep_target.OnResolved(&err)); |
118 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); | 120 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); |
119 | 121 |
120 // Make a binary target | 122 // Make a binary target |
121 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); | 123 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); |
122 target.set_output_type(Target::EXECUTABLE); | 124 target.set_output_type(Target::EXECUTABLE); |
123 target.SetToolchain(setup.toolchain()); | 125 target.SetToolchain(setup.toolchain()); |
124 target.OnResolved(); | 126 ASSERT_TRUE(target.OnResolved(&err)); |
125 | 127 |
126 std::ostringstream stream; | 128 std::ostringstream stream; |
127 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); | 129 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); |
128 OutputFile dep = | 130 OutputFile dep = |
129 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 131 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
130 | 132 |
131 EXPECT_EQ("obj/foo/target.inputdeps.stamp", dep.value()); | 133 EXPECT_EQ("obj/foo/target.inputdeps.stamp", dep.value()); |
132 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " | 134 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " |
133 "obj/foo/setup.stamp\n", | 135 "obj/foo/setup.stamp\n", |
134 stream.str()); | 136 stream.str()); |
135 } | 137 } |
OLD | NEW |