OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <sstream> |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "tools/gn/ninja_binary_target_writer.h" |
| 9 #include "tools/gn/test_with_scope.h" |
| 10 |
| 11 TEST(NinjaBinaryTargetWriter, SourceSet) { |
| 12 TestWithScope setup; |
| 13 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 14 setup.settings()->set_target_os(Settings::WIN); |
| 15 |
| 16 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 17 target.set_output_type(Target::SOURCE_SET); |
| 18 target.sources().push_back(SourceFile("//foo/input1.cc")); |
| 19 target.sources().push_back(SourceFile("//foo/input2.cc")); |
| 20 target.OnResolved(); |
| 21 |
| 22 // Source set itself. |
| 23 { |
| 24 std::ostringstream out; |
| 25 NinjaBinaryTargetWriter writer(&target, out); |
| 26 writer.Run(); |
| 27 |
| 28 // TODO(brettw) I think we'll need to worry about backslashes here |
| 29 // depending if we're on actual Windows or Linux pretending to be Windows. |
| 30 const char expected_win[] = |
| 31 "arch = environment.x86\n" |
| 32 "defines =\n" |
| 33 "includes =\n" |
| 34 "cflags =\n" |
| 35 "cflags_c =\n" |
| 36 "cflags_cc =\n" |
| 37 "cflags_objc =\n" |
| 38 "cflags_objcc =\n" |
| 39 "\n" |
| 40 "build obj/foo/bar.input1.obj: tc_cxx ../../foo/input1.cc\n" |
| 41 "build obj/foo/bar.input2.obj: tc_cxx ../../foo/input2.cc\n" |
| 42 "\n" |
| 43 "build obj/foo/bar.stamp: tc_stamp obj/foo/bar.input1.obj obj/foo/bar.in
put2.obj\n"; |
| 44 std::string out_str = out.str(); |
| 45 #if defined(OS_WIN) |
| 46 std::replace(out_str.begin(), out_str.end(), '\\', '/'); |
| 47 #endif |
| 48 EXPECT_EQ(expected_win, out_str); |
| 49 } |
| 50 |
| 51 // A shared library that depends on the source set. |
| 52 Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); |
| 53 shlib_target.set_output_type(Target::SHARED_LIBRARY); |
| 54 shlib_target.deps().push_back(&target); |
| 55 shlib_target.OnResolved(); |
| 56 |
| 57 { |
| 58 std::ostringstream out; |
| 59 NinjaBinaryTargetWriter writer(&shlib_target, out); |
| 60 writer.Run(); |
| 61 |
| 62 // TODO(brettw) I think we'll need to worry about backslashes here |
| 63 // depending if we're on actual Windows or Linux pretending to be Windows. |
| 64 const char expected_win[] = |
| 65 "arch = environment.x86\n" |
| 66 "defines =\n" |
| 67 "includes =\n" |
| 68 "cflags =\n" |
| 69 "cflags_c =\n" |
| 70 "cflags_cc =\n" |
| 71 "cflags_objc =\n" |
| 72 "cflags_objcc =\n" |
| 73 "\n" |
| 74 "\n" |
| 75 "manifests = obj/foo/shlib.intermediate.manifest\n" |
| 76 "ldflags = /MANIFEST /ManifestFile:obj/foo/shlib.intermediate.manifest\n
" |
| 77 "libs =\n" |
| 78 "build shlib.dll shlib.dll.lib: tc_solink obj/foo/bar.input1.obj obj/foo
/bar.input2.obj\n" |
| 79 " soname = shlib.dll\n" |
| 80 " lib = shlib.dll\n" |
| 81 " dll = shlib.dll\n" |
| 82 " implibflag = /IMPLIB:shlib.dll.lib\n\n"; |
| 83 std::string out_str = out.str(); |
| 84 #if defined(OS_WIN) |
| 85 std::replace(out_str.begin(), out_str.end(), '\\', '/'); |
| 86 #endif |
| 87 EXPECT_EQ(expected_win, out_str); |
| 88 } |
| 89 } |
OLD | NEW |