2018-06-20 18:54:47 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-06-22 14:22:00 +00:00
|
|
|
"""
|
|
|
|
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
|
|
|
|
|
2018-09-20 14:42:38 +00:00
|
|
|
from . import common
|
|
|
|
from . import buildpkg
|
2018-06-20 18:54:47 +00:00
|
|
|
|
|
|
|
|
2018-08-06 14:01:28 +00:00
|
|
|
def build_package(pkgname, dependencies, packagesdir, outputdir, args):
|
2018-06-22 14:22:00 +00:00
|
|
|
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)
|
2020-06-28 18:24:40 +00:00
|
|
|
buildpkg.build_package(packagesdir / pkgname / "meta.yaml", args)
|
2018-06-20 18:54:47 +00:00
|
|
|
shutil.copyfile(
|
2020-06-28 18:24:40 +00:00
|
|
|
packagesdir / pkgname / "build" / (pkgname + ".data"),
|
|
|
|
outputdir / (pkgname + ".data"),
|
|
|
|
)
|
2018-06-20 18:54:47 +00:00
|
|
|
shutil.copyfile(
|
2020-06-28 18:24:40 +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):
|
2018-06-22 14:22:00 +00:00
|
|
|
# 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-10-10 18:16:14 +00:00
|
|
|
import_name_to_package_name = {}
|
2020-05-08 23:28:44 +00:00
|
|
|
included_packages = common._parse_package_subset(args.only)
|
|
|
|
if included_packages is not None:
|
|
|
|
# check that the specified packages exist
|
|
|
|
for name in included_packages:
|
|
|
|
if not (packagesdir / name).exists():
|
|
|
|
raise ValueError(
|
2020-06-28 18:24:40 +00:00
|
|
|
f"package name {name} does not exist. "
|
|
|
|
f"The value of PYODIDE_PACKAGES is likely incorrect."
|
2020-05-08 23:28:44 +00:00
|
|
|
)
|
|
|
|
|
2018-08-03 16:48:22 +00:00
|
|
|
for pkgdir in packagesdir.iterdir():
|
2020-06-28 18:24:40 +00:00
|
|
|
if included_packages is not None and pkgdir.name not in included_packages:
|
2020-05-08 23:28:44 +00:00
|
|
|
print(
|
2020-07-13 19:46:20 +00:00
|
|
|
f"Warning: skipping build of {pkgdir.name} due "
|
2020-05-08 23:28:44 +00:00
|
|
|
f"to specified PYODIDE_PACKAGES"
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
|
2020-06-28 18:24:40 +00:00
|
|
|
pkgpath = pkgdir / "meta.yaml"
|
2018-08-03 16:48:22 +00:00
|
|
|
if pkgdir.is_dir() and pkgpath.is_file():
|
2018-06-20 18:54:47 +00:00
|
|
|
pkg = common.parse_package(pkgpath)
|
2020-06-28 18:24:40 +00:00
|
|
|
name = pkg["package"]["name"]
|
|
|
|
reqs = pkg.get("requirements", {}).get("run", [])
|
2018-06-20 18:54:47 +00:00
|
|
|
dependencies[name] = reqs
|
2020-06-28 18:24:40 +00:00
|
|
|
imports = pkg.get("test", {}).get("imports", [name])
|
2018-10-10 18:16:14 +00:00
|
|
|
for imp in imports:
|
|
|
|
import_name_to_package_name[imp] = name
|
2018-06-20 18:54:47 +00:00
|
|
|
|
2018-06-22 14:22:00 +00:00
|
|
|
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
|
|
|
|
2018-07-18 13:26:18 +00:00
|
|
|
# The "test" package is built in a different way, so we hardcode its
|
|
|
|
# existence here.
|
2020-06-28 18:24:40 +00:00
|
|
|
dependencies["test"] = []
|
2018-07-18 13:26:18 +00:00
|
|
|
|
|
|
|
# This is done last so the Makefile can use it as a completion token.
|
2020-06-28 18:24:40 +00:00
|
|
|
with open(outputdir / "packages.json", "w") as fd:
|
|
|
|
json.dump(
|
|
|
|
{
|
|
|
|
"dependencies": dependencies,
|
|
|
|
"import_name_to_package_name": import_name_to_package_name,
|
|
|
|
},
|
|
|
|
fd,
|
|
|
|
)
|
2018-06-20 18:54:47 +00:00
|
|
|
|
|
|
|
|
2018-09-20 14:42:38 +00:00
|
|
|
def make_parser(parser):
|
2020-05-08 23:28:44 +00:00
|
|
|
parser.description = (
|
|
|
|
"Build all of the packages in a given directory\n\n"
|
|
|
|
"Unless the --only option is provided"
|
|
|
|
)
|
2018-06-22 14:22:00 +00:00
|
|
|
parser.add_argument(
|
2020-06-28 18:24:40 +00:00
|
|
|
"dir",
|
|
|
|
type=str,
|
|
|
|
nargs=1,
|
|
|
|
help="Input directory containing a tree of package definitions",
|
|
|
|
)
|
2018-06-22 14:22:00 +00:00
|
|
|
parser.add_argument(
|
2020-06-28 18:24:40 +00:00
|
|
|
"output",
|
|
|
|
type=str,
|
|
|
|
nargs=1,
|
|
|
|
help="Output directory in which to put all built packages",
|
|
|
|
)
|
2018-12-25 09:44:09 +00:00
|
|
|
parser.add_argument(
|
2020-06-28 18:24:40 +00:00
|
|
|
"--package_abi",
|
|
|
|
type=int,
|
|
|
|
required=True,
|
|
|
|
help="The ABI number for the packages to be built",
|
|
|
|
)
|
2018-06-20 19:05:13 +00:00
|
|
|
parser.add_argument(
|
2020-06-28 18:24:40 +00:00
|
|
|
"--cflags",
|
|
|
|
type=str,
|
|
|
|
nargs="?",
|
|
|
|
default=common.DEFAULTCFLAGS,
|
|
|
|
help="Extra compiling flags",
|
|
|
|
)
|
2018-06-20 19:05:13 +00:00
|
|
|
parser.add_argument(
|
2020-06-28 18:24:40 +00:00
|
|
|
"--ldflags",
|
|
|
|
type=str,
|
|
|
|
nargs="?",
|
|
|
|
default=common.DEFAULTLDFLAGS,
|
|
|
|
help="Extra linking flags",
|
|
|
|
)
|
2018-06-20 19:05:13 +00:00
|
|
|
parser.add_argument(
|
2020-06-28 18:24:40 +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(
|
2020-06-28 18:24:40 +00:00
|
|
|
"--target",
|
|
|
|
type=str,
|
|
|
|
nargs="?",
|
|
|
|
default=common.TARGETPYTHON,
|
|
|
|
help="The path to the target Python installation",
|
|
|
|
)
|
2020-05-08 23:28:44 +00:00
|
|
|
parser.add_argument(
|
2020-06-28 18:24:40 +00:00
|
|
|
"--only",
|
|
|
|
type=str,
|
|
|
|
nargs="?",
|
|
|
|
default=None,
|
|
|
|
help=(
|
|
|
|
"Only build the specified packages, provided as a comma " "separated list"
|
|
|
|
),
|
|
|
|
)
|
2018-09-20 14:42:38 +00:00
|
|
|
return parser
|
2018-06-20 18:54:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2020-06-28 18:24:40 +00:00
|
|
|
if __name__ == "__main__":
|
2018-09-20 14:42:38 +00:00
|
|
|
parser = make_parser(argparse.ArgumentParser())
|
|
|
|
args = parser.parse_args()
|
2018-06-20 18:54:47 +00:00
|
|
|
main(args)
|