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
|
// Copyright (c) 2013 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 <algorithm>
#include <sstream>
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/ninja_copy_target_writer.h"
#include "tools/gn/target.h"
#include "tools/gn/test_with_scope.h"
// Tests multiple files with an output pattern and no toolchain dependency.
TEST(NinjaCopyTargetWriter, Run) {
TestWithScope setup;
Err err;
setup.settings()->set_target_os(Settings::LINUX);
setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
target.set_output_type(Target::COPY_FILES);
target.sources().push_back(SourceFile("//foo/input1.txt"));
target.sources().push_back(SourceFile("//foo/input2.txt"));
target.action_values().outputs() =
SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out");
target.SetToolchain(setup.toolchain());
ASSERT_TRUE(target.OnResolved(&err));
std::ostringstream out;
NinjaCopyTargetWriter writer(&target, out);
writer.Run();
const char expected_linux[] =
"build input1.out: copy ../../foo/input1.txt\n"
"build input2.out: copy ../../foo/input2.txt\n"
"\n"
"build obj/foo/bar.stamp: stamp input1.out input2.out\n";
std::string out_str = out.str();
EXPECT_EQ(expected_linux, out_str);
}
// Tests a single file with no output pattern.
TEST(NinjaCopyTargetWriter, ToolchainDeps) {
TestWithScope setup;
Err err;
setup.settings()->set_target_os(Settings::LINUX);
setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
target.set_output_type(Target::COPY_FILES);
target.sources().push_back(SourceFile("//foo/input1.txt"));
target.action_values().outputs() =
SubstitutionList::MakeForTest("//out/Debug/output.out");
target.SetToolchain(setup.toolchain());
ASSERT_TRUE(target.OnResolved(&err));
std::ostringstream out;
NinjaCopyTargetWriter writer(&target, out);
writer.Run();
const char expected_linux[] =
"build output.out: copy ../../foo/input1.txt\n"
"\n"
"build obj/foo/bar.stamp: stamp output.out\n";
std::string out_str = out.str();
EXPECT_EQ(expected_linux, out_str);
}
TEST(NinjaCopyTargetWriter, OrderOnlyDeps) {
TestWithScope setup;
Err err;
setup.settings()->set_target_os(Settings::LINUX);
setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
target.set_output_type(Target::COPY_FILES);
target.sources().push_back(SourceFile("//foo/input1.txt"));
target.action_values().outputs() =
SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out");
target.inputs().push_back(SourceFile("//foo/script.py"));
target.SetToolchain(setup.toolchain());
ASSERT_TRUE(target.OnResolved(&err));
std::ostringstream out;
NinjaCopyTargetWriter writer(&target, out);
writer.Run();
const char expected_linux[] =
"build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py\n"
"build input1.out: copy ../../foo/input1.txt || "
"obj/foo/bar.inputdeps.stamp\n"
"\n"
"build obj/foo/bar.stamp: stamp input1.out\n";
std::string out_str = out.str();
EXPECT_EQ(expected_linux, out_str);
}
|