Chromium Code Reviews| 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/ninja_copy_target_writer.h" | 9 #include "tools/gn/ninja_copy_target_writer.h" |
| 10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 target.sources().push_back(SourceFile("//foo/input1.txt")); | 22 target.sources().push_back(SourceFile("//foo/input1.txt")); |
| 23 target.sources().push_back(SourceFile("//foo/input2.txt")); | 23 target.sources().push_back(SourceFile("//foo/input2.txt")); |
| 24 | 24 |
| 25 target.action_values().outputs() = | 25 target.action_values().outputs() = |
| 26 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); | 26 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); |
| 27 | 27 |
| 28 target.SetToolchain(setup.toolchain()); | 28 target.SetToolchain(setup.toolchain()); |
| 29 ASSERT_TRUE(target.OnResolved(&err)); | 29 ASSERT_TRUE(target.OnResolved(&err)); |
| 30 | 30 |
| 31 std::ostringstream out; | 31 std::ostringstream out; |
| 32 NinjaCopyTargetWriter writer(&target, out); | 32 NinjaCopyTargetWriter writer(&target, out, Toolchain::TYPE_COPY); |
| 33 writer.Run(); | 33 writer.Run(); |
| 34 | 34 |
| 35 const char expected_linux[] = | 35 const char expected_linux[] = |
| 36 "build input1.out: copy ../../foo/input1.txt\n" | 36 "build input1.out: copy ../../foo/input1.txt\n" |
| 37 "build input2.out: copy ../../foo/input2.txt\n" | 37 "build input2.out: copy ../../foo/input2.txt\n" |
| 38 "\n" | 38 "\n" |
| 39 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 39 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
| 40 std::string out_str = out.str(); | 40 std::string out_str = out.str(); |
| 41 EXPECT_EQ(expected_linux, out_str); | 41 EXPECT_EQ(expected_linux, out_str); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Tests a single file with no output pattern. | 44 // Tests a single file with no output pattern. |
| 45 TEST(NinjaCopyTargetWriter, ToolchainDeps) { | 45 TEST(NinjaCopyTargetWriter, ToolchainDeps) { |
| 46 TestWithScope setup; | 46 TestWithScope setup; |
| 47 Err err; | 47 Err err; |
| 48 | 48 |
| 49 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 49 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 50 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 50 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 51 target.set_output_type(Target::COPY_FILES); | 51 target.set_output_type(Target::COPY_FILES); |
| 52 | 52 |
| 53 target.sources().push_back(SourceFile("//foo/input1.txt")); | 53 target.sources().push_back(SourceFile("//foo/input1.txt")); |
| 54 | 54 |
| 55 target.action_values().outputs() = | 55 target.action_values().outputs() = |
| 56 SubstitutionList::MakeForTest("//out/Debug/output.out"); | 56 SubstitutionList::MakeForTest("//out/Debug/output.out"); |
| 57 | 57 |
| 58 target.SetToolchain(setup.toolchain()); | 58 target.SetToolchain(setup.toolchain()); |
| 59 ASSERT_TRUE(target.OnResolved(&err)); | 59 ASSERT_TRUE(target.OnResolved(&err)); |
| 60 | 60 |
| 61 std::ostringstream out; | 61 std::ostringstream out; |
| 62 NinjaCopyTargetWriter writer(&target, out); | 62 NinjaCopyTargetWriter writer(&target, out, Toolchain::TYPE_COPY); |
| 63 writer.Run(); | 63 writer.Run(); |
| 64 | 64 |
| 65 const char expected_linux[] = | 65 const char expected_linux[] = |
| 66 "build output.out: copy ../../foo/input1.txt\n" | 66 "build output.out: copy ../../foo/input1.txt\n" |
| 67 "\n" | 67 "\n" |
| 68 "build obj/foo/bar.stamp: stamp output.out\n"; | 68 "build obj/foo/bar.stamp: stamp output.out\n"; |
| 69 std::string out_str = out.str(); | 69 std::string out_str = out.str(); |
| 70 EXPECT_EQ(expected_linux, out_str); | 70 EXPECT_EQ(expected_linux, out_str); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST(NinjaCopyTargetWriter, OrderOnlyDeps) { | 73 TEST(NinjaCopyTargetWriter, OrderOnlyDeps) { |
| 74 TestWithScope setup; | 74 TestWithScope setup; |
| 75 Err err; | 75 Err err; |
| 76 | 76 |
| 77 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 77 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 78 | 78 |
| 79 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 79 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 80 target.set_output_type(Target::COPY_FILES); | 80 target.set_output_type(Target::COPY_FILES); |
| 81 target.sources().push_back(SourceFile("//foo/input1.txt")); | 81 target.sources().push_back(SourceFile("//foo/input1.txt")); |
| 82 target.action_values().outputs() = | 82 target.action_values().outputs() = |
| 83 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); | 83 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); |
| 84 target.inputs().push_back(SourceFile("//foo/script.py")); | 84 target.inputs().push_back(SourceFile("//foo/script.py")); |
| 85 target.SetToolchain(setup.toolchain()); | 85 target.SetToolchain(setup.toolchain()); |
| 86 ASSERT_TRUE(target.OnResolved(&err)); | 86 ASSERT_TRUE(target.OnResolved(&err)); |
| 87 | 87 |
| 88 std::ostringstream out; | 88 std::ostringstream out; |
| 89 NinjaCopyTargetWriter writer(&target, out); | 89 NinjaCopyTargetWriter writer(&target, out, Toolchain::TYPE_COPY); |
|
brettw
2016/01/26 23:51:41
Can you add a case for the new type?
sdefresne
2016/01/27 13:13:45
Done.
| |
| 90 writer.Run(); | 90 writer.Run(); |
| 91 | 91 |
| 92 const char expected_linux[] = | 92 const char expected_linux[] = |
| 93 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py\n" | 93 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py\n" |
| 94 "build input1.out: copy ../../foo/input1.txt || " | 94 "build input1.out: copy ../../foo/input1.txt || " |
| 95 "obj/foo/bar.inputdeps.stamp\n" | 95 "obj/foo/bar.inputdeps.stamp\n" |
| 96 "\n" | 96 "\n" |
| 97 "build obj/foo/bar.stamp: stamp input1.out\n"; | 97 "build obj/foo/bar.stamp: stamp input1.out\n"; |
| 98 std::string out_str = out.str(); | 98 std::string out_str = out.str(); |
| 99 EXPECT_EQ(expected_linux, out_str); | 99 EXPECT_EQ(expected_linux, out_str); |
| 100 } | 100 } |
| OLD | NEW |