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_action_target_writer.h" | 9 #include "tools/gn/ninja_action_target_writer.h" |
10 #include "tools/gn/substitution_list.h" | 10 #include "tools/gn/substitution_list.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 std::ostringstream out; | 21 std::ostringstream out; |
22 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); | 22 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); |
23 | 23 |
24 SourceFile source("//foo/bar.in"); | 24 SourceFile source("//foo/bar.in"); |
25 std::vector<OutputFile> output_files; | 25 std::vector<OutputFile> output_files; |
26 writer.WriteOutputFilesForBuildLine(source, &output_files); | 26 writer.WriteOutputFilesForBuildLine(source, &output_files); |
27 | 27 |
28 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str()); | 28 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str()); |
29 } | 29 } |
30 | 30 |
| 31 // Tests an action with no sources. |
| 32 TEST(NinjaActionTargetWriter, ActionNoSources) { |
| 33 TestWithScope setup; |
| 34 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 35 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 36 target.set_output_type(Target::ACTION); |
| 37 |
| 38 target.action_values().set_script(SourceFile("//foo/script.py")); |
| 39 target.inputs().push_back(SourceFile("//foo/included.txt")); |
| 40 |
| 41 target.action_values().outputs() = |
| 42 SubstitutionList::MakeForTest("//out/Debug/foo.out"); |
| 43 |
| 44 setup.settings()->set_target_os(Settings::LINUX); |
| 45 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( |
| 46 "/usr/bin/python"))); |
| 47 |
| 48 std::ostringstream out; |
| 49 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); |
| 50 writer.Run(); |
| 51 |
| 52 const char expected[] = |
| 53 "rule __foo_bar___rule\n" |
| 54 " command = /usr/bin/python ../../foo/script.py\n" |
| 55 " description = ACTION //foo:bar()\n" |
| 56 " restat = 1\n" |
| 57 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " |
| 58 "../../foo/included.txt\n" |
| 59 "\n" |
| 60 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" |
| 61 "\n" |
| 62 "build obj/foo/bar.stamp: stamp foo.out\n"; |
| 63 EXPECT_EQ(expected, out.str()); |
| 64 } |
| 65 |
31 // Makes sure that we write sources as input dependencies for actions with | 66 // Makes sure that we write sources as input dependencies for actions with |
32 // both sources and inputs (ACTION_FOREACH treats the sources differently). | 67 // both sources and inputs (ACTION_FOREACH treats the sources differently). |
33 TEST(NinjaActionTargetWriter, ActionWithSources) { | 68 TEST(NinjaActionTargetWriter, ActionWithSources) { |
34 TestWithScope setup; | 69 TestWithScope setup; |
35 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 70 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
36 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 71 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
37 target.set_output_type(Target::ACTION); | 72 target.set_output_type(Target::ACTION); |
38 | 73 |
39 target.action_values().set_script(SourceFile("//foo/script.py")); | 74 target.action_values().set_script(SourceFile("//foo/script.py")); |
40 | 75 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 "build input2.out: __foo_bar___rule ../../foo/input2.txt" | 342 "build input2.out: __foo_bar___rule ../../foo/input2.txt" |
308 " | obj/foo/bar.inputdeps.stamp\n" | 343 " | obj/foo/bar.inputdeps.stamp\n" |
309 " unique_name = 1\n" | 344 " unique_name = 1\n" |
310 " source_name_part = input2\n" | 345 " source_name_part = input2\n" |
311 " depfile = gen/input2.d\n" | 346 " depfile = gen/input2.d\n" |
312 "\n" | 347 "\n" |
313 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 348 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
314 EXPECT_EQ(expected_win, out.str()); | 349 EXPECT_EQ(expected_win, out.str()); |
315 } | 350 } |
316 } | 351 } |
OLD | NEW |