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

Function GetClangCommandFromNinjaForFilename

deps/v8/.ycm_extra_conf.py:76–162  ·  view source on GitHub ↗

Returns the command line to build |filename|. Asks ninja how it would build the source file. If the specified file is a header, tries to find its companion source file first. Args: v8_root: (String) Path to v8/. filename: (String) Path to source file being edited. Returns: (Li

(v8_root, filename)

Source from the content-addressed store, hash-verified

74
75
76def GetClangCommandFromNinjaForFilename(v8_root, filename):
77 """Returns the command line to build |filename|.
78
79 Asks ninja how it would build the source file. If the specified file is a
80 header, tries to find its companion source file first.
81
82 Args:
83 v8_root: (String) Path to v8/.
84 filename: (String) Path to source file being edited.
85
86 Returns:
87 (List of Strings) Command line arguments for clang.
88 """
89 if not v8_root:
90 return []
91
92 # Generally, everyone benefits from including V8's root, because all of
93 # V8's includes are relative to that.
94 v8_flags = ['-I' + os.path.join(v8_root)]
95
96 # Version of Clang used to compile V8 can be newer then version of
97 # libclang that YCM uses for completion. So it's possible that YCM's libclang
98 # doesn't know about some used warning options, which causes compilation
99 # warnings (and errors, because of '-Werror');
100 v8_flags.append('-Wno-unknown-warning-option')
101
102 # Header files can't be built. Instead, try to match a header file to its
103 # corresponding source file.
104 if filename.endswith('.h'):
105 base = filename[:-6] if filename.endswith('-inl.h') else filename[:-2]
106 for alternate in [base + e for e in ['.cc', '.cpp']]:
107 if os.path.exists(alternate):
108 filename = alternate
109 break
110 else:
111 # If this is a standalone .h file with no source, we ask ninja for the
112 # compile flags of some generic cc file ('src/utils/utils.cc'). This
113 # should contain most/all of the interesting flags for other targets too.
114 filename = os.path.join(v8_root, 'src', 'utils', 'utils.cc')
115
116 sys.path.append(os.path.join(v8_root, 'tools', 'vim'))
117 from ninja_output import GetNinjaOutputDirectory
118 out_dir = os.path.realpath(GetNinjaOutputDirectory(v8_root))
119
120 # Ninja needs the path to the source file relative to the output build
121 # directory.
122 rel_filename = os.path.relpath(os.path.realpath(filename), out_dir)
123
124 # Ask ninja how it would build our source file.
125 p = subprocess.Popen(['ninja', '-v', '-C', out_dir, '-t',
126 'commands', rel_filename + '^'],
127 stdout=subprocess.PIPE)
128 stdout, stderr = p.communicate()
129 if p.returncode:
130 return v8_flags
131
132 # Ninja might execute several commands to build something. We want the last
133 # clang command.

Callers 1

FlagsForFileFunction · 0.85

Calls 9

GetNinjaOutputDirectoryFunction · 0.90
MakeIncludePathAbsoluteFunction · 0.85
decodeMethod · 0.65
joinMethod · 0.45
appendMethod · 0.45
existsMethod · 0.45
realpathMethod · 0.45
splitlinesMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…