| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "tools/gn/ninja_binary_target_writer.h" | 8 #include "tools/gn/ninja_binary_target_writer.h" |
| 9 #include "tools/gn/target.h" | 9 #include "tools/gn/target.h" |
| 10 #include "tools/gn/test_with_scope.h" | 10 #include "tools/gn/test_with_scope.h" |
| 11 | 11 |
| 12 TEST(NinjaBinaryTargetWriter, SourceSet) { | 12 TEST(NinjaBinaryTargetWriter, SourceSet) { |
| 13 TestWithScope setup; | 13 TestWithScope setup; |
| 14 Err err; | 14 Err err; |
| 15 | 15 |
| 16 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 16 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 17 setup.settings()->set_target_os(Settings::WIN); | 17 setup.settings()->set_target_os(Settings::WIN); |
| 18 | 18 |
| 19 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 19 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 20 target.set_output_type(Target::SOURCE_SET); | 20 target.set_output_type(Target::SOURCE_SET); |
| 21 target.visibility().SetPublic(); |
| 21 target.sources().push_back(SourceFile("//foo/input1.cc")); | 22 target.sources().push_back(SourceFile("//foo/input1.cc")); |
| 22 target.sources().push_back(SourceFile("//foo/input2.cc")); | 23 target.sources().push_back(SourceFile("//foo/input2.cc")); |
| 23 // Also test object files, which should be just passed through to the | 24 // Also test object files, which should be just passed through to the |
| 24 // dependents to link. | 25 // dependents to link. |
| 25 target.sources().push_back(SourceFile("//foo/input3.o")); | 26 target.sources().push_back(SourceFile("//foo/input3.o")); |
| 26 target.sources().push_back(SourceFile("//foo/input4.obj")); | 27 target.sources().push_back(SourceFile("//foo/input4.obj")); |
| 27 target.SetToolchain(setup.toolchain()); | 28 target.SetToolchain(setup.toolchain()); |
| 28 ASSERT_TRUE(target.OnResolved(&err)); | 29 ASSERT_TRUE(target.OnResolved(&err)); |
| 29 | 30 |
| 30 // Source set itself. | 31 // Source set itself. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 "\n" | 51 "\n" |
| 51 "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " | 52 "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " |
| 52 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj\n"; | 53 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj\n"; |
| 53 std::string out_str = out.str(); | 54 std::string out_str = out.str(); |
| 54 EXPECT_EQ(expected, out_str); | 55 EXPECT_EQ(expected, out_str); |
| 55 } | 56 } |
| 56 | 57 |
| 57 // A shared library that depends on the source set. | 58 // A shared library that depends on the source set. |
| 58 Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 59 Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); |
| 59 shlib_target.set_output_type(Target::SHARED_LIBRARY); | 60 shlib_target.set_output_type(Target::SHARED_LIBRARY); |
| 60 shlib_target.deps().push_back(LabelTargetPair(&target)); | 61 shlib_target.public_deps().push_back(LabelTargetPair(&target)); |
| 61 shlib_target.SetToolchain(setup.toolchain()); | 62 shlib_target.SetToolchain(setup.toolchain()); |
| 62 ASSERT_TRUE(shlib_target.OnResolved(&err)); | 63 ASSERT_TRUE(shlib_target.OnResolved(&err)); |
| 63 | 64 |
| 64 { | 65 { |
| 65 std::ostringstream out; | 66 std::ostringstream out; |
| 66 NinjaBinaryTargetWriter writer(&shlib_target, out); | 67 NinjaBinaryTargetWriter writer(&shlib_target, out); |
| 67 writer.Run(); | 68 writer.Run(); |
| 68 | 69 |
| 69 const char expected[] = | 70 const char expected[] = |
| 70 "defines =\n" | 71 "defines =\n" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 " ldflags =\n" | 88 " ldflags =\n" |
| 88 " libs =\n" | 89 " libs =\n" |
| 89 " output_extension = .so\n"; | 90 " output_extension = .so\n"; |
| 90 std::string out_str = out.str(); | 91 std::string out_str = out.str(); |
| 91 EXPECT_EQ(expected, out_str); | 92 EXPECT_EQ(expected, out_str); |
| 92 } | 93 } |
| 93 | 94 |
| 94 // A static library that depends on the source set (should not link it). | 95 // A static library that depends on the source set (should not link it). |
| 95 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib")); | 96 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib")); |
| 96 stlib_target.set_output_type(Target::STATIC_LIBRARY); | 97 stlib_target.set_output_type(Target::STATIC_LIBRARY); |
| 97 stlib_target.deps().push_back(LabelTargetPair(&target)); | 98 stlib_target.public_deps().push_back(LabelTargetPair(&target)); |
| 98 stlib_target.SetToolchain(setup.toolchain()); | 99 stlib_target.SetToolchain(setup.toolchain()); |
| 99 ASSERT_TRUE(stlib_target.OnResolved(&err)); | 100 ASSERT_TRUE(stlib_target.OnResolved(&err)); |
| 100 | 101 |
| 101 { | 102 { |
| 102 std::ostringstream out; | 103 std::ostringstream out; |
| 103 NinjaBinaryTargetWriter writer(&stlib_target, out); | 104 NinjaBinaryTargetWriter writer(&stlib_target, out); |
| 104 writer.Run(); | 105 writer.Run(); |
| 105 | 106 |
| 106 const char expected[] = | 107 const char expected[] = |
| 107 "defines =\n" | 108 "defines =\n" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 TEST(NinjaBinaryTargetWriter, ProductExtensionAndInputDeps) { | 165 TEST(NinjaBinaryTargetWriter, ProductExtensionAndInputDeps) { |
| 165 TestWithScope setup; | 166 TestWithScope setup; |
| 166 Err err; | 167 Err err; |
| 167 | 168 |
| 168 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 169 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 169 setup.settings()->set_target_os(Settings::LINUX); | 170 setup.settings()->set_target_os(Settings::LINUX); |
| 170 | 171 |
| 171 // An action for our library to depend on. | 172 // An action for our library to depend on. |
| 172 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); | 173 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); |
| 173 action.set_output_type(Target::ACTION_FOREACH); | 174 action.set_output_type(Target::ACTION_FOREACH); |
| 175 action.visibility().SetPublic(); |
| 174 action.SetToolchain(setup.toolchain()); | 176 action.SetToolchain(setup.toolchain()); |
| 175 ASSERT_TRUE(action.OnResolved(&err)); | 177 ASSERT_TRUE(action.OnResolved(&err)); |
| 176 | 178 |
| 177 // A shared library w/ the product_extension set to a custom value. | 179 // A shared library w/ the product_extension set to a custom value. |
| 178 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 180 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); |
| 179 target.set_output_type(Target::SHARED_LIBRARY); | 181 target.set_output_type(Target::SHARED_LIBRARY); |
| 180 target.set_output_extension(std::string("so.6")); | 182 target.set_output_extension(std::string("so.6")); |
| 181 target.sources().push_back(SourceFile("//foo/input1.cc")); | 183 target.sources().push_back(SourceFile("//foo/input1.cc")); |
| 182 target.sources().push_back(SourceFile("//foo/input2.cc")); | 184 target.sources().push_back(SourceFile("//foo/input2.cc")); |
| 183 target.deps().push_back(LabelTargetPair(&action)); | 185 target.public_deps().push_back(LabelTargetPair(&action)); |
| 184 target.SetToolchain(setup.toolchain()); | 186 target.SetToolchain(setup.toolchain()); |
| 185 ASSERT_TRUE(target.OnResolved(&err)); | 187 ASSERT_TRUE(target.OnResolved(&err)); |
| 186 | 188 |
| 187 std::ostringstream out; | 189 std::ostringstream out; |
| 188 NinjaBinaryTargetWriter writer(&target, out); | 190 NinjaBinaryTargetWriter writer(&target, out); |
| 189 writer.Run(); | 191 writer.Run(); |
| 190 | 192 |
| 191 const char expected[] = | 193 const char expected[] = |
| 192 "defines =\n" | 194 "defines =\n" |
| 193 "include_dirs =\n" | 195 "include_dirs =\n" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 "\n" | 260 "\n" |
| 259 "build ./libshlib.so: solink obj/foo/libshlib.input1.o " | 261 "build ./libshlib.so: solink obj/foo/libshlib.input1.o " |
| 260 "obj/foo/libshlib.input2.o\n" | 262 "obj/foo/libshlib.input2.o\n" |
| 261 " ldflags =\n" | 263 " ldflags =\n" |
| 262 " libs =\n" | 264 " libs =\n" |
| 263 " output_extension = .so\n"; | 265 " output_extension = .so\n"; |
| 264 | 266 |
| 265 std::string out_str = out.str(); | 267 std::string out_str = out.str(); |
| 266 EXPECT_EQ(expected, out_str); | 268 EXPECT_EQ(expected, out_str); |
| 267 } | 269 } |
| OLD | NEW |