Merge pull request #917 from pinotree/rlimit
[platform/upstream/ninja.git] / configure.py
index 3cd1e82..661662f 100755 (executable)
@@ -106,8 +106,9 @@ class Bootstrap:
     It also proxies all calls to an underlying ninja_syntax.Writer, to
     behave like non-bootstrap mode.
     """
-    def __init__(self, writer):
+    def __init__(self, writer, verbose=False):
         self.writer = writer
+        self.verbose = verbose
         # Map of variable name => expanded variable value.
         self.vars = {}
         # Map of rule name => dict of rule attributes.
@@ -163,6 +164,8 @@ class Bootstrap:
     def _run_command(self, cmdline):
         """Run a subcommand, quietly.  Prints the full command on error."""
         try:
+            if self.verbose:
+                print(cmdline)
             subprocess.check_call(cmdline, shell=True)
         except subprocess.CalledProcessError:
             print('when running: ', cmdline)
@@ -173,6 +176,8 @@ parser = OptionParser()
 profilers = ['gmon', 'pprof']
 parser.add_option('--bootstrap', action='store_true',
                   help='bootstrap a ninja binary from nothing')
+parser.add_option('--verbose', action='store_true',
+                  help='enable verbose build')
 parser.add_option('--platform',
                   help='target platform (' +
                        '/'.join(Platform.known_platforms()) + ')',
@@ -217,7 +222,7 @@ if options.bootstrap:
     # Wrap ninja_writer with the Bootstrapper, which also executes the
     # commands.
     print('bootstrapping ninja...')
-    n = Bootstrap(n)
+    n = Bootstrap(n, verbose=options.verbose)
 
 n.comment('This file is used to build ninja itself.')
 n.comment('It is generated by ' + os.path.basename(__file__) + '.')
@@ -279,6 +284,8 @@ if platform.is_msvc():
               '/wd4512', '/wd4800', '/wd4702', '/wd4819',
               # Disable warnings about passing "this" during initialization.
               '/wd4355',
+              # Disable warnings about ignored typedef in DbgHelp.h
+              '/wd4091',
               '/GR-',  # Disable RTTI.
               # Disable size_t -> int truncation warning.
               # We never have strings or arrays larger than 2**31.
@@ -310,8 +317,15 @@ else:
         cflags.remove('-fno-rtti')  # Needed for above pedanticness.
     else:
         cflags += ['-O2', '-DNDEBUG']
-    if 'clang' in os.path.basename(CXX):
-        cflags += ['-fcolor-diagnostics']
+    try:
+        proc = subprocess.Popen(
+            [CXX, '-fdiagnostics-color', '-c', '-x', 'c++', '/dev/null'],
+            stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT)
+        proc.wait()
+        if proc.returncode == 0:
+            cflags += ['-fdiagnostics-color']
+    except:
+        pass
     if platform.is_mingw():
         cflags += ['-D_WIN32_WINNT=0x0501']
     ldflags = ['-L$builddir']
@@ -602,6 +616,10 @@ 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():
@@ -609,6 +627,6 @@ if options.bootstrap:
         if os.path.exists(bootstrap_exe):
             os.unlink(bootstrap_exe)
         os.rename('ninja.exe', bootstrap_exe)
-        subprocess.check_call('ninja.bootstrap.exe', shell=True)
+        subprocess.check_call('ninja.bootstrap.exe%s' % verbose, shell=True)
     else:
-        subprocess.check_call('./ninja', shell=True)
+        subprocess.check_call('./ninja%s' % verbose, shell=True)