1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/builder_record.h"
#include "tools/gn/gyp_binary_target_writer.h"
#include "tools/gn/test_with_scope.h"
TEST(GypBinaryTargetWriter, ProductExtension) {
TestWithScope setup;
setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
// A shared library w/ the product_extension set to a custom value.
scoped_ptr<Target> target(
new Target(setup.settings(), Label(SourceDir("//foo/"), "bar")));
target->set_output_type(Target::SHARED_LIBRARY);
target->set_output_extension(std::string("so.6"));
target->sources().push_back(SourceFile("//foo/input1.cc"));
target->sources().push_back(SourceFile("//foo/input2.cc"));
BuilderRecord record(BuilderRecord::ITEM_TARGET, target->label());
record.set_item(target.PassAs<Item>());
GypTargetWriter::TargetGroup group;
group.debug = &record;
group.release = &record;
setup.settings()->set_target_os(Settings::LINUX);
std::ostringstream out;
GypBinaryTargetWriter writer(group, setup.toolchain(),
SourceDir("//out/gn_gyp/"), out);
writer.Run();
const char expected[] =
" {\n"
" 'target_name': 'bar',\n"
" 'product_name': 'bar',\n"
" 'product_extension': 'so.6',\n"
" 'type': 'shared_library',\n"
" 'target_conditions': [\n"
" ['_toolset == \"target\"', {\n"
" 'configurations': {\n"
" 'Debug': {\n"
" 'ldflags': [ ],\n"
" },\n"
" 'Release': {\n"
" 'ldflags': [ ],\n"
" },\n"
" },\n"
" 'sources': [\n"
" '<(DEPTH)/foo/input1.cc',\n"
" '<(DEPTH)/foo/input2.cc',\n"
" ],\n"
" },],\n"
" ],\n"
" },\n";
std::string out_str = out.str();
EXPECT_EQ(expected, out_str);
}
TEST(GypBinaryTargetWriter, EmptyProductExtension) {
TestWithScope setup;
setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
// This test is the same as ProductExtension, except that
// we call set_output_extension("") and ensure that we still get the default.
scoped_ptr<Target> target(
new Target(setup.settings(), Label(SourceDir("//foo/"), "bar")));
target->set_output_type(Target::SHARED_LIBRARY);
target->sources().push_back(SourceFile("//foo/input1.cc"));
target->sources().push_back(SourceFile("//foo/input2.cc"));
target->set_output_extension(std::string());
BuilderRecord record(BuilderRecord::ITEM_TARGET, target->label());
record.set_item(target.PassAs<Item>());
GypTargetWriter::TargetGroup group;
group.debug = &record;
group.release = &record;
setup.settings()->set_target_os(Settings::LINUX);
std::ostringstream out;
GypBinaryTargetWriter writer(group, setup.toolchain(),
SourceDir("//out/gn_gyp/"), out);
writer.Run();
const char expected[] =
" {\n"
" 'target_name': 'bar',\n"
" 'product_name': 'bar',\n"
" 'type': 'shared_library',\n"
" 'target_conditions': [\n"
" ['_toolset == \"target\"', {\n"
" 'configurations': {\n"
" 'Debug': {\n"
" 'ldflags': [ ],\n"
" },\n"
" 'Release': {\n"
" 'ldflags': [ ],\n"
" },\n"
" },\n"
" 'sources': [\n"
" '<(DEPTH)/foo/input1.cc',\n"
" '<(DEPTH)/foo/input2.cc',\n"
" ],\n"
" },],\n"
" ],\n"
" },\n";
std::string out_str = out.str();
EXPECT_EQ(expected, out_str);
}
|