MCPcopy Create free account
hub / github.com/cztomczak/cefpython / smart_compile

Function smart_compile

tools/build_cpp_projects.py:220–287  ·  view source on GitHub ↗

Smart compile will only recompile files that need recompiling.

(compiler, macros, extra_args, sources, output_dir)

Source from the content-addressed store, hash-verified

218
219
220def smart_compile(compiler, macros, extra_args, sources, output_dir):
221 """Smart compile will only recompile files that need recompiling."""
222 if not os.path.exists(output_dir):
223 os.makedirs(output_dir)
224 any_changed = False
225 objects = list()
226 for source_file in sources:
227 header_file = source_file.replace(".cpp", ".h")
228 header_file = header_file.replace(".mm", ".h")
229 assert header_file.endswith(".h")
230 if not os.path.isfile(header_file):
231 header_file = None
232 obj_file = os.path.join(output_dir, os.path.basename(source_file))
233 obj_file = obj_file.replace(".cpp", OBJ_EXT)
234 obj_file = obj_file.replace(".mm", OBJ_EXT)
235 assert obj_file.endswith(OBJ_EXT)
236 if os.path.exists(obj_file):
237 # Recompile source file if its time is newer than obj file,
238 # Also check its header file time. Also check times of any
239 # possible includes: cefpython_fixed.h, src/common/ files.
240 obj_time = os.path.getmtime(obj_file)
241 source_time = os.path.getmtime(source_file)
242 header_time = os.path.getmtime(header_file) if header_file else 0
243 cefpython_h_fixed_time = os.path.getmtime(
244 CEFPYTHON_API_HFILE_FIXED)
245 common_files_time = get_directory_mtime(os.path.join(SRC_DIR,
246 "common"))
247 changed = ((source_time > obj_time)
248 or (header_time > obj_time)
249 or (cefpython_h_fixed_time > obj_time)
250 or (common_files_time > obj_time))
251 else:
252 changed = True
253 if changed:
254 any_changed = True
255 else:
256 objects.append(obj_file)
257 if any_changed:
258 # If any has changed must recompile all given sources (for a library
259 # or executable). This is because we don't know which sources include
260 # which header files so must recompile everything.
261 objects = list()
262 # Compile each source file separately so that when compiling
263 # source files from different directories, object files are
264 # all put in the same output_directory. Otherwise distutils
265 # will create lots of subdirs in output_directory.
266 macros = macros_as_tuples(macros)
267 common_dir = os.path.join(SRC_DIR, "common")
268 original_dir = os.getcwd()
269 for source_file in sources:
270 source_dir = os.path.dirname(source_file)
271 os.chdir(source_dir)
272 source_basename = os.path.basename(source_file)
273 oneobj = compiler.compile([source_basename],
274 output_dir=output_dir,
275 macros=macros,
276 # TODO include dirs for Linux/Mac
277 include_dirs=[SRC_DIR,

Callers 2

build_libraryFunction · 0.85

Calls 3

get_directory_mtimeFunction · 0.85
macros_as_tuplesFunction · 0.85
get_python_include_pathFunction · 0.85

Tested by

no test coverage detected