aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSasha Smundak <asmundak@google.com>2021-10-14 16:40:32 -0700
committerSasha Smundak <asmundak@google.com>2021-10-15 14:39:53 -0700
commit06f2569b2d16628608c000a76e3d495a5a5528cb (patch)
treec2c9759015d401b688f071a82068fcc56595a620
parent371194da71b3e191fea6f2ccceb7b061bd0de310 (diff)
downloadkati-06f2569b2d16628608c000a76e3d495a5a5528cb.tar.gz
Write top-level targets to the Ninja file in the alphabetical order
Fixes issue#238
-rw-r--r--src/dep.cc7
-rw-r--r--testcase/build_once.mk14
-rw-r--r--testcase/curdir_implicit_rule.mk4
3 files changed, 18 insertions, 7 deletions
diff --git a/src/dep.cc b/src/dep.cc
index d16f2d3..bf4c947 100644
--- a/src/dep.cc
+++ b/src/dep.cc
@@ -918,7 +918,12 @@ class DepBuilder {
}
Evaluator* ev_;
- map<Symbol, RuleMerger> rules_;
+ struct TargetComp {
+ bool operator()(const Symbol& lhs, const Symbol& rhs) const {
+ return lhs.str() < rhs.str();
+ }
+ };
+ map<Symbol, RuleMerger, TargetComp> rules_;
const unordered_map<Symbol, Vars*>& rule_vars_;
unique_ptr<Vars> cur_rule_vars_;
diff --git a/testcase/build_once.mk b/testcase/build_once.mk
index ecb2a4e..792ae2b 100644
--- a/testcase/build_once.mk
+++ b/testcase/build_once.mk
@@ -1,7 +1,13 @@
# expect protoc compile/link only once.
+
+# Caveat: this test relies on Make and Ninja updating
+# the targets in the same order. Make's target update
+# order is depth first, Ninja's is the first lexically
+# updatable target. Caution should be taken as Kati reorders
+# targets.
test: foo
-foo: foo.o bar.o
+foo: foo.o xbar.o
echo link $@ from $<
%.o: %.c FORCE_DO_CMD
@@ -17,12 +23,12 @@ foo.c: foo.proto
foo.proto:
-bar.c: | protoc
+xbar.c: | protoc
-bar.c: bar.proto
+xbar.c: xbar.proto
echo protoc $@ from $<
-bar.proto:
+xbar.proto:
protoc: proto.o
echo link $@ from $<
diff --git a/testcase/curdir_implicit_rule.mk b/testcase/curdir_implicit_rule.mk
index 1f4ffaa..07df0ac 100644
--- a/testcase/curdir_implicit_rule.mk
+++ b/testcase/curdir_implicit_rule.mk
@@ -1,6 +1,6 @@
srcdir := .
-test: foo.o bar.o
+test: foo.o xbar.o
echo linking $@ from $<
%.o: $(srcdir)/%.c
@@ -9,5 +9,5 @@ test: foo.o bar.o
$(srcdir)/foo.c:
echo source $@
-bar.c:
+xbar.c:
echo source $@