Merge pull request #1033 from colincross/failed
authorNico Weber <nicolasweber@gmx.de>
Wed, 3 Feb 2016 21:11:28 +0000 (16:11 -0500)
committerNico Weber <nicolasweber@gmx.de>
Wed, 3 Feb 2016 21:11:28 +0000 (16:11 -0500)
Print output file on failure

53 files changed:
.gitignore
.travis.yml
HACKING.md
README
RELEASING
configure.py
doc/README.md [new file with mode: 0644]
doc/dblatex.xsl [new file with mode: 0644]
doc/docbook.xsl
doc/manual.asciidoc
doc/style.css
misc/bash-completion
misc/ninja.vim
misc/ninja_syntax.py
misc/ninja_syntax_test.py
misc/packaging/ninja.spec
misc/zsh-completion
src/build.cc
src/build_log.cc
src/build_log.h
src/build_log_perftest.cc
src/build_test.cc
src/debug_flags.cc
src/debug_flags.h
src/depfile_parser.cc
src/depfile_parser.in.cc
src/depfile_parser_test.cc
src/disk_interface.cc
src/disk_interface.h
src/disk_interface_test.cc
src/eval_env.cc
src/eval_env.h
src/getopt.c
src/getopt.h
src/graph.cc
src/graph.h
src/graph_test.cc
src/includes_normalize_test.cc
src/inline.sh
src/manifest_parser.cc
src/manifest_parser.h
src/manifest_parser_perftest.cc
src/manifest_parser_test.cc
src/ninja.cc
src/ninja_test.cc
src/subprocess-posix.cc
src/subprocess-win32.cc
src/subprocess.h
src/subprocess_test.cc
src/test.cc
src/test.h
src/util.cc
src/util_test.cc

index f7fc044..5a85203 100644 (file)
@@ -7,6 +7,7 @@ TAGS
 /build
 /build.ninja
 /ninja
+/ninja.bootstrap
 /build_log_perftest
 /canon_perftest
 /depfile_parser_perftest
index 544db6f..216b8b0 100644 (file)
@@ -1,3 +1,4 @@
+sudo: false
 language: cpp
 compiler:
   - gcc
index 7fdb152..c544615 100644 (file)
@@ -20,7 +20,7 @@ You should end up with a `ninja` binary (or `ninja.exe`) in the source root.
 On Windows, you'll need to install Python to run `configure.py`, and
 run everything under a Visual Studio Tools Command Prompt (or after
 running `vcvarsall` in a normal command prompt).  See below if you
-want to use mingw or some other compiler instead using Visual Studio.
+want to use mingw or some other compiler instead of Visual Studio.
 
 ### Adjusting build flags
 
