pyodide/tools/buildall

86 lines
2.9 KiB
Plaintext
Raw Normal View History

2018-06-20 18:54:47 +00:00
#!/usr/bin/env python3
"""
Build all of the packages in a given directory.
"""
2018-06-20 18:54:47 +00:00
import argparse
import json
2018-08-03 16:48:22 +00:00
from pathlib import Path
2018-06-20 18:54:47 +00:00
import shutil
import common
import buildpkg
2018-08-06 14:01:28 +00:00
def build_package(pkgname, dependencies, packagesdir, outputdir, args):
reqs = dependencies[pkgname]
# Make sure all of the package's requirements are built first
2018-06-20 18:54:47 +00:00
for req in reqs:
2018-08-06 14:01:28 +00:00
build_package(req, dependencies, packagesdir, outputdir, args)
2018-08-03 16:48:22 +00:00
if not (packagesdir / pkgname / 'build' / '.packaged').is_file():
2018-06-20 18:54:47 +00:00
print("BUILDING PACKAGE: " + pkgname)
2018-08-03 16:48:22 +00:00
buildpkg.build_package(packagesdir / pkgname / 'meta.yaml', args)
2018-06-20 18:54:47 +00:00
shutil.copyfile(
2018-08-03 16:48:22 +00:00
packagesdir / pkgname / 'build' / (pkgname + '.data'),
outputdir / (pkgname + '.data'))
2018-06-20 18:54:47 +00:00
shutil.copyfile(
2018-08-03 16:48:22 +00:00
packagesdir / pkgname / 'build' / (pkgname + '.js'),
outputdir / (pkgname + '.js'))
2018-06-20 18:54:47 +00:00
2018-08-06 14:01:28 +00:00
def build_packages(packagesdir, outputdir, args):
# We have to build the packages in the correct order (dependencies first),
# so first load in all of the package metadata and build a dependency map.
2018-06-20 18:54:47 +00:00
dependencies = {}
2018-08-03 16:48:22 +00:00
for pkgdir in packagesdir.iterdir():
pkgpath = pkgdir / 'meta.yaml'
if pkgdir.is_dir() and pkgpath.is_file():
2018-06-20 18:54:47 +00:00
pkg = common.parse_package(pkgpath)
name = pkg['package']['name']
reqs = pkg.get('requirements', {}).get('run', [])
dependencies[name] = reqs
for pkgname in dependencies.keys():
2018-08-06 14:01:28 +00:00
build_package(pkgname, dependencies, packagesdir, outputdir, args)
2018-06-20 18:54:47 +00:00
# This is done last so the main Makefile can use it as a completion token
2018-08-03 16:48:22 +00:00
with open(outputdir / 'packages.json', 'w') as fd:
2018-06-20 18:54:47 +00:00
json.dump({'dependencies': dependencies}, fd)
def parse_args():
parser = argparse.ArgumentParser(
"Build all of the packages in a given directory")
parser.add_argument(
'dir', type=str, nargs=1,
help='Input directory containing a tree of package definitions')
parser.add_argument(
'output', type=str, nargs=1,
help='Output directory in which to put all built packages')
2018-06-20 19:05:13 +00:00
parser.add_argument(
2018-06-22 18:49:52 +00:00
'--cflags', type=str, nargs='?', default=common.DEFAULTCFLAGS,
help='Extra compiling flags')
2018-06-20 19:05:13 +00:00
parser.add_argument(
2018-06-22 18:49:52 +00:00
'--ldflags', type=str, nargs='?', default=common.DEFAULTLDFLAGS,
help='Extra linking flags')
2018-06-20 19:05:13 +00:00
parser.add_argument(
2018-06-22 18:49:52 +00:00
'--host', type=str, nargs='?', default=common.HOSTPYTHON,
help='The path to the host Python installation')
2018-06-20 19:05:13 +00:00
parser.add_argument(
2018-06-22 18:49:52 +00:00
'--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation')
2018-06-20 18:54:47 +00:00
return parser.parse_args()
def main(args):
2018-08-03 16:48:22 +00:00
packagesdir = Path(args.dir[0]).resolve()
outputdir = Path(args.output[0]).resolve()
2018-08-06 14:01:28 +00:00
build_packages(packagesdir, outputdir, args)
2018-06-20 18:54:47 +00:00
if __name__ == '__main__':
args = parse_args()
main(args)