Home | History | Annotate | Download | only in ninja
      1 # Copyright 2015 the V8 project authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 import os
      7 import os.path
      8 
      9 
     10 def GetNinjaOutputDirectory(v8_root, configuration=None):
     11   """Returns <v8_root>/<output_dir>/(Release|Debug).
     12 
     13   The configuration chosen is the one most recently generated/built, but can be
     14   overriden via the <configuration> parameter. Detects a custom output_dir
     15   specified by GYP_GENERATOR_FLAGS."""
     16 
     17   output_dir = 'out'
     18   generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ')
     19   for flag in generator_flags:
     20     name_value = flag.split('=', 1)
     21     if len(name_value) == 2 and name_value[0] == 'output_dir':
     22       output_dir = name_value[1]
     23 
     24   root = os.path.join(v8_root, output_dir)
     25   if configuration:
     26     return os.path.join(root, configuration)
     27 
     28   debug_path = os.path.join(root, 'Debug')
     29   release_path = os.path.join(root, 'Release')
     30 
     31   def is_release_newer(test_path):
     32     try:
     33       debug_mtime = os.path.getmtime(os.path.join(debug_path, test_path))
     34     except os.error:
     35       debug_mtime = 0
     36     try:
     37       rel_mtime = os.path.getmtime(os.path.join(release_path, test_path))
     38     except os.error:
     39       rel_mtime = 0
     40     return rel_mtime >= debug_mtime
     41 
     42   if is_release_newer('.ninja_log') or is_release_newer('.ninja_deps'):
     43     return release_path
     44   return debug_path
     45