diff --git a/autotests/folding/build.ninja.fold b/autotests/folding/build.ninja.fold new file mode 100644 --- /dev/null +++ b/autotests/folding/build.ninja.fold @@ -0,0 +1,122 @@ +# comment +rule b +rule c +#d +rule c +description=a +rule d + description = ds + description = ds + rule=ds + description = ds +rule b + +rule c + +rule c + # ds + ds=ds +description=a +rule d + rule =description = ds + +rule b + command = clang -MMD -MF $out.d -o $out -c $in + description = building $out + unknown = xyz + +rule dump + command = sleep 1; ls -l /proc/self/fd; exit 1 + pool = link_pool + # blah blah + pool = console + pool = $console + +rule xy-z_ +rule --xy-z_ +rule _xy-z_ + +# error +rule with error +rule a:a +rule a|a +rule a$ +rule 0-@#d + +# browse_py.h is used to inline browse.py. +rule inline + command = "$root/src/inline.sh" $varname < $in > $out + description = INLINE $out + +default foo bar +default baz + +include ninja1.ninja + +subninja ninja2.ninja + +pool link_pool + depth = 4 + xxx = d + +pool link_pool d + depth = 4 + +build a.o: b a.c + +build a.o|c: b a.c || a | b + +build a.o | c : b a.c | a || b + +build $a.o | $c : b $a.c | $a || $b + +build 0: sleep README + +build 1: sleep README + +build all: phony 0 1 +deps = xxx +CMD = cc +build all: phony 0 1 + +build $builddir/browse_py.h: inline $root/src/browse.py | $root/src/inline.sh + varname = kBrowsePy + +build $builddir/subprocess-posix.o: cxx $root/src/subprocess-posix.cc +build $builddir/libninja.a: ar $builddir/browse.o $builddir/build.o $ + $builddir/build_log.o $builddir/clean.o $builddir/debug_flags.o $ + $builddir/depfile_parser.o $builddir/deps_log.o + +build $root/doc/manual.pdf: dblatex $builddir/manual.xml | $ + $root/doc/dblatex.xsl + +builddir=/ +builddir =/ +builddir= / +ldflags = -L$builddir + +xx x + +x = $a +x = $-a_ +x = ${a} +x = ${-a} +x = $a@ +x = $@ +x = $$ +x = $: +x = $ a +x = $ + b +x = $ + $ + a +x = $ + $a +x = $a a +x = ${a} a +x = $$ a +x = $: a +x = $! a +x = ${a b ds + x = a diff --git a/autotests/html/build.ninja.html b/autotests/html/build.ninja.html new file mode 100644 --- /dev/null +++ b/autotests/html/build.ninja.html @@ -0,0 +1,129 @@ + + + +build.ninja + +
+# comment
+rule b
+rule c
+#d
+rule c
+description=a
+rule d
+  description = ds
+  description = ds
+  rule=ds
+  description = ds
+rule b
+
+rule c
+
+rule c
+ # ds
+ ds=ds
+description=a
+rule d
+  rule =description = ds
+
+rule b
+  command = clang -MMD -MF $out.d -o $out -c $in
+  description = building $out
+  unknown = xyz
+
+rule dump
+  command = sleep 1; ls -l /proc/self/fd; exit 1
+  pool = link_pool
+  # blah blah
+  pool = console
+  pool = $console
+
+rule xy-z_
+rule --xy-z_
+rule _xy-z_
+
+# error
+rule with error
+rule a:a
+rule a|a
+rule a$
+rule 0-@#d
+
+# browse_py.h is used to inline browse.py.
+rule inline
+  command = "$root/src/inline.sh" $varname < $in > $out
+  description = INLINE $out
+
+default foo bar
+default baz
+
+include ninja1.ninja
+
+subninja ninja2.ninja
+
+pool link_pool
+  depth = 4
+  xxx = d
+
+pool link_pool d
+  depth = 4
+
+build a.o: b a.c
+
+build a.o|c: b a.c || a | b
+
+build a.o | c : b a.c | a || b
+
+build $a.o | $c : b $a.c | $a || $b
+
+build 0: sleep README
+
+build 1: sleep README
+
+build all: phony 0 1
+deps = xxx
+CMD = cc
+build all: phony 0 1
+
+build $builddir/browse_py.h: inline $root/src/browse.py | $root/src/inline.sh
+  varname = kBrowsePy
+
+build $builddir/subprocess-posix.o: cxx $root/src/subprocess-posix.cc
+build $builddir/libninja.a: ar $builddir/browse.o $builddir/build.o $
+    $builddir/build_log.o $builddir/clean.o $builddir/debug_flags.o $
+    $builddir/depfile_parser.o $builddir/deps_log.o
+
+build $root/doc/manual.pdf: dblatex $builddir/manual.xml | $
+    $root/doc/dblatex.xsl
+
+builddir=/
+builddir =/
+builddir= /
+ldflags = -L$builddir
+
+xx x
+
+x = $a
+x = $-a_
+x = ${a}
+x = ${-a}
+x = $a@
+x = $@
+x = $$
+x = $:
+x = $ a
+x = $
+    b
+x = $
+    $
+    a
+x = $
+    $a
+x = $a a
+x = ${a} a
+x = $$ a
+x = $: a
+x = $! a
+x = ${a b ds
+ x = a
+
diff --git a/autotests/input/build.ninja b/autotests/input/build.ninja new file mode 100644 --- /dev/null +++ b/autotests/input/build.ninja @@ -0,0 +1,122 @@ +# comment +rule b +rule c +#d +rule c +description=a +rule d + description = ds + description = ds + rule=ds + description = ds +rule b + +rule c + +rule c + # ds + ds=ds +description=a +rule d + rule =description = ds + +rule b + command = clang -MMD -MF $out.d -o $out -c $in + description = building $out + unknown = xyz + +rule dump + command = sleep 1; ls -l /proc/self/fd; exit 1 + pool = link_pool + # blah blah + pool = console + pool = $console + +rule xy-z_ +rule --xy-z_ +rule _xy-z_ + +# error +rule with error +rule a:a +rule a|a +rule a$ +rule 0-@#d + +# browse_py.h is used to inline browse.py. +rule inline + command = "$root/src/inline.sh" $varname < $in > $out + description = INLINE $out + +default foo bar +default baz + +include ninja1.ninja + +subninja ninja2.ninja + +pool link_pool + depth = 4 + xxx = d + +pool link_pool d + depth = 4 + +build a.o: b a.c + +build a.o|c: b a.c || a | b + +build a.o | c : b a.c | a || b + +build $a.o | $c : b $a.c | $a || $b + +build 0: sleep README + +build 1: sleep README + +build all: phony 0 1 +deps = xxx +CMD = cc +build all: phony 0 1 + +build $builddir/browse_py.h: inline $root/src/browse.py | $root/src/inline.sh + varname = kBrowsePy + +build $builddir/subprocess-posix.o: cxx $root/src/subprocess-posix.cc +build $builddir/libninja.a: ar $builddir/browse.o $builddir/build.o $ + $builddir/build_log.o $builddir/clean.o $builddir/debug_flags.o $ + $builddir/depfile_parser.o $builddir/deps_log.o + +build $root/doc/manual.pdf: dblatex $builddir/manual.xml | $ + $root/doc/dblatex.xsl + +builddir=/ +builddir =/ +builddir= / +ldflags = -L$builddir + +xx x + +x = $a +x = $-a_ +x = ${a} +x = ${-a} +x = $a@ +x = $@ +x = $$ +x = $: +x = $ a +x = $ + b +x = $ + $ + a +x = $ + $a +x = $a a +x = ${a} a +x = $$ a +x = $: a +x = $! a +x = ${a b ds + x = a diff --git a/autotests/reference/build.ninja.ref b/autotests/reference/build.ninja.ref new file mode 100644 --- /dev/null +++ b/autotests/reference/build.ninja.ref @@ -0,0 +1,122 @@ +# comment
+rule b
+rule c
+#d
+rule c
+description=a
+rule d
+ description = ds
+ description = ds
+ rule=ds
+ description = ds
+rule b
+
+rule c
+
+rule c
+ # ds
+ ds=ds
+description=a
+rule d
+ rule =description = ds
+
+rule b
+ command = clang -MMD -MF $out.d -o $out -c $in
+ description = building $out
+ unknown = xyz
+
+rule dump
+ command = sleep 1; ls -l /proc/self/fd; exit 1
+ pool = link_pool
+ # blah blah
+ pool = console
+ pool = $console
+
+rule xy-z_
+rule --xy-z_
+rule _xy-z_
+
+# error
+rule with error
+rule a:a
+rule a|a
+rule a$
+rule 0-@#d
+
+# browse_py.h is used to inline browse.py.
+rule inline
+ command = "$root/src/inline.sh" $varname < $in > $out
+ description = INLINE $out
+
+default foo bar
+default baz
+
+include ninja1.ninja
+
+subninja ninja2.ninja
+
+pool link_pool
+ depth = 4
+ xxx = d
+
+pool link_pool d
+ depth = 4
+
+build a.o: b a.c
+
+build a.o|c: b a.c || a | b
+
+build a.o | c : b a.c | a || b
+
+build $a.o | $c : b $a.c | $a || $b
+
+build 0: sleep README
+
+build 1: sleep README
+
+build all: phony 0 1
+deps = xxx
+CMD = cc
+build all: phony 0 1
+
+build $builddir/browse_py.h: inline $root/src/browse.py | $root/src/inline.sh
+ varname = kBrowsePy
+
+build $builddir/subprocess-posix.o: cxx $root/src/subprocess-posix.cc
+build $builddir/libninja.a: ar $builddir/browse.o $builddir/build.o $
+ $builddir/build_log.o $builddir/clean.o $builddir/debug_flags.o $
+ $builddir/depfile_parser.o $builddir/deps_log.o
+
+build $root/doc/manual.pdf: dblatex $builddir/manual.xml | $
+ $root/doc/dblatex.xsl
+
+builddir=/
+builddir =/
+builddir= /
+ldflags = -L$builddir
+
+xx x
+
+x = $a
+x = $-a_
+x = ${a}
+x = ${-a}
+x = $a@
+x = $@
+x = $$
+x = $:
+x = $ a
+x = $
+ b
+x = $
+ $
+ a
+x = $
+ $a
+x = $a a
+x = ${a} a
+x = $$ a
+x = $: a
+x = $! a
+x = ${a b ds
+ x = a
diff --git a/data/syntax/ninja.xml b/data/syntax/ninja.xml new file mode 100644 --- /dev/null +++ b/data/syntax/ninja.xml @@ -0,0 +1,288 @@ + + + +]> + + + rule + build + pool + + default + include + subninja + + + + console + + + + phony + + + + builddir + ninja_required_version + + + + depth + + + + command + console + depfile + deps + msvc_deps_prefix + description + generator + in + in_newline + out + pool + restat + rspfile + rspfile_content + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +