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, setup.toolchain(), 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 "defines =\n" 32 "includes =\n" 33 "cflags =\n" 34 "cflags_c =\n" 35 "cflags_cc =\n" 36 "cflags_objc =\n" 37 "cflags_objcc =\n" 38 "\n" 39 "build obj/foo/bar.input1.obj: cxx ../../foo/input1.cc\n" 40 "build obj/foo/bar.input2.obj: cxx ../../foo/input2.cc\n" 41 "\n" 42 "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.obj obj/foo/bar.input2.obj\n"; 43 std::string out_str = out.str(); 44 #if defined(OS_WIN) 45 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 46 #endif 47 EXPECT_EQ(expected_win, out_str); 48 } 49 50 // A shared library that depends on the source set. 51 Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); 52 shlib_target.set_output_type(Target::SHARED_LIBRARY); 53 shlib_target.deps().push_back(LabelTargetPair(&target)); 54 shlib_target.OnResolved(); 55 56 { 57 std::ostringstream out; 58 NinjaBinaryTargetWriter writer(&shlib_target, setup.toolchain(), out); 59 writer.Run(); 60 61 // TODO(brettw) I think we'll need to worry about backslashes here 62 // depending if we're on actual Windows or Linux pretending to be Windows. 63 const char expected_win[] = 64 "defines =\n" 65 "includes =\n" 66 "cflags =\n" 67 "cflags_c =\n" 68 "cflags_cc =\n" 69 "cflags_objc =\n" 70 "cflags_objcc =\n" 71 "\n" 72 "\n" 73 "manifests = obj/foo/shlib.intermediate.manifest\n" 74 "ldflags = /MANIFEST /ManifestFile:obj/foo/shlib.intermediate.manifest\n" 75 "libs =\n" 76 "build shlib.dll shlib.dll.lib: solink obj/foo/bar.input1.obj obj/foo/bar.input2.obj\n" 77 " soname = shlib.dll\n" 78 " lib = shlib.dll\n" 79 " dll = shlib.dll\n" 80 " implibflag = /IMPLIB:shlib.dll.lib\n\n"; 81 std::string out_str = out.str(); 82 #if defined(OS_WIN) 83 std::replace(out_str.begin(), out_str.end(), '\\', '/'); 84 #endif 85 EXPECT_EQ(expected_win, out_str); 86 } 87 } 88