Check mtime to avoid recreating existing so
This commit is contained in:
parent
353a97c49d
commit
be221f68d5
1 changed files with 17 additions and 4 deletions
|
@ -79,6 +79,17 @@ def gen_eh_elf(obj_path, out_dir=None):
|
||||||
print("> {}...".format(os.path.basename(obj_path)))
|
print("> {}...".format(os.path.basename(obj_path)))
|
||||||
|
|
||||||
out_base_name = os.path.basename(obj_path) + '.eh_elf'
|
out_base_name = os.path.basename(obj_path) + '.eh_elf'
|
||||||
|
out_so_path = os.path.join(out_dir, (out_base_name + '.so'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
so_mtime = os.path.getmtime(out_so_path)
|
||||||
|
obj_mtime = os.path.getmtime(obj_path)
|
||||||
|
|
||||||
|
if obj_mtime < so_mtime:
|
||||||
|
return # The object is recent enough, no need to recreate it
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as compile_dir:
|
with tempfile.TemporaryDirectory() as compile_dir:
|
||||||
# Generate the C source file
|
# Generate the C source file
|
||||||
|
@ -89,14 +100,16 @@ def gen_eh_elf(obj_path, out_dir=None):
|
||||||
# Compile it into a .o
|
# Compile it into a .o
|
||||||
print("\tCompiling into .o…")
|
print("\tCompiling into .o…")
|
||||||
o_path = os.path.join(compile_dir, (out_base_name + '.o'))
|
o_path = os.path.join(compile_dir, (out_base_name + '.o'))
|
||||||
if subprocess.call([CXX_BIN, '-o', o_path, '-c', c_path,
|
call_rc = subprocess.call(
|
||||||
'-O3', '-fPIC']) != 0:
|
[CXX_BIN, '-o', o_path, '-c', c_path, '-O3', '-fPIC'])
|
||||||
|
if call_rc != 0:
|
||||||
raise Exception("Failed to compile to a .o file")
|
raise Exception("Failed to compile to a .o file")
|
||||||
|
|
||||||
# Compile it into a .so
|
# Compile it into a .so
|
||||||
print("\tCompiling into .so…")
|
print("\tCompiling into .so…")
|
||||||
so_path = os.path.join(out_dir, (out_base_name + '.so'))
|
call_rc = subprocess.call(
|
||||||
if subprocess.call([CXX_BIN, '-o', so_path, '-shared', o_path]) != 0:
|
[CXX_BIN, '-o', out_so_path, '-shared', o_path])
|
||||||
|
if call_rc != 0:
|
||||||
raise Exception("Failed to compile to a .so file")
|
raise Exception("Failed to compile to a .so file")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue