OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 <algorithm> | 5 #include <algorithm> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "tools/gn/file_template.h" | 9 #include "tools/gn/file_template.h" |
10 #include "tools/gn/ninja_copy_target_writer.h" | 10 #include "tools/gn/ninja_copy_target_writer.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 const char expected_linux[] = | 31 const char expected_linux[] = |
32 "build input1.out: copy ../../foo/input1.txt\n" | 32 "build input1.out: copy ../../foo/input1.txt\n" |
33 "build input2.out: copy ../../foo/input2.txt\n" | 33 "build input2.out: copy ../../foo/input2.txt\n" |
34 "\n" | 34 "\n" |
35 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 35 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
36 std::string out_str = out.str(); | 36 std::string out_str = out.str(); |
37 EXPECT_EQ(expected_linux, out_str); | 37 EXPECT_EQ(expected_linux, out_str); |
38 } | 38 } |
39 | 39 |
40 // Tests a single file with no output pattern and a toolchain dependency. | 40 // Tests a single file with no output pattern. |
41 TEST(NinjaCopyTargetWriter, ToolchainDeps) { | 41 TEST(NinjaCopyTargetWriter, ToolchainDeps) { |
42 TestWithScope setup; | 42 TestWithScope setup; |
43 setup.settings()->set_target_os(Settings::LINUX); | 43 setup.settings()->set_target_os(Settings::LINUX); |
44 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 44 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
45 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 45 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
46 target.set_output_type(Target::COPY_FILES); | 46 target.set_output_type(Target::COPY_FILES); |
47 | 47 |
48 // Toolchain dependency. Here we make a target in the same toolchain for | |
49 // simplicity, but in real life (using the Builder) this would be rejected | |
50 // because it would be a circular dependency (the target depends on its | |
51 // toolchain, and the toolchain depends on this target). | |
52 Target toolchain_dep_target(setup.settings(), | |
53 Label(SourceDir("//foo/"), "setup")); | |
54 toolchain_dep_target.set_output_type(Target::ACTION); | |
55 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); | |
56 | |
57 target.sources().push_back(SourceFile("//foo/input1.txt")); | 48 target.sources().push_back(SourceFile("//foo/input1.txt")); |
58 | 49 |
59 target.action_values().outputs().push_back("//out/Debug/output.out"); | 50 target.action_values().outputs().push_back("//out/Debug/output.out"); |
60 | 51 |
61 std::ostringstream out; | 52 std::ostringstream out; |
62 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); | 53 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); |
63 writer.Run(); | 54 writer.Run(); |
64 | 55 |
65 const char expected_linux[] = | 56 const char expected_linux[] = |
66 "build obj/foo/bar.inputdeps.stamp: stamp obj/foo/setup.stamp\n" | 57 "build output.out: copy ../../foo/input1.txt\n" |
67 "build output.out: copy ../../foo/input1.txt | " | |
68 "obj/foo/bar.inputdeps.stamp\n" | |
69 "\n" | 58 "\n" |
70 "build obj/foo/bar.stamp: stamp output.out\n"; | 59 "build obj/foo/bar.stamp: stamp output.out\n"; |
71 std::string out_str = out.str(); | 60 std::string out_str = out.str(); |
72 EXPECT_EQ(expected_linux, out_str); | 61 EXPECT_EQ(expected_linux, out_str); |
73 } | 62 } |
OLD | NEW |