Auto-update in-tree bindings

This commit is contained in:
Xidorn Quan 2016-12-15 18:51:54 +11:00
parent fde9ac1768
commit af487f5730
2 changed files with 22 additions and 7 deletions

View file

@ -24,7 +24,7 @@ from mach.decorators import (
Command, Command,
) )
from servo.command_base import CommandBase, cd, call, BIN_SUFFIX, host_triple from servo.command_base import CommandBase, cd, call, BIN_SUFFIX, host_triple, find_dep_path_newest
def format_duration(seconds): def format_duration(seconds):
@ -401,7 +401,8 @@ class MachCommands(CommandBase):
self.ensure_bootstrapped() self.ensure_bootstrapped()
env = self.build_env(is_build=True) env = self.build_env(is_build=True)
env["CARGO_TARGET_DIR"] = path.join(self.context.topdir, "target", "geckolib").encode("UTF-8") geckolib_build_path = path.join(self.context.topdir, "target", "geckolib").encode("UTF-8")
env["CARGO_TARGET_DIR"] = geckolib_build_path
ret = None ret = None
opts = [] opts = []
@ -425,6 +426,15 @@ class MachCommands(CommandBase):
print("GeckoLib build completed in %s" % format_duration(elapsed)) print("GeckoLib build completed in %s" % format_duration(elapsed))
if with_gecko is not None and ret == 0:
print("Copying binding files to style/gecko_bindings...")
build_path = path.join(geckolib_build_path, "release" if release else "debug", "")
target_style_path = find_dep_path_newest("style", build_path)
out_gecko_path = path.join(target_style_path, "out", "gecko")
bindings_path = path.join(self.context.topdir, "components", "style", "gecko_bindings")
for f in ["bindings.rs", "structs_debug.rs", "structs_release.rs"]:
shutil.copy(path.join(out_gecko_path, f), bindings_path)
return ret return ret
@Command('clean', @Command('clean',

View file

@ -50,12 +50,17 @@ def setlocale(name):
def find_dep_path_newest(package, bin_path): def find_dep_path_newest(package, bin_path):
deps_path = path.join(path.split(bin_path)[0], "build") deps_path = path.join(path.split(bin_path)[0], "build")
candidates = []
with cd(deps_path): with cd(deps_path):
candidates = glob(package + '-*') for c in glob(package + '-*'):
candidates = (path.join(deps_path, c) for c in candidates) candidate_path = path.join(deps_path, c)
candidate_times = sorted(((path.getmtime(c), c) for c in candidates), reverse=True) candidate_output = path.join(candidate_path, "output")
if len(candidate_times) > 0: if path.exists(candidate_output):
return candidate_times[0][1] candidates.append((path.getmtime(candidate_output), candidate_path))
candidates.sort(reverse=True)
if candidates:
_, candidate_path = candidates[0]
return candidate_path
return None return None