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" |
11 #include "tools/gn/test_with_scope.h" | 11 #include "tools/gn/test_with_scope.h" |
12 | 12 |
13 // Tests mutliple files with an output pattern and no toolchain dependency. | 13 // Tests mutliple files with an output pattern and no toolchain dependency. |
14 TEST(NinjaCopyTargetWriter, Run) { | 14 TEST(NinjaCopyTargetWriter, Run) { |
15 TestWithScope setup; | 15 TestWithScope setup; |
16 setup.settings()->set_target_os(Settings::LINUX); | 16 setup.settings()->set_target_os(Settings::LINUX); |
17 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 17 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
19 target.set_output_type(Target::COPY_FILES); | 19 target.set_output_type(Target::COPY_FILES); |
20 | 20 |
21 target.sources().push_back(SourceFile("//foo/input1.txt")); | 21 target.sources().push_back(SourceFile("//foo/input1.txt")); |
22 target.sources().push_back(SourceFile("//foo/input2.txt")); | 22 target.sources().push_back(SourceFile("//foo/input2.txt")); |
23 | 23 |
24 target.action_values().outputs().push_back( | 24 target.action_values().outputs().push_back( |
25 SourceFile("//out/Debug/{{source_name_part}}.out")); | 25 "//out/Debug/{{source_name_part}}.out"); |
26 | 26 |
27 std::ostringstream out; | 27 std::ostringstream out; |
28 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); | 28 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); |
29 writer.Run(); | 29 writer.Run(); |
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"; |
(...skipping 13 matching lines...) Expand all Loading... |
49 // simplicity, but in real life (using the Builder) this would be rejected | 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 | 50 // because it would be a circular dependency (the target depends on its |
51 // toolchain, and the toolchain depends on this target). | 51 // toolchain, and the toolchain depends on this target). |
52 Target toolchain_dep_target(setup.settings(), | 52 Target toolchain_dep_target(setup.settings(), |
53 Label(SourceDir("//foo/"), "setup")); | 53 Label(SourceDir("//foo/"), "setup")); |
54 toolchain_dep_target.set_output_type(Target::ACTION); | 54 toolchain_dep_target.set_output_type(Target::ACTION); |
55 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); | 55 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); |
56 | 56 |
57 target.sources().push_back(SourceFile("//foo/input1.txt")); | 57 target.sources().push_back(SourceFile("//foo/input1.txt")); |
58 | 58 |
59 target.action_values().outputs().push_back( | 59 target.action_values().outputs().push_back("//out/Debug/output.out"); |
60 SourceFile("//out/Debug/output.out")); | |
61 | 60 |
62 std::ostringstream out; | 61 std::ostringstream out; |
63 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); | 62 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); |
64 writer.Run(); | 63 writer.Run(); |
65 | 64 |
66 const char expected_linux[] = | 65 const char expected_linux[] = |
67 "build obj/foo/bar.inputdeps.stamp: stamp obj/foo/setup.stamp\n" | 66 "build obj/foo/bar.inputdeps.stamp: stamp obj/foo/setup.stamp\n" |
68 "build output.out: copy ../../foo/input1.txt | " | 67 "build output.out: copy ../../foo/input1.txt | " |
69 "obj/foo/bar.inputdeps.stamp\n" | 68 "obj/foo/bar.inputdeps.stamp\n" |
70 "\n" | 69 "\n" |
71 "build obj/foo/bar.stamp: stamp output.out\n"; | 70 "build obj/foo/bar.stamp: stamp output.out\n"; |
72 std::string out_str = out.str(); | 71 std::string out_str = out.str(); |
73 EXPECT_EQ(expected_linux, out_str); | 72 EXPECT_EQ(expected_linux, out_str); |
74 } | 73 } |
OLD | NEW |