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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 " restat = 1\n" | 69 " restat = 1\n" |
70 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " | 70 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " |
71 "../../foo/included.txt\n" | 71 "../../foo/included.txt\n" |
72 "\n" | 72 "\n" |
73 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" | 73 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" |
74 "\n" | 74 "\n" |
75 "build obj/foo/bar.stamp: stamp foo.out\n"; | 75 "build obj/foo/bar.stamp: stamp foo.out\n"; |
76 EXPECT_EQ(expected, out.str()); | 76 EXPECT_EQ(expected, out.str()); |
77 } | 77 } |
78 | 78 |
| 79 |
| 80 // Tests an action with no sources and console = true |
| 81 TEST(NinjaActionTargetWriter, ActionNoSourcesConsole) { |
| 82 TestWithScope setup; |
| 83 Err err; |
| 84 |
| 85 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 86 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 87 target.set_output_type(Target::ACTION); |
| 88 |
| 89 target.action_values().set_script(SourceFile("//foo/script.py")); |
| 90 target.inputs().push_back(SourceFile("//foo/included.txt")); |
| 91 |
| 92 target.action_values().outputs() = |
| 93 SubstitutionList::MakeForTest("//out/Debug/foo.out"); |
| 94 target.action_values().set_console(true); |
| 95 |
| 96 target.SetToolchain(setup.toolchain()); |
| 97 ASSERT_TRUE(target.OnResolved(&err)); |
| 98 |
| 99 setup.settings()->set_target_os(Settings::LINUX); |
| 100 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( |
| 101 "/usr/bin/python"))); |
| 102 |
| 103 std::ostringstream out; |
| 104 NinjaActionTargetWriter writer(&target, out); |
| 105 writer.Run(); |
| 106 |
| 107 const char expected[] = |
| 108 "rule __foo_bar___rule\n" |
| 109 " command = /usr/bin/python ../../foo/script.py\n" |
| 110 " description = ACTION //foo:bar()\n" |
| 111 " restat = 1\n" |
| 112 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " |
| 113 "../../foo/included.txt\n" |
| 114 "\n" |
| 115 "build foo.out: __foo_bar___rule | obj/foo/bar.inputdeps.stamp\n" |
| 116 " pool = console\n" |
| 117 "\n" |
| 118 "build obj/foo/bar.stamp: stamp foo.out\n"; |
| 119 EXPECT_EQ(expected, out.str()); |
| 120 } |
| 121 |
79 // Makes sure that we write sources as input dependencies for actions with | 122 // Makes sure that we write sources as input dependencies for actions with |
80 // both sources and inputs (ACTION_FOREACH treats the sources differently). | 123 // both sources and inputs (ACTION_FOREACH treats the sources differently). |
81 TEST(NinjaActionTargetWriter, ActionWithSources) { | 124 TEST(NinjaActionTargetWriter, ActionWithSources) { |
82 TestWithScope setup; | 125 TestWithScope setup; |
83 Err err; | 126 Err err; |
84 | 127 |
85 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 128 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
86 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 129 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
87 target.set_output_type(Target::ACTION); | 130 target.set_output_type(Target::ACTION); |
88 | 131 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 "build input2.out: __foo_bar___rule ../../foo/input2.txt" | 419 "build input2.out: __foo_bar___rule ../../foo/input2.txt" |
377 " | obj/foo/bar.inputdeps.stamp\n" | 420 " | obj/foo/bar.inputdeps.stamp\n" |
378 " unique_name = 1\n" | 421 " unique_name = 1\n" |
379 " source_name_part = input2\n" | 422 " source_name_part = input2\n" |
380 " depfile = gen/input2.d\n" | 423 " depfile = gen/input2.d\n" |
381 "\n" | 424 "\n" |
382 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 425 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
383 EXPECT_EQ(expected_win, out.str()); | 426 EXPECT_EQ(expected_win, out.str()); |
384 } | 427 } |
385 } | 428 } |
OLD | NEW |