MCPcopy Index your code
hub / github.com/nodejs/node / GetNinjaOutputDirectory

Function GetNinjaOutputDirectory

deps/v8/tools/vim/ninja_output.py:17–65  ·  view source on GitHub ↗

Returns / /(Release|Debug| ). The configuration chosen is the one most recently generated/built, but can be overriden via the parameter. Detects a custom output_dir specified by GYP_GENERATOR_FLAGS.

(v8_root, configuration=None)

Source from the content-addressed store, hash-verified

15
16
17def GetNinjaOutputDirectory(v8_root, configuration=None):
18 """Returns <v8_root>/<output_dir>/(Release|Debug|<other>).
19
20 The configuration chosen is the one most recently generated/built, but can be
21 overriden via the <configuration> parameter. Detects a custom output_dir
22 specified by GYP_GENERATOR_FLAGS."""
23
24 output_dirs = []
25
26 generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ')
27 for flag in generator_flags:
28 name_value = flag.split('=', 1)
29 if (len(name_value) == 2 and name_value[0] == 'output_dir' and
30 os.path.isdir(os.path.join(v8_root, name_value[1]))):
31 output_dirs = [name_value[1]]
32
33 if configuration:
34 output_dir = 'out' if len(output_dirs) == 0 else output_dirs[-1]
35 return os.path.join(os.path.join(v8_root, output_dir), configuration)
36
37 if not output_dirs:
38 for f in os.listdir(v8_root):
39 if re.match(r'out(\b|_)', f):
40 if os.path.isdir(os.path.join(v8_root, f)):
41 output_dirs.append(f)
42
43 def generate_paths():
44 for out_dir in output_dirs:
45 out_path = os.path.join(v8_root, out_dir)
46 for config in os.listdir(out_path):
47 path = os.path.join(out_path, config)
48 if os.path.exists(os.path.join(path, 'build.ninja')):
49 yield path
50
51 def approx_directory_mtime(path):
52 # This is a heuristic; don't recurse into subdirectories.
53 paths = [path] + [os.path.join(path, f) for f in os.listdir(path)]
54 return max(filter(None, [safe_mtime(p) for p in paths]))
55
56 def safe_mtime(path):
57 try:
58 return os.path.getmtime(path)
59 except OSError:
60 return None
61
62 try:
63 return max(generate_paths(), key=approx_directory_mtime)
64 except ValueError:
65 raise RuntimeError('Unable to find a valid ninja output directory.')
66
67
68if __name__ == '__main__':

Callers 2

ninja_output.pyFile · 0.85

Calls 6

generate_pathsFunction · 0.85
matchMethod · 0.65
maxFunction · 0.50
splitMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…