@@ -53,7 +53,7 @@ obvious exceptions (fixing typos in comments don't need tests).
 
 I am very wary of changes that increase the complexity of Ninja (in
 particular, new build file syntax or command-line flags) or increase
-the maintenance burden of Ninja.  Ninja is already successfully in use
+the maintenance burden of Ninja.  Ninja is already successfully used
 by hundreds of developers for large projects and it already achieves
 (most of) the goals I set out for it to do.  It's probably best to
 discuss new feature ideas on the mailing list before I shoot down your
@@ -74,7 +74,7 @@ build "all" before committing to verify the other source still works!
 ## Testing performance impact of changes
 
 If you have a Chrome build handy, it's a good test case.  Otherwise,
-[the github downoads page](https://github.com/martine/ninja/downloads)
+[the github downoads page](https://github.com/ninja-build/ninja/releases)
 has a copy of the Chrome build files (and depfiles). You can untar
 that, then run
 
diff --git a/README b/README
index 66a6516..a1535ff 100644 (file)
--- a/README
+++ b/README
@@ -1,19 +1,19 @@
 Ninja is a small build system with a focus on speed.
-http://martine.github.com/ninja/
+https://ninja-build.org/
 
-See the manual -- http://martine.github.com/ninja/manual.html or
+See the manual -- https://ninja-build.org/manual.html or
 doc/manual.asciidoc included in the distribution -- for background
 and more details.
 
 Binaries for Linux, Mac, and Windows are available at
-  https://github.com/martine/ninja/releases
+  https://github.com/ninja-build/ninja/releases
 Run './ninja -h' for Ninja help.
 
 To build your own binary, on many platforms it should be sufficient to
 just run `./configure.py --bootstrap`; for more details see HACKING.md.
 (Also read that before making changes to Ninja, as it has advice.)
 
-Installation is not necessary because the only required file is is the
+Installation is not necessary because the only required file is the
 resulting ninja binary. However, to enable features like Bash
 completion and Emacs and Vim editing modes, some files in misc/ must be
 copied to appropriate locations.
index 4d08253..20da5d9 100644 (file)
--- a/RELEASING
+++ b/RELEASING
@@ -17,14 +17,14 @@ Push new release branch:
 
 Release on github:
 1. https://github.com/blog/1547-release-your-software
-   Add binaries to https://github.com/martine/ninja/releases
+   Add binaries to https://github.com/ninja-build/ninja/releases
 
 Make announcement on mailing list:
 1. copy old mail
 
 Update website:
 1. Make sure your ninja checkout is on the v1.5.0 tag
-2. Clone https://github.com/martine/martine.github.io
+2. Clone https://github.com/ninja-build/ninja-build.github.io
 3. In that repo, `cd ninja && ./update-docs.sh`
 4. Update index.html with newest version and link to release notes
 5. git commit -m 'run update-docs.sh, 1.5.0 release'
index 64f940b..1c97db7 100755 (executable)
@@ -58,11 +58,13 @@ class Platform(object):
             self._platform = 'bitrig'
         elif self._platform.startswith('netbsd'):
             self._platform = 'netbsd'
+        elif self._platform.startswith('aix'):
+            self._platform = 'aix'
 
     @staticmethod
     def known_platforms():
       return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5',
-              'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd']
+              'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd', 'aix']
 
     def platform(self):
         return self._platform
@@ -81,7 +83,7 @@ class Platform(object):
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
         out, err = popen.communicate()
-        return '/FS ' in str(out)
+        return b'/FS' in out
 
     def is_windows(self):
         return self.is_mingw() or self.is_msvc()
@@ -89,6 +91,9 @@ class Platform(object):
     def is_solaris(self):
         return self._platform == 'solaris'
 
+    def is_aix(self):
+        return self._platform == 'aix'
+
     def uses_usr_local(self):
         return self._platform in ('freebsd', 'openbsd', 'bitrig')
 
@@ -96,8 +101,12 @@ class Platform(object):
         return self._platform in ('linux', 'openbsd', 'bitrig')
 
     def supports_ninja_browse(self):
-        return not self.is_windows() and not self.is_solaris()
+        return (not self.is_windows()
+                and not self.is_solaris()
+                and not self.is_aix())
 
+    def can_rebuild_in_place(self):
+        return not (self.is_windows() or self.is_aix())
 
 class Bootstrap:
     """API shim for ninja_syntax.Writer that instead runs the commands.
@@ -256,11 +265,11 @@ if platform.is_msvc():
     objext = '.obj'
 
 def src(filename):
-    return os.path.join('$sourcedir', 'src', filename)
+    return os.path.join('$root', 'src', filename)
 def built(filename):
     return os.path.join('$builddir', filename)
 def doc(filename):
-    return os.path.join('$sourcedir', 'doc', filename)
+    return os.path.join('$root', 'doc', filename)
 def cc(name, **kwargs):
     return n.build(built(name + objext), 'cxx', src(name + '.c'), **kwargs)
 def cxx(name, **kwargs):
@@ -272,7 +281,12 @@ def binary(name):
         return exe
     return name
 
-n.variable('sourcedir', sourcedir)
+root = sourcedir
+if root == os.getcwd():
+    # In the common case where we're building directly in the source
+    # tree, simplify all the paths to just be cwd-relative.
+    root = '.'
+n.variable('root', root)
 n.variable('builddir', 'build')
 n.variable('cxx', CXX)
 if platform.is_msvc():
@@ -312,11 +326,11 @@ if platform.is_msvc():
 else:
     cflags = ['-g', '-Wall', '-Wextra',
               '-Wno-deprecated',
+              '-Wno-missing-field-initializers',
               '-Wno-unused-parameter',
               '-fno-rtti',
               '-fno-exceptions',
               '-fvisibility=hidden', '-pipe',
-              '-Wno-missing-field-initializers',
               '-DNINJA_PYTHON="%s"' % options.with_python]
     if options.debug:
         cflags += ['-D_GLIBCXX_DEBUG', '-D_GLIBCXX_DEBUG_PEDANTIC']
@@ -346,6 +360,8 @@ if platform.is_mingw():
     ldflags.append('-static')
 elif platform.is_solaris():
     cflags.remove('-fvisibility=hidden')
+elif platform.is_aix():
+    cflags.remove('-fvisibility=hidden')
 elif platform.is_msvc():
     pass
 else:
@@ -486,6 +502,8 @@ if platform.is_windows():
     objs += cc('getopt')
 else:
     objs += cxx('subprocess-posix')
+if platform.is_aix():
+    objs += cc('getopt')
 if platform.is_msvc():
     ninja_lib = n.build(built('ninja.lib'), 'ar', objs)
 else:
@@ -497,6 +515,9 @@ if platform.is_msvc():
 else:
     libs.append('-lninja')
 
+if platform.is_aix():
+    libs.append('-lperfstat')
+
 all_targets = []
 
 n.comment('Main executable is library plus main() function.')
@@ -576,13 +597,19 @@ n.rule('asciidoc',
 n.rule('xsltproc',
        command='xsltproc --nonet doc/docbook.xsl $in > $out',
        description='XSLTPROC $out')
-xml = n.build(built('manual.xml'), 'asciidoc', doc('manual.asciidoc'))
-manual = n.build(doc('manual.html'), 'xsltproc', xml,
-                 implicit=doc('style.css'))
+docbookxml = n.build(built('manual.xml'), 'asciidoc', doc('manual.asciidoc'))
+manual = n.build(doc('manual.html'), 'xsltproc', docbookxml,
+                 implicit=[doc('style.css'), doc('docbook.xsl')])
 n.build('manual', 'phony',
         order_only=manual)
 n.newline()
 
+n.rule('dblatex',
+       command='dblatex -q -o $out -p doc/dblatex.xsl $in',
+       description='DBLATEX $out')
+n.build(doc('manual.pdf'), 'dblatex', docbookxml,
+        implicit=[doc('dblatex.xsl')])
+
 n.comment('Generate Doxygen.')
 n.rule('doxygen',
        command='doxygen $in',
@@ -602,12 +629,12 @@ n.newline()
 if not host.is_mingw():
     n.comment('Regenerate build files if build script changes.')
     n.rule('configure',
-           command='${configure_env}%s $sourcedir/configure.py $configure_args' %
+           command='${configure_env}%s $root/configure.py $configure_args' %
                options.with_python,
            generator=True)
     n.build('build.ninja', 'configure',
-            implicit=['$sourcedir/configure.py',
-                      os.path.normpath('$sourcedir/misc/ninja_syntax.py')])
+            implicit=['$root/configure.py',
+                      os.path.normpath('$root/misc/ninja_syntax.py')])
     n.newline()
 
 n.default(ninja)
@@ -626,17 +653,28 @@ n.build('all', 'phony', all_targets)
 n.close()
 print('wrote %s.' % BUILD_FILENAME)
 
-verbose = ''
-if options.verbose:
-    verbose = ' -v'
-
 if options.bootstrap:
     print('bootstrap complete.  rebuilding...')
-    if platform.is_windows():
-        bootstrap_exe = 'ninja.bootstrap.exe'
+
+    rebuild_args = []
+
+    if platform.can_rebuild_in_place():
+        rebuild_args.append('./ninja')
+    else:
+        if platform.is_windows():
+            bootstrap_exe = 'ninja.bootstrap.exe'
+            final_exe = 'ninja.exe'
+        else:
+            bootstrap_exe = './ninja.bootstrap'
+            final_exe = './ninja'
+
         if os.path.exists(bootstrap_exe):
             os.unlink(bootstrap_exe)
-        os.rename('ninja.exe', bootstrap_exe)
-        subprocess.check_call('ninja.bootstrap.exe%s' % verbose, shell=True)
-    else:
-        subprocess.check_call('./ninja%s' % verbose, shell=True)
+        os.rename(final_exe, bootstrap_exe)
+
+        rebuild_args.append(bootstrap_exe)
+
+    if options.verbose:
+        rebuild_args.append('-v')
+
+    subprocess.check_call(rebuild_args)
diff --git a/doc/README.md b/doc/README.md
new file mode 100644 (file)
index 0000000..6afe5d4
--- /dev/null
@@ -0,0 +1,11 @@
+This directory contains the Ninja manual and support files used in
+building it.  Here's a brief overview of how it works.
+
+The source text, `manual.asciidoc`, is written in the AsciiDoc format.
+AsciiDoc can generate HTML but it doesn't look great; instead, we use
+AsciiDoc to generate the Docbook XML format and then provide our own
+Docbook XSL tweaks to produce HTML from that.
+
+In theory using AsciiDoc and DocBook allows us to produce nice PDF
+documentation etc.  In reality it's not clear anyone wants that, but the
+build rules are in place to generate it if you install dblatex.
diff --git a/doc/dblatex.xsl b/doc/dblatex.xsl
new file mode 100644 (file)
index 0000000..c0da212
--- /dev/null
@@ -0,0 +1,7 @@
+<!-- This custom XSL tweaks the dblatex XML settings. -->
+<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
+  <!-- These parameters disable the list of collaborators and revisions.
+       Together remove a useless page from the front matter. -->
+  <xsl:param name='doc.collab.show'>0</xsl:param>
+  <xsl:param name='latex.output.revhistory'>0</xsl:param>
+</xsl:stylesheet>
index 8afdc8c..19cc126 100644 (file)
@@ -1,15 +1,29 @@
-<!-- This soup of XML is the minimum customization necessary to make the
-     autogenerated manual look ok. -->
+<!-- This custom XSL tweaks the DocBook XML -> HTML settings to produce
+     an OK-looking manual.  -->
 <!DOCTYPE xsl:stylesheet [
 <!ENTITY css SYSTEM "style.css">
 ]>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'>
   <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
+
+  <!-- Embed our stylesheet as the user-provided <head> content. -->
   <xsl:template name="user.head.content"><style>&css;</style></xsl:template>
+
+  <!-- Remove the body.attributes block, which specifies a bunch of
+       useless bgcolor etc. attrs on the <body> tag. -->
   <xsl:template name="body.attributes"></xsl:template>
-  <xsl:param name="generate.toc" select="'book toc'"/>
-  <xsl:param name="chapter.autolabel" select="0" />
+
+  <!-- Specify that in "book" form (which we're using), we only want a
+       single table of contents at the beginning of the document. -->
+  <xsl:param name="generate.toc">book toc</xsl:param>
+
+  <!-- Don't put the "Chapter 1." prefix on the "chapters". -->
+  <xsl:param name="chapter.autolabel">0</xsl:param>
+
+  <!-- Use <ul> for the table of contents.  By default DocBook uses a
+       <dl>, which makes no semantic sense.  I imagine they just did
+       it because it looks nice? -->
   <xsl:param name="toc.list.type">ul</xsl:param>
 
   <xsl:output method="html" encoding="utf-8" indent="no"
index 003c71e..4e73df3 100644 (file)
@@ -1,6 +1,5 @@
-Ninja
-=====
-Evan Martin <martine@danga.com>
+The Ninja build system
+======================
 
 
 Introduction
@@ -598,6 +597,11 @@ rule cc
   command = cl /showIncludes -c $in /Fo$out
 ----
 
+If the include directory directives are using absolute paths, your depfile
+may result in a mixture of relative and absolute paths. Paths used by other
+build rules need to match exactly. Therefore, it is recommended to use
+relative paths in these cases.
+
 [[ref_pool]]
 Pools
 ~~~~~
@@ -685,6 +689,10 @@ A file is a series of declarations.  A declaration can be one of:
    Order-only dependencies may be tacked on the end with +||
    _dependency1_ _dependency2_+.  (See <<ref_dependencies,the reference on
    dependency types>>.)
++
+Implicit outputs _(available since Ninja 1.7)_ may be added before
+the `:` with +| _output1_ _output2_+ and do not appear in `$out`.
+(See <<ref_outputs,the reference on output types>>.)
 
 3. Variable declarations, which look like +_variable_ = _value_+.
 
@@ -713,7 +721,6 @@ spaces within a token must be escaped.
 There is only one escape character, `$`, and it has the following
 behaviors:
 
-[horizontal]
 `$` followed by a newline:: escape the newline (continue the current line
 across a line break).
 
@@ -778,11 +785,9 @@ A `rule` block contains a list of `key = value` declarations that
 affect the processing of the rule.  Here is a full list of special
 keys.
 
-`command` (_required_):: the command line to run.  This string (after
-  $variables are expanded) is passed directly to `sh -c` without
-  interpretation by Ninja. Each `rule` may have only one `command`
-  declaration. To specify multiple commands use `&&` (or similar) to
-  concatenate operations.
+`command` (_required_):: the command line to run.  Each `rule` may
+  have only one `command` declaration. See <<ref_rule_command,the next
+  section>> for more details on quoting and executing multiple commands.
 
 `depfile`:: path to an optional `Makefile` that contains extra
   _implicit dependencies_ (see <<ref_dependencies,the reference on
@@ -850,6 +855,48 @@ rule link
 build myapp.exe: link a.obj b.obj [possibly many other .obj files]
 ----
 
+[[ref_rule_command]]
+Interpretation of the `command` variable
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Fundamentally, command lines behave differently on Unixes and Windows.
+
+On Unixes, commands are arrays of arguments.  The Ninja `command`
+variable is passed directly to `sh -c`, which is then responsible for
+interpreting that string into an argv array.  Therefore the quoting
+rules are those of the shell, and you can use all the normal shell
+operators, like `&&` to chain multiple commands, or `VAR=value cmd` to
+set environment variables.
+
+On Windows, commands are strings, so Ninja passes the `command` string
+directly to `CreateProcess`.  (In the common case of simply executing
+a compiler this means there is less overhead.)  Consequently the
+quoting rules are deterimined by the called program, which on Windows
+are usually provided by the C library.  If you need shell
+interpretation of the command (such as the use of `&&` to chain
+multiple commands), make the command execute the Windows shell by
+prefixing the command with `cmd /c`.
+
+[[ref_outputs]]
+Build outputs
+~~~~~~~~~~~~~
+
+There are two types of build outputs which are subtly different.
+
+1. _Explicit outputs_, as listed in a build line.  These are
+   available as the `$out` variable in the rule.
++
+This is the standard form of output to be used for e.g. the
+object file of a compile command.
+
+2. _Implicit outputs_, as listed in a build line with the syntax +|
+   _out1_ _out2_+ + before the `:` of a build line _(available since
+   Ninja 1.7)_.  The semantics are identical to explicit outputs,
+  the only difference is that implicit outputs don't show up in the
+  `$out` variable.
++
+This is for expressing outputs that don't show up on the
+command line of the command.
+
 [[ref_dependencies]]
 Build dependencies
 ~~~~~~~~~~~~~~~~~~
@@ -861,7 +908,7 @@ There are three types of build dependencies which are subtly different.
    cause the output to be rebuilt; if these file are missing and
    Ninja doesn't know how to build them, the build is aborted.
 +
-This is the standard form of dependency to be used for e.g. the
+This is the standard form of dependency to be used e.g. for the
 source file of a compile command.
 
 2. _Implicit dependencies_, either as picked up from
@@ -889,6 +936,9 @@ header file before starting a subsequent compilation step.  (Once the
 header is used in compilation, a generated dependency file will then
 express the implicit dependency.)
 
+File paths are compared as is, which means that an absolute path and a
+relative path, pointing to the same file, are considered different by Ninja.
+
 Variable expansion
 ~~~~~~~~~~~~~~~~~~
 
@@ -947,4 +997,3 @@ Variable declarations indented in a `build` block are scoped to the
 
 5. Variables from the file that included that file using the
    `subninja` keyword.
-
index 5d14a1c..9976c03 100644 (file)
@@ -24,12 +24,6 @@ div.chapter {
     margin-top: 4em;
     border-top: solid 2px black;
 }
-.section .title {
-    font-size: 1.3em;
-}
-.section .section .title {
-    font-size: 1.2em;
-}
 p {
     margin-top: 0;
 }
index 0536760..e604cd4 100644 (file)
@@ -49,9 +49,8 @@ _ninja_target() {
                C) eval dir="$OPTARG" ;;
            esac
        done;
-       targets_command="eval ninja -C \"${dir}\" -t targets all"
-       targets=$(${targets_command} 2>/dev/null | awk -F: '{print $1}')
-       COMPREPLY=($(compgen -W "$targets" -- "$cur"))
+       targets_command="eval ninja -C \"${dir}\" -t targets all 2>/dev/null | cut -d: -f1"
+       COMPREPLY=($(compgen -W '`${targets_command}`' -- "$cur"))
     fi
     return
 }
index f34588f..190d9ce 100644 (file)
@@ -1,6 +1,6 @@
 " ninja build file syntax.
 " Language: ninja build file as described at
-"           http://martine.github.com/ninja/manual.html
+"           http://ninja-build.org/manual.html
 " Version: 1.4
 " Last Change: 2014/05/13
 " Maintainer: Nicolas Weber <nicolasweber@gmx.de>
@@ -9,8 +9,8 @@
 " upstream.
 
 " ninja lexer and parser are at
-" https://github.com/martine/ninja/blob/master/src/lexer.in.cc
-" https://github.com/martine/ninja/blob/master/src/manifest_parser.cc
+" https://github.com/ninja-build/ninja/blob/master/src/lexer.in.cc
+" https://github.com/ninja-build/ninja/blob/master/src/manifest_parser.cc
 
 if exists("b:current_syntax")
   finish
index 8673518..73d2209 100644 (file)
@@ -21,8 +21,9 @@ class Writer(object):
     def newline(self):
         self.output.write('\n')
 
-    def comment(self, text):
-        for line in textwrap.wrap(text, self.width - 2):
+    def comment(self, text, has_path=False):
+        for line in textwrap.wrap(text, self.width - 2, break_long_words=False,
+                                  break_on_hyphens=False):
             self.output.write('# ' + line + '\n')
 
     def variable(self, key, value, indent=0):
index 36b2e7b..c9755b8 100755 (executable)
@@ -45,6 +45,12 @@ class TestLineWordWrap(unittest.TestCase):
                                       INDENT + 'y']) + '\n',
                          self.out.getvalue())
 
+    def test_comment_wrap(self):
+        # Filenames shoud not be wrapped
+        self.n.comment('Hello /usr/local/build-tools/bin')
+        self.assertEqual('# Hello\n# /usr/local/build-tools/bin\n',
+                         self.out.getvalue())
+
     def test_short_words_indented(self):
         # Test that indent is taking into acount when breaking subsequent lines.
         # The second line should not be '    to tree', as that's longer than the
index fa244a6..05f5a07 100644 (file)
@@ -4,7 +4,7 @@ Version: %{ver}
 Release: %{rel}%{?dist}
 Group: Development/Tools
 License: Apache 2.0
-URL: https://github.com/martine/ninja
+URL: https://github.com/ninja-build/ninja
 Source0: %{name}-%{version}-%{rel}.tar.gz
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{rel}
 
index fd9b3a7..446e269 100644 (file)
@@ -22,9 +22,8 @@ __get_targets() {
   then
     eval dir="${opt_args[-C]}"
   fi
-  targets_command="ninja -C \"${dir}\" -t targets"
-  eval ${targets_command} 2>/dev/null | while read -r a b; do echo $a | cut -d ':' -f1; done;
-
+  targets_command="ninja -C \"${dir}\" -t targets all"
+  eval ${targets_command} 2>/dev/null | cut -d: -f1
 }
 
 __get_tools() {
@@ -66,4 +65,3 @@ _arguments \
   '-d+[Enable debugging (use -d list to list modes)]:modes:__modes' \
   '-t+[Run a subtool (use -t list to list subtools)]:tools:__tools' \
   '*::targets:__targets'
-
index 8865a1d..e33a007 100644 (file)
@@ -96,7 +96,8 @@ void BuildStatus::BuildEdgeStarted(Edge* edge) {
   running_edges_.insert(make_pair(edge, start_time));
   ++started_edges_;
 
-  PrintStatus(edge);
+  if (edge->use_console() || printer_.is_smart_terminal())
+    PrintStatus(edge);
 
   if (edge->use_console())
     printer_.SetConsoleLocked(true);
@@ -121,7 +122,7 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
   if (config_.verbosity == BuildConfig::QUIET)
     return;
 
-  if (!edge->use_console() && printer_.is_smart_terminal())
+  if (!edge->use_console())
     PrintStatus(edge);
 
   // Print the command that is spewing before printing its output.
@@ -369,7 +370,7 @@ void Plan::ScheduleWork(Edge* edge) {
   if (pool->ShouldDelayEdge()) {
     // The graph is not completely clean. Some Nodes have duplicate Out edges.
     // We need to explicitly ignore these here, otherwise their work will get
-    // scheduled twice (see https://github.com/martine/ninja/pull/519)
+    // scheduled twice (see https://github.com/ninja-build/ninja/pull/519)
     if (ready_.count(edge)) {
       return;
     }
@@ -877,9 +878,17 @@ bool Builder::ExtractDeps(CommandRunner::Result* result,
       return false;
     }
 
-    string content = disk_interface_->ReadFile(depfile, err);
-    if (!err->empty())
+    // Read depfile content.  Treat a missing depfile as empty.
+    string content;
+    switch (disk_interface_->ReadFile(depfile, &content, err)) {
+    case DiskInterface::Okay:
+      break;
+    case DiskInterface::NotFound:
+      err->clear();
+      break;
+    case DiskInterface::OtherError:
       return false;
+    }
     if (content.empty())
       return true;
 
@@ -898,9 +907,11 @@ bool Builder::ExtractDeps(CommandRunner::Result* result,
       deps_nodes->push_back(state_->GetNode(*i, slash_bits));
     }
 
-    if (disk_interface_->RemoveFile(depfile) < 0) {
-      *err = string("deleting depfile: ") + strerror(errno) + string("\n");
-      return false;
+    if (!g_keep_depfile) {
+      if (disk_interface_->RemoveFile(depfile) < 0) {
+        *err = string("deleting depfile: ") + strerror(errno) + string("\n");
+        return false;
+      }
     }
   } else {
     Fatal("unknown deps type '%s'", deps_type.c_str());
index 589c6da..8a52514 100644 (file)
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// On AIX, inttypes.h gets indirectly included by build_log.h.
+// It's easiest just to ask for the printf format macros right away.
+#ifndef _WIN32
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+#endif
+
 #include "build_log.h"
 
 #include <errno.h>
@@ -19,9 +27,6 @@
 #include <string.h>
 
 #ifndef _WIN32
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
-#endif
 #include <inttypes.h>
 #include <unistd.h>
 #endif
index fe81a85..785961e 100644 (file)
@@ -27,7 +27,7 @@ struct Edge;
 
 /// Can answer questions about the manifest for the BuildLog.
 struct BuildLogUser {
-  /// Return if a given output no longer part of the build manifest.
+  /// Return if a given output is no longer part of the build manifest.
   /// This is only called during recompaction and doesn't have to be fast.
   virtual bool IsPathDead(StringPiece s) const = 0;
 };
index 810c065..185c512 100644 (file)
@@ -71,7 +71,7 @@ bool WriteTestData(string* err) {
   long_rule_command += "$in -o $out\n";
 
   State state;
-  ManifestParser parser(&state, NULL);
+  ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
   if (!parser.ParseTest("rule cxx\n  command = " + long_rule_command, err))
     return false;
 
index 52a17c9..7c6060d 100644 (file)
@@ -717,8 +717,24 @@ TEST_F(BuildTest, TwoOutputs) {
   EXPECT_EQ("touch out1 out2", command_runner_.commands_ran_[0]);
 }
 
+TEST_F(BuildTest, ImplicitOutput) {
+  ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"rule touch\n"
+"  command = touch $out $out.imp\n"
+"build out | out.imp: touch in.txt\n"));
+  fs_.Create("in.txt", "");
+
+  string err;
+  EXPECT_TRUE(builder_.AddTarget("out.imp", &err));
+  ASSERT_EQ("", err);
+  EXPECT_TRUE(builder_.Build(&err));
+  EXPECT_EQ("", err);
+  ASSERT_EQ(1u, command_runner_.commands_ran_.size());
+  EXPECT_EQ("touch out out.imp", command_runner_.commands_ran_[0]);
+}
+
 // Test case from
-//   https://github.com/martine/ninja/issues/148
+//   https://github.com/ninja-build/ninja/issues/148
 TEST_F(BuildTest, MultiOutIn) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
 "rule touch\n"
@@ -1299,7 +1315,7 @@ TEST_F(BuildWithLogTest, RestatSingleDependentOutputDirty) {
 }
 
 // Test scenario, in which an input file is removed, but output isn't changed
-// https://github.com/martine/ninja/issues/295
+// https://github.com/ninja-build/ninja/issues/295
 TEST_F(BuildWithLogTest, RestatMissingInput) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
     "rule true\n"
@@ -2047,7 +2063,7 @@ TEST_F(BuildWithDepsLogTest, DepFileDepsLogCanonicalize) {
 #endif
 
 /// Check that a restat rule doesn't clear an edge if the depfile is missing.
-/// Follows from: https://github.com/martine/ninja/issues/603
+/// Follows from: https://github.com/ninja-build/ninja/issues/603
 TEST_F(BuildTest, RestatMissingDepfile) {
 const char* manifest =
 "rule true\n"
@@ -2071,7 +2087,7 @@ const char* manifest =
 }
 
 /// Check that a restat rule doesn't clear an edge if the deps are missing.
-/// https://github.com/martine/ninja/issues/603
+/// https://github.com/ninja-build/ninja/issues/603
 TEST_F(BuildWithDepsLogTest, RestatMissingDepfileDepslog) {
   string err;
   const char* manifest =
index 8065001..44b14c4 100644 (file)
@@ -14,6 +14,8 @@
 
 bool g_explaining = false;
 
+bool g_keep_depfile = false;
+
 bool g_keep_rsp = false;
 
 bool g_experimental_statcache = true;
index 7965585..e08a43b 100644 (file)
@@ -24,6 +24,8 @@
 
 extern bool g_explaining;
 
+extern bool g_keep_depfile;
+
 extern bool g_keep_rsp;
 
 extern bool g_experimental_statcache;
index 7268f31..7cee892 100644 (file)
@@ -47,7 +47,7 @@ bool DepfileParser::Parse(string* content, string* err) {
       const char* start = in;
       
     {
-      char yych;
+      unsigned char yych;
       static const unsigned char yybm[] = {
           0,   0,   0,   0,   0,   0,   0,   0, 
           0,   0,   0,   0,   0,   0,   0,   0, 
@@ -65,22 +65,22 @@ bool DepfileParser::Parse(string* content, string* err) {
         128, 128, 128, 128, 128, 128, 128, 128, 
         128, 128, 128, 128, 128, 128, 128, 128, 
         128, 128, 128, 128,   0, 128, 128,   0, 
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
-          0,   0,   0,   0,   0,   0,   0,   0
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
+        128, 128, 128, 128, 128, 128, 128, 128
       };
 
       yych = *in;
@@ -106,24 +106,28 @@ bool DepfileParser::Parse(string* content, string* err) {
           }
         }
       } else {
-        if (yych <= '^') {
-          if (yych <= 'Z') {
+        if (yych <= '_') {
+          if (yych <= '[') {
             if (yych <= '?') goto yy9;
-            goto yy5;
+            if (yych <= 'Z') goto yy5;
+            goto yy9;
           } else {
-            if (yych != '\\') goto yy9;
+            if (yych <= '\\') goto yy2;
+            if (yych <= '^') goto yy9;
+            goto yy5;
           }
         } else {
-          if (yych <= '{') {
-            if (yych == '`') goto yy9;
-            goto yy5;
-          } else {
-            if (yych <= '|') goto yy9;
-            if (yych <= '~') goto yy5;
+          if (yych <= '|') {
+            if (yych <= '`') goto yy9;
+            if (yych <= '{') goto yy5;
             goto yy9;
+          } else {
+            if (yych == 0x7F) goto yy9;
+            goto yy5;
           }
         }
       }
+yy2:
       ++in;
       if ((yych = *in) <= '"') {
         if (yych <= '\f') {
index deaee5b..98c1621 100644 (file)
@@ -45,7 +45,7 @@ bool DepfileParser::Parse(string* content, string* err) {
       // start: beginning of the current parsed span.
       const char* start = in;
       /*!re2c
-      re2c:define:YYCTYPE = "char";
+      re2c:define:YYCTYPE = "unsigned char";
       re2c:define:YYCURSOR = in;
       re2c:define:YYLIMIT = end;
 
@@ -73,7 +73,7 @@ bool DepfileParser::Parse(string* content, string* err) {
         *out++ = yych;
         continue;
       }
-      [a-zA-Z0-9+,/_:.~()}{@=!-]+ {
+      [a-zA-Z0-9+,/_:.~()}{@=!\x80-\xFF-]+ {
         // Got a span of plain text.
         int len = (int)(in - start);
         // Need to shift it over if we're overwriting backslashes.
index fe9424a..ee798f8 100644 (file)
@@ -121,18 +121,21 @@ TEST_F(DepfileParserTest, SpecialChars) {
   EXPECT_TRUE(Parse(
 "C:/Program\\ Files\\ (x86)/Microsoft\\ crtdefs.h: \n"
 " en@quot.header~ t+t-x!=1 \n"
-" openldap/slapd.d/cn=config/cn=schema/cn={0}core.ldif",
+" openldap/slapd.d/cn=config/cn=schema/cn={0}core.ldif\n"
+" Fu\303\244ball",
       &err));
   ASSERT_EQ("", err);
   EXPECT_EQ("C:/Program Files (x86)/Microsoft crtdefs.h",
             parser_.out_.AsString());
-  ASSERT_EQ(3u, parser_.ins_.size());
+  ASSERT_EQ(4u, parser_.ins_.size());
   EXPECT_EQ("en@quot.header~",
             parser_.ins_[0].AsString());
   EXPECT_EQ("t+t-x!=1",
             parser_.ins_[1].AsString());
   EXPECT_EQ("openldap/slapd.d/cn=config/cn=schema/cn={0}core.ldif",
             parser_.ins_[2].AsString());
+  EXPECT_EQ("Fu\303\244ball",
+            parser_.ins_[3].AsString());
 }
 
 TEST_F(DepfileParserTest, UnifyMultipleOutputs) {
index 70282c0..451a9b4 100644 (file)
@@ -229,14 +229,14 @@ bool RealDiskInterface::MakeDir(const string& path) {
   return true;
 }
 
-string RealDiskInterface::ReadFile(const string& path, string* err) {
-  string contents;
-  int ret = ::ReadFile(path, &contents, err);
-  if (ret == -ENOENT) {
-    // Swallow ENOENT.
-    err->clear();
+FileReader::Status RealDiskInterface::ReadFile(const string& path,
+                                               string* contents,
+                                               string* err) {
+  switch (::ReadFile(path, contents, err)) {
+  case 0:       return Okay;
+  case -ENOENT: return NotFound;
+  default:      return OtherError;
   }
-  return contents;
 }
 
 int RealDiskInterface::RemoveFile(const string& path) {
index b61d192..145e089 100644 (file)
@@ -21,13 +21,29 @@ using namespace std;
 
 #include "timestamp.h"
 
+/// Interface for reading files from disk.  See DiskInterface for details.
+/// This base offers the minimum interface needed just to read files.
+struct FileReader {
+  virtual ~FileReader() {}
+
+  /// Result of ReadFile.
+  enum Status {
+    Okay,
+    NotFound,
+    OtherError
+  };
+
+  /// Read and store in given string.  On success, return Okay.
+  /// On error, return another Status and fill |err|.
+  virtual Status ReadFile(const string& path, string* contents,
+                          string* err) = 0;
+};
+
 /// Interface for accessing the disk.
 ///
 /// Abstract so it can be mocked out for tests.  The real implementation
 /// is RealDiskInterface.
-struct DiskInterface {
-  virtual ~DiskInterface() {}
-
+struct DiskInterface: public FileReader {
   /// stat() a file, returning the mtime, or 0 if missing and -1 on
   /// other errors.
   virtual TimeStamp Stat(const string& path, string* err) const = 0;
@@ -39,9 +55,6 @@ struct DiskInterface {
   /// Returns true on success, false on failure
   virtual bool WriteFile(const string& path, const string& contents) = 0;
 
-  /// Read a file to a string.  Fill in |err| on error.
-  virtual string ReadFile(const string& path, string* err) = 0;
-
   /// Remove the file named @a path. It behaves like 'rm -f path' so no errors
   /// are reported if it does not exists.
   /// @returns 0 if the file has been removed,
@@ -65,7 +78,7 @@ struct RealDiskInterface : public DiskInterface {
   virtual TimeStamp Stat(const string& path, string* err) const;
   virtual bool MakeDir(const string& path);
   virtual bool WriteFile(const string& path, const string& contents);
-  virtual string ReadFile(const string& path, string* err);
+  virtual Status ReadFile(const string& path, string* contents, string* err);
   virtual int RemoveFile(const string& path);
 
   /// Whether stat information can be cached.  Only has an effect on Windows.
index 9d210b4..7187bdf 100644 (file)
@@ -157,8 +157,12 @@ TEST_F(DiskInterfaceTest, StatCache) {
 
 TEST_F(DiskInterfaceTest, ReadFile) {
   string err;
-  EXPECT_EQ("", disk_.ReadFile("foobar", &err));
-  EXPECT_EQ("", err);
+  std::string content;
+  ASSERT_EQ(DiskInterface::NotFound,
+            disk_.ReadFile("foobar", &content, &err));
+  EXPECT_EQ("", content);
+  EXPECT_NE("", err); // actual value is platform-specific
+  err.clear();
 
   const char* kTestFile = "testfile";
   FILE* f = fopen(kTestFile, "wb");
@@ -167,7 +171,9 @@ TEST_F(DiskInterfaceTest, ReadFile) {
   fprintf(f, "%s", kTestContent);
   ASSERT_EQ(0, fclose(f));
 
-  EXPECT_EQ(kTestContent, disk_.ReadFile(kTestFile, &err));
+  ASSERT_EQ(DiskInterface::Okay,
+            disk_.ReadFile(kTestFile, &content, &err));
+  EXPECT_EQ(kTestContent, content);
   EXPECT_EQ("", err);
 }
 
@@ -208,9 +214,9 @@ struct StatTest : public StateTestWithBuiltinRules,
     assert(false);
     return false;
   }
-  virtual string ReadFile(const string& path, string* err) {
+  virtual Status ReadFile(const string& path, string* contents, string* err) {
     assert(false);
-    return "";
+    return NotFound;
   }
   virtual int RemoveFile(const string& path) {
     assert(false);
index e991d21..8817a87 100644 (file)
@@ -55,7 +55,7 @@ void Rule::AddBinding(const string& key, const EvalString& val) {
 }
 
 const EvalString* Rule::GetBinding(const string& key) const {
-  map<string, EvalString>::const_iterator i = bindings_.find(key);
+  Bindings::const_iterator i = bindings_.find(key);
   if (i == bindings_.end())
     return NULL;
   return &i->second;
@@ -71,7 +71,8 @@ bool Rule::IsReservedBinding(const string& var) {
       var == "pool" ||
       var == "restat" ||
       var == "rspfile" ||
-      var == "rspfile_content";
+      var == "rspfile_content" ||
+      var == "msvc_deps_prefix";
 }
 
 const map<string, const Rule*>& BindingEnv::GetRules() const {
index 28c4d16..999ce42 100644 (file)
@@ -57,7 +57,6 @@ struct Rule {
 
   const string& name() const { return name_; }
 
-  typedef map<string, EvalString> Bindings;
   void AddBinding(const string& key, const EvalString& val);
 
   static bool IsReservedBinding(const string& var);
@@ -69,7 +68,8 @@ struct Rule {
   friend struct ManifestParser;
 
   string name_;
-  map<string, EvalString> bindings_;
+  typedef map<string, EvalString> Bindings;
+  Bindings bindings_;
 };
 
 /// An Env which contains a mapping of variables to values
index 3350fb9..0c2ef35 100644 (file)
@@ -385,11 +385,13 @@ getopt_internal (int argc, char **argv, char *shortopts,
     return optopt;
 }
 
+#ifndef _AIX
 int
 getopt (int argc, char **argv, char *optstring)
 {
   return getopt_internal (argc, argv, optstring, NULL, NULL, 0);
 }
+#endif
 
 int
 getopt_long (int argc, char **argv, const char *shortopts,
index b4247fb..965dc29 100644 (file)
@@ -39,7 +39,9 @@ extern "C"
   extern int optopt;
 
   /* function prototypes */
+#ifndef _AIX
   int getopt (int argc, char **argv, char *optstring);
+#endif
   int getopt_long (int argc, char **argv, const char *shortopts,
                    const GETOPT_LONG_OPTION_T * longopts, int *longind);
   int getopt_long_only (int argc, char **argv, const char *shortopts,
index 9e65675..98a2c18 100644 (file)
@@ -241,8 +241,9 @@ string EdgeEnv::LookupVariable(const string& var) {
                         edge_->inputs_.begin() + explicit_deps_count,
                         var == "in" ? ' ' : '\n');
   } else if (var == "out") {
+    int explicit_outs_count = edge_->outputs_.size() - edge_->implicit_outs_;
     return MakePathList(edge_->outputs_.begin(),
-                        edge_->outputs_.end(),
+                        edge_->outputs_.begin() + explicit_outs_count,
                         ' ');
   }
 
@@ -395,8 +396,15 @@ bool ImplicitDepLoader::LoadDeps(Edge* edge, string* err) {
 bool ImplicitDepLoader::LoadDepFile(Edge* edge, const string& path,
                                     string* err) {
   METRIC_RECORD("depfile load");
-  string content = disk_interface_->ReadFile(path, err);
-  if (!err->empty()) {
+  // Read depfile content.  Treat a missing depfile as empty.
+  string content;
+  switch (disk_interface_->ReadFile(path, &content, err)) {
+  case DiskInterface::Okay:
+    break;
+  case DiskInterface::NotFound:
+    err->clear();
+    break;
+  case DiskInterface::OtherError:
     *err = "loading '" + path + "': " + *err;
     return false;
   }
index cf15123..add8d3d 100644 (file)
@@ -129,7 +129,7 @@ private:
 struct Edge {
   Edge() : rule_(NULL), pool_(NULL), env_(NULL),
            outputs_ready_(false), deps_missing_(false),
-           implicit_deps_(0), order_only_deps_(0) {}
+           implicit_deps_(0), order_only_deps_(0), implicit_outs_(0) {}
 
   /// Return true if all inputs' in-edges are ready.
   bool AllInputsReady() const;
@@ -181,6 +181,16 @@ struct Edge {
     return index >= inputs_.size() - order_only_deps_;
   }
 
+  // There are two types of outputs.
+  // 1) explicit outs, which show up as $out on the command line;
+  // 2) implicit outs, which the target generates but are not part of $out.
+  // These are stored in outputs_ in that order, and we keep a count of
+  // #2 to use when we need to access the various subsets.
+  int implicit_outs_;
+  bool is_implicit_out(size_t index) const {
+    return index >= outputs_.size() - implicit_outs_;
+  }
+
   bool is_phony() const;
   bool use_console() const;
 };
index e41f5cc..723e8ea 100644 (file)
@@ -105,6 +105,50 @@ TEST_F(GraphTest, ExplicitImplicit) {
   EXPECT_TRUE(GetNode("out.o")->dirty());
 }
 
+TEST_F(GraphTest, ImplicitOutputParse) {
+  ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build out | out.imp: cat in\n"));
+
+  Edge* edge = GetNode("out")->in_edge();
+  EXPECT_EQ(2, edge->outputs_.size());
+  EXPECT_EQ("out", edge->outputs_[0]->path());
+  EXPECT_EQ("out.imp", edge->outputs_[1]->path());
+  EXPECT_EQ(1, edge->implicit_outs_);
+  EXPECT_EQ(edge, GetNode("out.imp")->in_edge());
+}
+
+TEST_F(GraphTest, ImplicitOutputMissing) {
+  ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build out | out.imp: cat in\n"));
+  fs_.Create("in", "");
+  fs_.Create("out", "");
+
+  Edge* edge = GetNode("out")->in_edge();
+  string err;
+  EXPECT_TRUE(scan_.RecomputeDirty(edge, &err));
+  ASSERT_EQ("", err);
+
+  EXPECT_TRUE(GetNode("out")->dirty());
+  EXPECT_TRUE(GetNode("out.imp")->dirty());
+}
+
+TEST_F(GraphTest, ImplicitOutputOutOfDate) {
+  ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build out | out.imp: cat in\n"));
+  fs_.Create("out.imp", "");
+  fs_.Tick();
+  fs_.Create("in", "");
+  fs_.Create("out", "");
+
+  Edge* edge = GetNode("out")->in_edge();
+  string err;
+  EXPECT_TRUE(scan_.RecomputeDirty(edge, &err));
+  ASSERT_EQ("", err);
+
+  EXPECT_TRUE(GetNode("out")->dirty());
+  EXPECT_TRUE(GetNode("out.imp")->dirty());
+}
+
 TEST_F(GraphTest, PathWithCurrentDirectory) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
 "rule catdep\n"
@@ -153,7 +197,7 @@ TEST_F(GraphTest, VarInOutPathEscaping) {
 #endif
 }
 
-// Regression test for https://github.com/martine/ninja/issues/380
+// Regression test for https://github.com/ninja-build/ninja/issues/380
 TEST_F(GraphTest, DepfileWithCanonicalizablePath) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
 "rule catdep\n"
@@ -172,7 +216,7 @@ TEST_F(GraphTest, DepfileWithCanonicalizablePath) {
   EXPECT_FALSE(GetNode("out.o")->dirty());
 }
 
-// Regression test for https://github.com/martine/ninja/issues/404
+// Regression test for https://github.com/ninja-build/ninja/issues/404
 TEST_F(GraphTest, DepfileRemoved) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
 "rule catdep\n"
index aba25d0..f18795c 100644 (file)
@@ -30,15 +30,15 @@ string GetCurDir() {
   return parts[parts.size() - 1];
 }
 
-string NormalizeAndCheckNoError(const std::string& input) {
+string NormalizeAndCheckNoError(const string& input) {
   string result, err;
   EXPECT_TRUE(IncludesNormalize::Normalize(input.c_str(), NULL, &result, &err));
   EXPECT_EQ("", err);
   return result;
 }
 
-string NormalizeRelativeAndCheckNoError(const std::string& input,
-                                        const std::string& relative_to) {
+string NormalizeRelativeAndCheckNoError(const string& input,
+                                        const string& relative_to) {
   string result, err;
   EXPECT_TRUE(IncludesNormalize::Normalize(input.c_str(), relative_to.c_str(),
                                            &result, &err));
@@ -160,8 +160,8 @@ TEST(IncludesNormalize, LongInvalidPath) {
       "012345678\\"
       "012345678\\"
       "0123456789";
-  std::string forward_slashes(kExactlyMaxPath);
-  std::replace(forward_slashes.begin(), forward_slashes.end(), '\\', '/');
+  string forward_slashes(kExactlyMaxPath);
+  replace(forward_slashes.begin(), forward_slashes.end(), '\\', '/');
   // Make sure a path that's exactly _MAX_PATH long is canonicalized.
   EXPECT_EQ(forward_slashes,
             NormalizeAndCheckNoError(kExactlyMaxPath));
index 5acc17b..fa282fa 100755 (executable)
@@ -20,6 +20,6 @@
 
 varname="$1"
 echo "const char $varname[] ="
-od -t x1 -A n -v | sed -e 's| ||g; s|..|\\x&|g; s|^|"|; s|$|"|'
+od -t x1 -A n -v | sed -e 's|[ \t]||g; s|..|\\x&|g; s|^|"|; s|$|"|'
 echo ";"
 
index e8c0436..be267a3 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <vector>
 
+#include "disk_interface.h"
 #include "graph.h"
 #include "metrics.h"
 #include "state.h"
@@ -25,9 +26,9 @@
 #include "version.h"
 
 ManifestParser::ManifestParser(State* state, FileReader* file_reader,
-                               bool dupe_edge_should_err)
+                               DupeEdgeAction dupe_edge_action)
     : state_(state), file_reader_(file_reader),
-      dupe_edge_should_err_(dupe_edge_should_err), quiet_(false) {
+      dupe_edge_action_(dupe_edge_action), quiet_(false) {
   env_ = &state->bindings_;
 }
 
@@ -35,7 +36,7 @@ bool ManifestParser::Load(const string& filename, string* err, Lexer* parent) {
   METRIC_RECORD(".ninja parse");
   string contents;
   string read_err;
-  if (!file_reader_->ReadFile(filename, &contents, &read_err)) {
+  if (file_reader_->ReadFile(filename, &contents, &read_err) != FileReader::Okay) {
     *err = "loading '" + filename + "': " + read_err;
     if (parent)
       parent->Error(string(*err), err);
@@ -247,6 +248,20 @@ bool ManifestParser::ParseEdge(string* err) {
     } while (!out.empty());
   }
 
+  // Add all implicit outs, counting how many as we go.
+  int implicit_outs = 0;
+  if (lexer_.PeekToken(Lexer::PIPE)) {
+    for (;;) {
+      EvalString out;
+      if (!lexer_.ReadPath(&out, err))
+        return err;
+      if (out.empty())
+        break;
+      outs.push_back(out);
+      ++implicit_outs;
+    }
+  }
+
   if (!ExpectToken(Lexer::COLON, err))
     return false;
 
@@ -331,7 +346,7 @@ bool ManifestParser::ParseEdge(string* err) {
     if (!CanonicalizePath(&path, &slash_bits, &path_err))
       return lexer_.Error(path_err, err);
     if (!state_->AddOut(edge, path, slash_bits)) {
-      if (dupe_edge_should_err_) {
+      if (dupe_edge_action_ == kDupeEdgeActionError) {
         lexer_.Error("multiple rules generate " + path + " [-w dupbuild=err]",
                      err);
         return false;
@@ -350,6 +365,7 @@ bool ManifestParser::ParseEdge(string* err) {
     delete edge;
     return true;
   }
+  edge->implicit_outs_ = implicit_outs;
 
   edge->inputs_.reserve(ins.size());
   for (vector<EvalString>::iterator i = ins.begin(); i != ins.end(); ++i) {
@@ -380,7 +396,7 @@ bool ManifestParser::ParseFileInclude(bool new_scope, string* err) {
     return false;
   string path = eval.Evaluate(env_);
 
-  ManifestParser subparser(state_, file_reader_);
+  ManifestParser subparser(state_, file_reader_, dupe_edge_action_);
   if (new_scope) {
     subparser.env_ = new BindingEnv(env_);
   } else {
index f72cd6f..043e4b2 100644 (file)
@@ -23,17 +23,18 @@ using namespace std;
 
 struct BindingEnv;
 struct EvalString;
+struct FileReader;
 struct State;
 
+enum DupeEdgeAction {
+  kDupeEdgeActionWarn,
+  kDupeEdgeActionError,
+};
+
 /// Parses .ninja files.
 struct ManifestParser {
-  struct FileReader {
-    virtual ~FileReader() {}
-    virtual bool ReadFile(const string& path, string* content, string* err) = 0;
-  };
-
   ManifestParser(State* state, FileReader* file_reader,
-                 bool dupe_edge_should_err = false);
+                 DupeEdgeAction dupe_edge_action);
 
   /// Load and parse a file.
   bool Load(const string& filename, string* err, Lexer* parent = NULL);
@@ -66,7 +67,7 @@ private:
   BindingEnv* env_;
   FileReader* file_reader_;
   Lexer lexer_;
-  bool dupe_edge_should_err_;
+  DupeEdgeAction dupe_edge_action_;
   bool quiet_;
 };
 
index 6b56ab0..572e2d5 100644 (file)
 #include "state.h"
 #include "util.h"
 
-struct RealFileReader : public ManifestParser::FileReader {
-  virtual bool ReadFile(const string& path, string* content, string* err) {
-    return ::ReadFile(path, content, err) == 0;
-  }
-};
-
 bool WriteFakeManifests(const string& dir, string* err) {
   RealDiskInterface disk_interface;
   TimeStamp mtime = disk_interface.Stat(dir + "/build.ninja", err);
@@ -59,9 +53,9 @@ bool WriteFakeManifests(const string& dir, string* err) {
 
 int LoadManifests(bool measure_command_evaluation) {
   string err;
-  RealFileReader file_reader;
+  RealDiskInterface disk_interface;
   State state;
-  ManifestParser parser(&state, &file_reader);
+  ManifestParser parser(&state, &disk_interface, kDupeEdgeActionWarn);
   if (!parser.Load("build.ninja", &err)) {
     fprintf(stderr, "Failed to read test data: %s\n", err.c_str());
     exit(1);
index 8f7b575..e8c1907 100644 (file)
 #include "state.h"
 #include "test.h"
 
-struct ParserTest : public testing::Test,
-                    public ManifestParser::FileReader {
+struct ParserTest : public testing::Test {
   void AssertParse(const char* input) {
-    ManifestParser parser(&state, this);
+    ManifestParser parser(&state, &fs_, kDupeEdgeActionWarn);
     string err;
     EXPECT_TRUE(parser.ParseTest(input, &err));
     ASSERT_EQ("", err);
     VerifyGraph(state);
   }
 
-  virtual bool ReadFile(const string& path, string* content, string* err) {
-    files_read_.push_back(path);
-    map<string, string>::iterator i = files_.find(path);
-    if (i == files_.end()) {
-      *err = "No such file or directory";  // Match strerror() for ENOENT.
-      return false;
-    }
-    *content = i->second;
-    return true;
-  }
-
   State state;
-  map<string, string> files_;
-  vector<string> files_read_;
+  VirtualFileSystem fs_;
 };
 
 TEST_F(ParserTest, Empty) {
@@ -371,12 +358,28 @@ TEST_F(ParserTest, DuplicateEdgeWithMultipleOutputsError) {
 "build out1 out2: cat in1\n"
 "build out1: cat in2\n"
 "build final: cat out1\n";
-  ManifestParser parser(&state, this, /*dupe_edges_should_err=*/true);
+  ManifestParser parser(&state, &fs_, kDupeEdgeActionError);
   string err;
   EXPECT_FALSE(parser.ParseTest(kInput, &err));
   EXPECT_EQ("input:5: multiple rules generate out1 [-w dupbuild=err]\n", err);
 }
 
+TEST_F(ParserTest, DuplicateEdgeInIncludedFile) {
+  fs_.Create("sub.ninja",
+    "rule cat\n"
+    "  command = cat $in > $out\n"
+    "build out1 out2: cat in1\n"
+    "build out1: cat in2\n"
+    "build final: cat out1\n");
+  const char kInput[] =
+    "subninja sub.ninja\n";
+  ManifestParser parser(&state, &fs_, kDupeEdgeActionError);
+  string err;
+  EXPECT_FALSE(parser.ParseTest(kInput, &err));
+  EXPECT_EQ("sub.ninja:5: multiple rules generate out1 [-w dupbuild=err]\n",
+            err);
+}
+
 TEST_F(ParserTest, ReservedWords) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(
 "rule build\n"
@@ -388,7 +391,7 @@ TEST_F(ParserTest, ReservedWords) {
 TEST_F(ParserTest, Errors) {
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest(string("subn", 4), &err));
     EXPECT_EQ("input:1: expected '=', got eof\n"
@@ -399,7 +402,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("foobar", &err));
     EXPECT_EQ("input:1: expected '=', got eof\n"
@@ -410,7 +413,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("x 3", &err));
     EXPECT_EQ("input:1: expected '=', got identifier\n"
@@ -421,7 +424,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("x = 3", &err));
     EXPECT_EQ("input:1: unexpected EOF\n"
@@ -432,7 +435,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("x = 3\ny 2", &err));
     EXPECT_EQ("input:2: expected '=', got identifier\n"
@@ -443,7 +446,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("x = $", &err));
     EXPECT_EQ("input:1: bad $-escape (literal $ must be written as $$)\n"
@@ -454,7 +457,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("x = $\n $[\n", &err));
     EXPECT_EQ("input:2: bad $-escape (literal $ must be written as $$)\n"
@@ -465,7 +468,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("x = a$\n b$\n $\n", &err));
     EXPECT_EQ("input:4: unexpected EOF\n"
@@ -474,7 +477,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("build\n", &err));
     EXPECT_EQ("input:1: expected path\n"
@@ -485,7 +488,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("build x: y z\n", &err));
     EXPECT_EQ("input:1: unknown build rule 'y'\n"
@@ -496,7 +499,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("build x:: y z\n", &err));
     EXPECT_EQ("input:1: expected build command name\n"
@@ -507,7 +510,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cat\n  command = cat ok\n"
                                   "build x: cat $\n :\n",
@@ -520,7 +523,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cat\n",
                                   &err));
@@ -529,7 +532,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cat\n"
                                   "  command = echo\n"
@@ -543,7 +546,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cat\n"
                                   "  command = echo\n"
@@ -555,7 +558,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cat\n"
                                   "  command = ${fafsd\n"
@@ -570,7 +573,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cat\n"
                                   "  command = cat\n"
@@ -585,7 +588,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cat\n"
                                   "  command = cat\n"
@@ -599,7 +602,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule %foo\n",
                                   &err));
@@ -608,7 +611,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cc\n"
                                   "  command = foo\n"
@@ -622,7 +625,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cc\n  command = foo\n"
                                   "build $.: cc bar.cc\n",
@@ -635,7 +638,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cc\n  command = foo\n  && bar",
                                   &err));
@@ -644,7 +647,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule cc\n  command = foo\n"
                                   "build $: cc bar.cc\n",
@@ -657,7 +660,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("default\n",
                                   &err));
@@ -669,7 +672,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("default nonexistent\n",
                                   &err));
@@ -681,7 +684,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule r\n  command = r\n"
                                   "build b: r\n"
@@ -695,7 +698,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("default $a\n", &err));
     EXPECT_EQ("input:1: empty path\n"
@@ -706,7 +709,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("rule r\n"
                                   "  command = r\n"
@@ -718,7 +721,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     // the indented blank line must terminate the rule
     // this also verifies that "unexpected (token)" errors are correct
@@ -731,7 +734,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("pool\n", &err));
     EXPECT_EQ("input:1: expected pool name\n", err);
@@ -739,7 +742,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("pool foo\n", &err));
     EXPECT_EQ("input:2: expected 'depth =' line\n", err);
@@ -747,7 +750,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("pool foo\n"
                                   "  depth = 4\n"
@@ -760,7 +763,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("pool foo\n"
                                   "  depth = -1\n", &err));
@@ -772,7 +775,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     EXPECT_FALSE(parser.ParseTest("pool foo\n"
                                   "  bar = 1\n", &err));
@@ -784,7 +787,7 @@ TEST_F(ParserTest, Errors) {
 
   {
     State state;
-    ManifestParser parser(&state, NULL);
+    ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
     string err;
     // Pool names are dereferenced at edge parsing time.
     EXPECT_FALSE(parser.ParseTest("rule run\n"
@@ -797,7 +800,7 @@ TEST_F(ParserTest, Errors) {
 
 TEST_F(ParserTest, MissingInput) {
   State state;
-  ManifestParser parser(&state, this);
+  ManifestParser parser(&state, &fs_, kDupeEdgeActionWarn);
   string err;
   EXPECT_FALSE(parser.Load("build.ninja", &err));
   EXPECT_EQ("loading 'build.ninja': No such file or directory", err);
@@ -805,7 +808,7 @@ TEST_F(ParserTest, MissingInput) {
 
 TEST_F(ParserTest, MultipleOutputs) {
   State state;
-  ManifestParser parser(&state, NULL);
+  ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
   string err;
   EXPECT_TRUE(parser.ParseTest("rule cc\n  command = foo\n  depfile = bar\n"
                                "build a.o b.o: cc c.cc\n",
@@ -815,7 +818,7 @@ TEST_F(ParserTest, MultipleOutputs) {
 
 TEST_F(ParserTest, MultipleOutputsWithDeps) {
   State state;
-  ManifestParser parser(&state, NULL);
+  ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
   string err;
   EXPECT_FALSE(parser.ParseTest("rule cc\n  command = foo\n  deps = gcc\n"
                                "build a.o b.o: cc c.cc\n",
@@ -825,9 +828,9 @@ TEST_F(ParserTest, MultipleOutputsWithDeps) {
 }
 
 TEST_F(ParserTest, SubNinja) {
-  files_["test.ninja"] =
+  fs_.Create("test.ninja",
     "var = inner\n"
-    "build $builddir/inner: varref\n";
+    "build $builddir/inner: varref\n");
   ASSERT_NO_FATAL_FAILURE(AssertParse(
 "builddir = some_dir/\n"
 "rule varref\n"
@@ -836,9 +839,9 @@ TEST_F(ParserTest, SubNinja) {
 "build $builddir/outer: varref\n"
 "subninja test.ninja\n"
 "build $builddir/outer2: varref\n"));
-  ASSERT_EQ(1u, files_read_.size());
+  ASSERT_EQ(1u, fs_.files_read_.size());
 
-  EXPECT_EQ("test.ninja", files_read_[0]);
+  EXPECT_EQ("test.ninja", fs_.files_read_[0]);
   EXPECT_TRUE(state.LookupNode("some_dir/outer"));
   // Verify our builddir setting is inherited.
   EXPECT_TRUE(state.LookupNode("some_dir/inner"));
@@ -850,7 +853,7 @@ TEST_F(ParserTest, SubNinja) {
 }
 
 TEST_F(ParserTest, MissingSubNinja) {
-  ManifestParser parser(&state, this);
+  ManifestParser parser(&state, &fs_, kDupeEdgeActionWarn);
   string err;
   EXPECT_FALSE(parser.ParseTest("subninja foo.ninja\n", &err));
   EXPECT_EQ("input:1: loading 'foo.ninja': No such file or directory\n"
@@ -861,9 +864,9 @@ TEST_F(ParserTest, MissingSubNinja) {
 
 TEST_F(ParserTest, DuplicateRuleInDifferentSubninjas) {
   // Test that rules are scoped to subninjas.
-  files_["test.ninja"] = "rule cat\n"
-                         "  command = cat\n";
-  ManifestParser parser(&state, this);
+  fs_.Create("test.ninja", "rule cat\n"
+                         "  command = cat\n");
+  ManifestParser parser(&state, &fs_, kDupeEdgeActionWarn);
   string err;
   EXPECT_TRUE(parser.ParseTest("rule cat\n"
                                 "  command = cat\n"
@@ -872,11 +875,11 @@ TEST_F(ParserTest, DuplicateRuleInDifferentSubninjas) {
 
 TEST_F(ParserTest, DuplicateRuleInDifferentSubninjasWithInclude) {
   // Test that rules are scoped to subninjas even with includes.
-  files_["rules.ninja"] = "rule cat\n"
-                         "  command = cat\n";
-  files_["test.ninja"] = "include rules.ninja\n"
-                         "build x : cat\n";
-  ManifestParser parser(&state, this);
+  fs_.Create("rules.ninja", "rule cat\n"
+                         "  command = cat\n");
+  fs_.Create("test.ninja", "include rules.ninja\n"
+                         "build x : cat\n");
+  ManifestParser parser(&state, &fs_, kDupeEdgeActionWarn);
   string err;
   EXPECT_TRUE(parser.ParseTest("include rules.ninja\n"
                                 "subninja test.ninja\n"
@@ -884,19 +887,19 @@ TEST_F(ParserTest, DuplicateRuleInDifferentSubninjasWithInclude) {
 }
 
 TEST_F(ParserTest, Include) {
-  files_["include.ninja"] = "var = inner\n";
+  fs_.Create("include.ninja", "var = inner\n");
   ASSERT_NO_FATAL_FAILURE(AssertParse(
 "var = outer\n"
 "include include.ninja\n"));
 
-  ASSERT_EQ(1u, files_read_.size());
-  EXPECT_EQ("include.ninja", files_read_[0]);
+  ASSERT_EQ(1u, fs_.files_read_.size());
+  EXPECT_EQ("include.ninja", fs_.files_read_[0]);
   EXPECT_EQ("inner", state.bindings_.LookupVariable("var"));
 }
 
 TEST_F(ParserTest, BrokenInclude) {
-  files_["include.ninja"] = "build\n";
-  ManifestParser parser(&state, this);
+  fs_.Create("include.ninja", "build\n");
+  ManifestParser parser(&state, &fs_, kDupeEdgeActionWarn);
   string err;
   EXPECT_FALSE(parser.ParseTest("include include.ninja\n", &err));
   EXPECT_EQ("include.ninja:1: expected path\n"
@@ -924,6 +927,40 @@ TEST_F(ParserTest, OrderOnly) {
   ASSERT_TRUE(edge->is_order_only(1));
 }
 
+TEST_F(ParserTest, ImplicitOutput) {
+  ASSERT_NO_FATAL_FAILURE(AssertParse(
+"rule cat\n"
+"  command = cat $in > $out\n"
+"build foo | imp: cat bar\n"));
+
+  Edge* edge = state.LookupNode("imp")->in_edge();
+  ASSERT_EQ(edge->outputs_.size(), 2);
+  EXPECT_TRUE(edge->is_implicit_out(1));
+}
+
+TEST_F(ParserTest, ImplicitOutputEmpty) {
+  ASSERT_NO_FATAL_FAILURE(AssertParse(
+"rule cat\n"
+"  command = cat $in > $out\n"
+"build foo | : cat bar\n"));
+
+  Edge* edge = state.LookupNode("foo")->in_edge();
+  ASSERT_EQ(edge->outputs_.size(), 1);
+  EXPECT_FALSE(edge->is_implicit_out(0));
+}
+
+TEST_F(ParserTest, NoExplicitOutput) {
+  ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
+  string err;
+  EXPECT_FALSE(parser.ParseTest(
+"rule cat\n"
+"  command = cat $in > $out\n"
+"build | imp : cat bar\n", &err));
+  ASSERT_EQ("input:3: expected path\n"
+            "build | imp : cat bar\n"
+            "      ^ near here", err);
+}
+
 TEST_F(ParserTest, DefaultDefault) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(
 "rule cat\n  command = cat $in > $out\n"
@@ -976,7 +1013,7 @@ TEST_F(ParserTest, UTF8) {
 
 TEST_F(ParserTest, CRLF) {
   State state;
-  ManifestParser parser(&state, NULL);
+  ManifestParser parser(&state, NULL, kDupeEdgeActionWarn);
   string err;
 
   EXPECT_TRUE(parser.ParseTest("# comment with crlf\r\n", &err));
index a3d963f..a3f1be0 100644 (file)
@@ -22,6 +22,9 @@
 #include "getopt.h"
 #include <direct.h>
 #include <windows.h>
+#elif defined(_AIX)
+#include "getopt.h"
+#include <unistd.h>
 #else
 #include <getopt.h>
 #include <unistd.h>
@@ -226,14 +229,6 @@ int GuessParallelism() {
   }
 }
 
-/// An implementation of ManifestParser::FileReader that actually reads
-/// the file.
-struct RealFileReader : public ManifestParser::FileReader {
-  virtual bool ReadFile(const string& path, string* content, string* err) {
-    return ::ReadFile(path, content, err) == 0;
-  }
-};
-
 /// Rebuild the build manifest, if necessary.
 /// Returns true if the manifest was rebuilt.
 bool NinjaMain::RebuildManifest(const char* input_file, string* err) {
@@ -254,7 +249,7 @@ bool NinjaMain::RebuildManifest(const char* input_file, string* err) {
 
   // Even if the manifest was cleaned by a restat rule, claim that it was
   // rebuilt.  Not doing so can lead to crashes, see
-  // https://github.com/martine/ninja/issues/874
+  // https://github.com/ninja-build/ninja/issues/874
   return builder.Build(err);
 }
 
@@ -698,7 +693,7 @@ int NinjaMain::ToolUrtle(int argc, char** argv) {
     if ('0' <= *p && *p <= '9') {
       count = count*10 + *p - '0';
     } else {
-      for (int i = 0; i < std::max(count, 1); ++i)
+      for (int i = 0; i < max(count, 1); ++i)
         printf("%c", *p);
       count = 0;
     }
@@ -771,9 +766,10 @@ const Tool* ChooseTool(const string& tool_name) {
 bool DebugEnable(const string& name) {
   if (name == "list") {
     printf("debugging modes:\n"
-"  stats    print operation counts/timing info\n"
-"  explain  explain what caused a command to execute\n"
-"  keeprsp  don't delete @response files on success\n"
+"  stats        print operation counts/timing info\n"
+"  explain      explain what caused a command to execute\n"
+"  keepdepfile  don't delete depfiles after they're read by ninja\n"
+"  keeprsp      don't delete @response files on success\n"
 #ifdef _WIN32
 "  nostatcache  don't batch stat() calls per directory and cache them\n"
 #endif
@@ -785,6 +781,9 @@ bool DebugEnable(const string& name) {
   } else if (name == "explain") {
     g_explaining = true;
     return true;
+  } else if (name == "keepdepfile") {
+    g_keep_depfile = true;
+    return true;
   } else if (name == "keeprsp") {
     g_keep_rsp = true;
     return true;
@@ -793,8 +792,9 @@ bool DebugEnable(const string& name) {
     return true;
   } else {
     const char* suggestion =
-        SpellcheckString(name.c_str(), "stats", "explain", "keeprsp",
-        "nostatcache", NULL);
+        SpellcheckString(name.c_str(),
+                         "stats", "explain", "keepdepfile", "keeprsp",
+                         "nostatcache", NULL);
     if (suggestion) {
       Error("unknown debug setting '%s', did you mean '%s'?",
             name.c_str(), suggestion);
@@ -1109,9 +1109,10 @@ int real_main(int argc, char** argv) {
   for (int cycle = 1; cycle <= kCycleLimit; ++cycle) {
     NinjaMain ninja(ninja_command, config);
 
-    RealFileReader file_reader;
-    ManifestParser parser(&ninja.state_, &file_reader,
-                          options.dupe_edges_should_err);
+    ManifestParser parser(&ninja.state_, &ninja.disk_interface_,
+                          options.dupe_edges_should_err
+                              ? kDupeEdgeActionError
+                              : kDupeEdgeActionWarn);
     string err;
     if (!parser.Load(options.input_file, &err)) {
       Error("%s", err.c_str());
@@ -1132,6 +1133,10 @@ int real_main(int argc, char** argv) {
 
     // Attempt to rebuild the manifest before building anything else
     if (ninja.RebuildManifest(options.input_file, &err)) {
+      // In dry_run mode the regeneration will succeed without changing the
+      // manifest forever. Better to return immediately.
+      if (config.dry_run)
+        return 0;
       // Start the build over with the new manifest.
       continue;
     } else if (!err.empty()) {
@@ -1156,7 +1161,7 @@ int main(int argc, char** argv) {
 #if defined(_MSC_VER)
   // Set a handler to catch crashes not caught by the __try..__except
   // block (e.g. an exception in a stack-unwind-block).
-  std::set_terminate(TerminateHandler);
+  set_terminate(TerminateHandler);
   __try {
     // Running inside __try ... __except suppresses any Windows error
     // dialogs for errors such as bad_alloc.
index 54d8784..11087b6 100644 (file)
@@ -17,6 +17,9 @@
 
 #ifdef _WIN32
 #include "getopt.h"
+#elif defined(_AIX)
+#include "getopt.h"
+#include <unistd.h>
 #else
 #include <getopt.h>
 #endif
index f3baec2..2ddc709 100644 (file)
@@ -64,6 +64,8 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
         break;
       if (sigaction(SIGTERM, &set->old_term_act_, 0) < 0)
         break;
+      if (sigaction(SIGHUP, &set->old_hup_act_, 0) < 0)
+        break;
       if (sigprocmask(SIG_SETMASK, &set->old_mask_, 0) < 0)
         break;
 
@@ -136,7 +138,8 @@ ExitStatus Subprocess::Finish() {
     if (exit == 0)
       return ExitSuccess;
   } else if (WIFSIGNALED(status)) {
-    if (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGTERM)
+    if (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGTERM
+        || WTERMSIG(status) == SIGHUP)
       return ExitInterrupted;
   }
   return ExitFailure;
@@ -167,6 +170,8 @@ void SubprocessSet::HandlePendingInterruption() {
     interrupted_ = SIGINT;
   else if (sigismember(&pending, SIGTERM))
     interrupted_ = SIGTERM;
+  else if (sigismember(&pending, SIGHUP))
+    interrupted_ = SIGHUP;
 }
 
 SubprocessSet::SubprocessSet() {
@@ -174,6 +179,7 @@ SubprocessSet::SubprocessSet() {
   sigemptyset(&set);
   sigaddset(&set, SIGINT);
   sigaddset(&set, SIGTERM);
+  sigaddset(&set, SIGHUP);
   if (sigprocmask(SIG_BLOCK, &set, &old_mask_) < 0)
     Fatal("sigprocmask: %s", strerror(errno));
 
@@ -184,6 +190,8 @@ SubprocessSet::SubprocessSet() {
     Fatal("sigaction: %s", strerror(errno));
   if (sigaction(SIGTERM, &act, &old_term_act_) < 0)
     Fatal("sigaction: %s", strerror(errno));
+  if (sigaction(SIGHUP, &act, &old_hup_act_) < 0)
+    Fatal("sigaction: %s", strerror(errno));
 }
 
 SubprocessSet::~SubprocessSet() {
@@ -193,6 +201,8 @@ SubprocessSet::~SubprocessSet() {
     Fatal("sigaction: %s", strerror(errno));
   if (sigaction(SIGTERM, &old_term_act_, 0) < 0)
     Fatal("sigaction: %s", strerror(errno));
+  if (sigaction(SIGHUP, &old_hup_act_, 0) < 0)
+    Fatal("sigaction: %s", strerror(errno));
   if (sigprocmask(SIG_SETMASK, &old_mask_, 0) < 0)
     Fatal("sigprocmask: %s", strerror(errno));
 }
index fad66e8..4bab719 100644 (file)
@@ -255,7 +255,7 @@ bool SubprocessSet::DoWork() {
 
   if (subproc->Done()) {
     vector<Subprocess*>::iterator end =
-        std::remove(running_.begin(), running_.end(), subproc);
+        remove(running_.begin(), running_.end(), subproc);
     if (running_.end() != end) {
       finished_.push(subproc);
       running_.resize(end - running_.begin());
index a001fc9..51f40b2 100644 (file)
@@ -98,6 +98,7 @@ struct SubprocessSet {
 
   struct sigaction old_int_act_;
   struct sigaction old_term_act_;
+  struct sigaction old_hup_act_;
   sigset_t old_mask_;
 #endif
 };
index 07cc52f..2fe4bce 100644 (file)
@@ -122,6 +122,30 @@ TEST_F(SubprocessTest, InterruptParentWithSigTerm) {
   ASSERT_FALSE("We should have been interrupted");
 }
 
+TEST_F(SubprocessTest, InterruptChildWithSigHup) {
+  Subprocess* subproc = subprocs_.Add("kill -HUP $$");
+  ASSERT_NE((Subprocess *) 0, subproc);
+
+  while (!subproc->Done()) {
+    subprocs_.DoWork();
+  }
+
+  EXPECT_EQ(ExitInterrupted, subproc->Finish());
+}
+
+TEST_F(SubprocessTest, InterruptParentWithSigHup) {
+  Subprocess* subproc = subprocs_.Add("kill -HUP $PPID ; sleep 1");
+  ASSERT_NE((Subprocess *) 0, subproc);
+
+  while (!subproc->Done()) {
+    bool interrupted = subprocs_.DoWork();
+    if (interrupted)
+      return;
+  }
+
+  ASSERT_FALSE("We should have been interrupted");
+}
+
 // A shell command to check if the current process is connected to a terminal.
 // This is different from having stdin/stdout/stderr be a terminal. (For
 // instance consider the command "yes < /dev/null > /dev/null 2>&1".
@@ -135,8 +159,8 @@ TEST_F(SubprocessTest, Console) {
     // Test that stdin, stdout and stderr are a terminal.
     // Also check that the current process is connected to a terminal.
     Subprocess* subproc =
-        subprocs_.Add(std::string("test -t 0 -a -t 1 -a -t 2 && ") +
-                          std::string(kIsConnectedToTerminal),
+        subprocs_.Add(string("test -t 0 -a -t 1 -a -t 2 && ") +
+                      string(kIsConnectedToTerminal),
                       /*use_console=*/true);
     ASSERT_NE((Subprocess*)0, subproc);
 
index aed8db7..53bfc48 100644 (file)
@@ -95,7 +95,7 @@ Node* StateTestWithBuiltinRules::GetNode(const string& path) {
 }
 
 void AssertParse(State* state, const char* input) {
-  ManifestParser parser(state, NULL);
+  ManifestParser parser(state, NULL, kDupeEdgeActionWarn);
   string err;
   EXPECT_TRUE(parser.ParseTest(input, &err));
   ASSERT_EQ("", err);
@@ -115,7 +115,7 @@ void VerifyGraph(const State& state) {
     for (vector<Node*>::const_iterator in_node = (*e)->inputs_.begin();
          in_node != (*e)->inputs_.end(); ++in_node) {
       const vector<Edge*>& out_edges = (*in_node)->out_edges();
-      EXPECT_NE(std::find(out_edges.begin(), out_edges.end(), *e),
+      EXPECT_NE(find(out_edges.begin(), out_edges.end(), *e),
                 out_edges.end());
     }
     // Check that the edge's outputs have the edge as in-edge.
@@ -164,12 +164,17 @@ bool VirtualFileSystem::MakeDir(const string& path) {
   return true;  // success
 }
 
-string VirtualFileSystem::ReadFile(const string& path, string* err) {
+FileReader::Status VirtualFileSystem::ReadFile(const string& path,
+                                               string* contents,
+                                               string* err) {
   files_read_.push_back(path);
   FileMap::iterator i = files_.find(path);
-  if (i != files_.end())
-    return i->second.contents;
-  return "";
+  if (i != files_.end()) {
+    *contents = i->second.contents;
+    return Okay;
+  }
+  *err = strerror(ENOENT);
+  return NotFound;
 }
 
 int VirtualFileSystem::RemoveFile(const string& path) {
index 156e68a..488c243 100644 (file)
@@ -145,7 +145,7 @@ struct VirtualFileSystem : public DiskInterface {
   virtual TimeStamp Stat(const string& path, string* err) const;
   virtual bool WriteFile(const string& path, const string& contents);
   virtual bool MakeDir(const string& path);
-  virtual string ReadFile(const string& path, string* err);
+  virtual Status ReadFile(const string& path, string* contents, string* err);
   virtual int RemoveFile(const string& path);
 
   /// An entry for a single in-memory file.
index aa47f2f..e31fd1f 100644 (file)
@@ -45,6 +45,8 @@
 #elif defined(__SVR4) && defined(__sun)
 #include <unistd.h>
 #include <sys/loadavg.h>
+#elif defined(_AIX)
+#include <libperfstat.h>
 #elif defined(linux) || defined(__GLIBC__)
 #include <sys/sysinfo.h>
 #endif
@@ -224,8 +226,8 @@ bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits,
   }
 
   if (dst == start) {
-    *err = "path canonicalizes to the empty path";
-    return false;
+    *dst++ = '.';
+    *dst++ = '\0';
   }
 
   *len = dst - start - 1;
@@ -573,6 +575,16 @@ double GetLoadAverage() {
 
   return posix_compatible_load;
 }
+#elif defined(_AIX)
+double GetLoadAverage() {
+  perfstat_cpu_total_t cpu_stats;
+  if (perfstat_cpu_total(NULL, &cpu_stats, sizeof(cpu_stats), 1) < 0) {
+    return -0.0f;
+  }
+
+  // Calculation taken from comment in libperfstats.h
+  return double(cpu_stats.loadavg[0]) / double(1 << SBITS);
+}
 #else
 double GetLoadAverage() {
   double loadavg[3] = { 0.0f, 0.0f, 0.0f };
index 8ca7f56..33a4107 100644 (file)
@@ -91,6 +91,22 @@ TEST(CanonicalizePath, PathSamples) {
   path = "/";
   EXPECT_TRUE(CanonicalizePath(&path, &err));
   EXPECT_EQ("", path);
+
+  path = "/foo/..";
+  EXPECT_TRUE(CanonicalizePath(&path, &err));
+  EXPECT_EQ("", path);
+
+  path = ".";
+  EXPECT_TRUE(CanonicalizePath(&path, &err));
+  EXPECT_EQ(".", path);
+
+  path = "./.";
+  EXPECT_TRUE(CanonicalizePath(&path, &err));
+  EXPECT_EQ(".", path);
+
+  path = "foo/..";
+  EXPECT_TRUE(CanonicalizePath(&path, &err));
+  EXPECT_EQ(".", path);
 }
 
 #ifdef _WIN32
@@ -288,22 +304,6 @@ TEST(CanonicalizePath, TooManyComponents) {
 }
 #endif
 
-TEST(CanonicalizePath, EmptyResult) {
-  string path;
-  string err;
-
-  EXPECT_FALSE(CanonicalizePath(&path, &err));
-  EXPECT_EQ("empty path", err);
-
-  path = ".";
-  EXPECT_FALSE(CanonicalizePath(&path, &err));
-  EXPECT_EQ("path canonicalizes to the empty path", err);
-
-  path = "./.";
-  EXPECT_FALSE(CanonicalizePath(&path, &err));
-  EXPECT_EQ("path canonicalizes to the empty path", err);
-}
-
 TEST(CanonicalizePath, UpDir) {
   string path, err;
   path = "../../foo/bar.h";