Skip to content

Commit 680efe4

Browse files
committed
Merge pull request ninja-build#1159 from nicolasdespres/no-explicit-outputs
Parser accepts no explicit outputs.
2 parents 63a8584 + ccaa3d1 commit 680efe4

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

src/graph_test.cc

+39
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,45 @@ TEST_F(GraphTest, ImplicitOutputOutOfDate) {
149149
EXPECT_TRUE(GetNode("out.imp")->dirty());
150150
}
151151

152+
TEST_F(GraphTest, ImplicitOutputOnlyParse) {
153+
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
154+
"build | out.imp: cat in\n"));
155+
156+
Edge* edge = GetNode("out.imp")->in_edge();
157+
EXPECT_EQ(1, edge->outputs_.size());
158+
EXPECT_EQ("out.imp", edge->outputs_[0]->path());
159+
EXPECT_EQ(1, edge->implicit_outs_);
160+
EXPECT_EQ(edge, GetNode("out.imp")->in_edge());
161+
}
162+
163+
TEST_F(GraphTest, ImplicitOutputOnlyMissing) {
164+
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
165+
"build | out.imp: cat in\n"));
166+
fs_.Create("in", "");
167+
168+
Edge* edge = GetNode("out.imp")->in_edge();
169+
string err;
170+
EXPECT_TRUE(scan_.RecomputeDirty(edge, &err));
171+
ASSERT_EQ("", err);
172+
173+
EXPECT_TRUE(GetNode("out.imp")->dirty());
174+
}
175+
176+
TEST_F(GraphTest, ImplicitOutputOnlyOutOfDate) {
177+
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
178+
"build | out.imp: cat in\n"));
179+
fs_.Create("out.imp", "");
180+
fs_.Tick();
181+
fs_.Create("in", "");
182+
183+
Edge* edge = GetNode("out.imp")->in_edge();
184+
string err;
185+
EXPECT_TRUE(scan_.RecomputeDirty(edge, &err));
186+
ASSERT_EQ("", err);
187+
188+
EXPECT_TRUE(GetNode("out.imp")->dirty());
189+
}
190+
152191
TEST_F(GraphTest, PathWithCurrentDirectory) {
153192
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
154193
"rule catdep\n"

src/manifest_parser.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,13 @@ bool ManifestParser::ParseEdge(string* err) {
236236
EvalString out;
237237
if (!lexer_.ReadPath(&out, err))
238238
return false;
239-
if (out.empty())
240-
return lexer_.Error("expected path", err);
241-
242-
do {
239+
while (!out.empty()) {
243240
outs.push_back(out);
244241

245242
out.Clear();
246243
if (!lexer_.ReadPath(&out, err))
247244
return false;
248-
} while (!out.empty());
245+
}
249246
}
250247

251248
// Add all implicit outs, counting how many as we go.
@@ -262,6 +259,9 @@ bool ManifestParser::ParseEdge(string* err) {
262259
}
263260
}
264261

262+
if (outs.empty())
263+
return lexer_.Error("expected path", err);
264+
265265
if (!ExpectToken(Lexer::COLON, err))
266266
return false;
267267

src/manifest_parser_test.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -976,13 +976,10 @@ TEST_F(ParserTest, ImplicitOutputDupes) {
976976
TEST_F(ParserTest, NoExplicitOutput) {
977977
ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
978978
string err;
979-
EXPECT_FALSE(parser.ParseTest(
979+
EXPECT_TRUE(parser.ParseTest(
980980
"rule cat\n"
981981
" command = cat $in > $out\n"
982982
"build | imp : cat bar\n", &err));
983-
ASSERT_EQ("input:3: expected path\n"
984-
"build | imp : cat bar\n"
985-
" ^ near here", err);
986983
}
987984

988985
TEST_F(ParserTest, DefaultDefault) {

0 commit comments

Comments
 (0)