From 8f6e1bab09cd5a49aaf7cc668219475e0aa30e22 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 13 Mar 2019 14:50:18 -0400 Subject: [PATCH] Automatically rebuild packages if any patches or extra files change --- Makefile | 4 +++- pyodide_build/buildall.py | 4 +--- pyodide_build/buildpkg.py | 31 ++++++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 84820d9ea..2f6dcf998 100644 --- a/Makefile +++ b/Makefile @@ -221,8 +221,10 @@ $(CLAPACK): $(CPYTHONLIB) make -C CLAPACK -build/packages.json: $(CPYTHONLIB) $(CLAPACK) +build/packages.json: FORCE make -C packages emsdk/emsdk/.complete: make -C emsdk + +FORCE: diff --git a/pyodide_build/buildall.py b/pyodide_build/buildall.py index 913bb9625..b64a1b161 100755 --- a/pyodide_build/buildall.py +++ b/pyodide_build/buildall.py @@ -19,9 +19,7 @@ def build_package(pkgname, dependencies, packagesdir, outputdir, args): # Make sure all of the package's requirements are built first for req in reqs: build_package(req, dependencies, packagesdir, outputdir, args) - if not (packagesdir / pkgname / 'build' / '.packaged').is_file(): - print("BUILDING PACKAGE: " + pkgname) - buildpkg.build_package(packagesdir / pkgname / 'meta.yaml', args) + buildpkg.build_package(packagesdir / pkgname / 'meta.yaml', args) shutil.copyfile( packagesdir / pkgname / 'build' / (pkgname + '.data'), outputdir / (pkgname + '.data')) diff --git a/pyodide_build/buildpkg.py b/pyodide_build/buildpkg.py index 63421a1ba..c57792123 100755 --- a/pyodide_build/buildpkg.py +++ b/pyodide_build/buildpkg.py @@ -147,16 +147,41 @@ def package_files(buildpath, srcpath, pkg, args): fd.write(b'\n') +def needs_rebuild(pkg, path, buildpath): + """ + Determines if a package needs a rebuild because its meta.yaml, patches, or + sources are newer than the `.packaged` thunk. + """ + packaged_token = buildpath / '.packaged' + if not packaged_token.is_file(): + return True + + package_time = packaged_token.stat().st_mtime + + def source_files(): + yield path + yield from pkg.get('source', {}).get('patches', []) + yield from (x[0] for x in pkg.get('source', {}).get('extras', [])) + + for source_file in source_files(): + source_file = Path(source_file) + if source_file.stat().st_mtime > package_time: + return True + + def build_package(path, args): pkg = common.parse_package(path) packagedir = pkg['package']['name'] + '-' + pkg['package']['version'] dirpath = path.parent orig_path = Path.cwd() os.chdir(dirpath) + buildpath = dirpath / 'build' try: - buildpath = dirpath / 'build' - if not buildpath.resolve().is_dir(): - os.makedirs(buildpath) + if not needs_rebuild(pkg, path, buildpath): + return + if buildpath.resolve().is_dir(): + shutil.rmtree(buildpath) + os.makedirs(buildpath) srcpath = download_and_extract(buildpath, packagedir, pkg, args) patch(path, srcpath, pkg, args) compile(path, srcpath, pkg, args)