Commit 72293058 authored by Roman Yurchak's avatar Roman Yurchak

Converting tools scripts to a python package

parent 9d15654f
...@@ -22,3 +22,4 @@ ccache ...@@ -22,3 +22,4 @@ ccache
/six/six-1.11.0 /six/six-1.11.0
/lz4/lz4-1.8.3 /lz4/lz4-1.8.3
*.egg-info/
...@@ -204,6 +204,8 @@ ccache/em++: ...@@ -204,6 +204,8 @@ ccache/em++:
$(CPYTHONLIB): emsdk/emsdk/.complete ccache/emcc ccache/em++ $(CPYTHONLIB): emsdk/emsdk/.complete ccache/emcc ccache/em++
make -C $(CPYTHONROOT) make -C $(CPYTHONROOT)
python -m pip install -e .
"$(HOSTPYTHONROOT)/bin/python3" -m pip install -e .
$(LZ4LIB): $(LZ4LIB):
......
...@@ -2,7 +2,7 @@ PYODIDE_ROOT=$(abspath ..) ...@@ -2,7 +2,7 @@ PYODIDE_ROOT=$(abspath ..)
include ../Makefile.envs include ../Makefile.envs
all: all:
../tools/buildall . ../build --ldflags="$(SIDE_LDFLAGS)" --host=$(HOSTPYTHONROOT) --target=$(TARGETPYTHONROOT) pyodide buildall . ../build --ldflags="$(SIDE_LDFLAGS)" --host=$(HOSTPYTHONROOT) --target=$(TARGETPYTHONROOT)
clean: clean:
rm -rf ./*/build rm -rf ./*/build
__version__ = '0.1.0'
...@@ -10,8 +10,8 @@ from pathlib import Path ...@@ -10,8 +10,8 @@ from pathlib import Path
import shutil import shutil
import common from . import common
import buildpkg from . import buildpkg
def build_package(pkgname, dependencies, packagesdir, outputdir, args): def build_package(pkgname, dependencies, packagesdir, outputdir, args):
...@@ -54,9 +54,8 @@ def build_packages(packagesdir, outputdir, args): ...@@ -54,9 +54,8 @@ def build_packages(packagesdir, outputdir, args):
json.dump({'dependencies': dependencies}, fd) json.dump({'dependencies': dependencies}, fd)
def parse_args(): def make_parser(parser):
parser = argparse.ArgumentParser( parser.description = "Build all of the packages in a given directory"
"Build all of the packages in a given directory")
parser.add_argument( parser.add_argument(
'dir', type=str, nargs=1, 'dir', type=str, nargs=1,
help='Input directory containing a tree of package definitions') help='Input directory containing a tree of package definitions')
...@@ -75,7 +74,7 @@ def parse_args(): ...@@ -75,7 +74,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--target', type=str, nargs='?', default=common.TARGETPYTHON, '--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation') help='The path to the target Python installation')
return parser.parse_args() return parser
def main(args): def main(args):
...@@ -85,5 +84,6 @@ def main(args): ...@@ -85,5 +84,6 @@ def main(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parse_args() parser = make_parser(argparse.ArgumentParser())
args = parser.parse_args()
main(args) main(args)
...@@ -12,10 +12,7 @@ import shutil ...@@ -12,10 +12,7 @@ import shutil
import subprocess import subprocess
import common from . import common
ROOTDIR = Path(__file__).parent.resolve()
def check_checksum(path, pkg): def check_checksum(path, pkg):
...@@ -88,7 +85,8 @@ def compile(path, srcpath, pkg, args): ...@@ -88,7 +85,8 @@ def compile(path, srcpath, pkg, args):
try: try:
subprocess.run([ subprocess.run([
str(Path(args.host) / 'bin' / 'python3'), str(Path(args.host) / 'bin' / 'python3'),
str(ROOTDIR / 'pywasmcross'), '-m', 'pyodide_build',
'pywasmcross',
'--cflags', '--cflags',
args.cflags + ' ' + args.cflags + ' ' +
pkg.get('build', {}).get('cflags', ''), pkg.get('build', {}).get('cflags', ''),
...@@ -124,7 +122,7 @@ def package_files(buildpath, srcpath, pkg, args): ...@@ -124,7 +122,7 @@ def package_files(buildpath, srcpath, pkg, args):
install_prefix = (srcpath / 'install').resolve() install_prefix = (srcpath / 'install').resolve()
subprocess.run([ subprocess.run([
'python', 'python',
Path(ROOTDIR) / 'file_packager.py', common.TOOLSDIR / 'file_packager.py',
name + '.data', name + '.data',
'--lz4', '--lz4',
'--preload', '--preload',
...@@ -163,8 +161,8 @@ def build_package(path, args): ...@@ -163,8 +161,8 @@ def build_package(path, args):
os.chdir(orig_path) os.chdir(orig_path)
def parse_args(): def make_parser(parser):
parser = argparse.ArgumentParser('Build a pyodide package.') parser.description = 'Build a pyodide package.'
parser.add_argument( parser.add_argument(
'package', type=str, nargs=1, 'package', type=str, nargs=1,
help="Path to meta.yaml package description") help="Path to meta.yaml package description")
...@@ -180,7 +178,7 @@ def parse_args(): ...@@ -180,7 +178,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--target', type=str, nargs='?', default=common.TARGETPYTHON, '--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation') help='The path to the target Python installation')
return parser.parse_args() return parser
def main(args): def main(args):
...@@ -189,5 +187,6 @@ def main(args): ...@@ -189,5 +187,6 @@ def main(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parse_args() parser = make_parser(argparse.ArgumentParser())
args = parser.parse_args()
main(args) main(args)
from pathlib import Path from pathlib import Path
ROOTDIR = Path(__file__).parent.resolve() ROOTDIR = Path(__file__).parents[1].resolve()
HOSTPYTHON = ROOTDIR / '..' / 'cpython' / 'build' / '3.7.0' / 'host' TOOLSDIR = ROOTDIR / 'tools'
TARGETPYTHON = ROOTDIR / '..' / 'cpython' / 'installs' / 'python-3.7.0' HOSTPYTHON = ROOTDIR / 'cpython' / 'build' / '3.7.0' / 'host'
TARGETPYTHON = ROOTDIR / 'cpython' / 'installs' / 'python-3.7.0'
DEFAULTCFLAGS = '' DEFAULTCFLAGS = ''
DEFAULTLDFLAGS = ' '.join([ DEFAULTLDFLAGS = ' '.join([
'-O3', '-O3',
......
...@@ -34,10 +34,12 @@ import subprocess ...@@ -34,10 +34,12 @@ import subprocess
import sys import sys
import common # absolute import is necessary as this file will be symlinked
# under tools
from pyodide_build import common
ROOTDIR = Path(__file__).parent.resolve() TOOLSDIR = common.TOOLSDIR
symlinks = set(['cc', 'c++', 'ld', 'ar', 'gcc']) symlinks = set(['cc', 'c++', 'ld', 'ar', 'gcc'])
...@@ -53,8 +55,8 @@ def collect_args(basename): ...@@ -53,8 +55,8 @@ def collect_args(basename):
# native compiler # native compiler
env = dict(os.environ) env = dict(os.environ)
path = env['PATH'] path = env['PATH']
while str(ROOTDIR) + ':' in path: while str(TOOLSDIR) + ':' in path:
path = path.replace(str(ROOTDIR) + ':', '') path = path.replace(str(TOOLSDIR) + ':', '')
env['PATH'] = path env['PATH'] = path
with open('build.log', 'a') as fd: with open('build.log', 'a') as fd:
...@@ -74,7 +76,7 @@ def make_symlinks(env): ...@@ -74,7 +76,7 @@ def make_symlinks(env):
""" """
exec_path = Path(__file__).resolve() exec_path = Path(__file__).resolve()
for symlink in symlinks: for symlink in symlinks:
symlink_path = ROOTDIR / symlink symlink_path = TOOLSDIR / symlink
if not symlink_path.exists(): if not symlink_path.exists():
symlink_path.symlink_to(exec_path) symlink_path.symlink_to(exec_path)
if symlink == 'c++': if symlink == 'c++':
...@@ -87,7 +89,7 @@ def make_symlinks(env): ...@@ -87,7 +89,7 @@ def make_symlinks(env):
def capture_compile(args): def capture_compile(args):
env = dict(os.environ) env = dict(os.environ)
make_symlinks(env) make_symlinks(env)
env['PATH'] = str(ROOTDIR) + ':' + os.environ['PATH'] env['PATH'] = str(TOOLSDIR) + ':' + os.environ['PATH']
result = subprocess.run( result = subprocess.run(
[Path(args.host) / 'bin' / 'python3', [Path(args.host) / 'bin' / 'python3',
...@@ -186,7 +188,7 @@ def clean_out_native_artifacts(): ...@@ -186,7 +188,7 @@ def clean_out_native_artifacts():
path.unlink() path.unlink()
def install_for_distribution(): def install_for_distribution(args):
subprocess.check_call( subprocess.check_call(
[Path(args.host) / 'bin' / 'python3', [Path(args.host) / 'bin' / 'python3',
'setup.py', 'setup.py',
...@@ -202,11 +204,11 @@ def build_wrap(args): ...@@ -202,11 +204,11 @@ def build_wrap(args):
capture_compile(args) capture_compile(args)
clean_out_native_artifacts() clean_out_native_artifacts()
replay_compile(args) replay_compile(args)
install_for_distribution() install_for_distribution(args)
def parse_args(): def make_parser(parser):
parser = argparse.ArgumentParser( parser.description = (
'Cross compile a Python distutils package. ' 'Cross compile a Python distutils package. '
'Run from the root directory of the package\'s source') 'Run from the root directory of the package\'s source')
parser.add_argument( parser.add_argument(
...@@ -221,14 +223,19 @@ def parse_args(): ...@@ -221,14 +223,19 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--target', type=str, nargs='?', default=common.TARGETPYTHON, '--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation') help='The path to the target Python installation')
args = parser.parse_args() parser.add_argument('basename', type=str, nargs='?')
return args return parser
if __name__ == '__main__': def main(args, unknown=None):
basename = Path(sys.argv[0]).name basename = Path(sys.argv[0]).name
if basename in symlinks: if basename in symlinks:
collect_args(basename) collect_args(basename)
else: else:
args = parse_args()
build_wrap(args) build_wrap(args)
if __name__ == '__main__':
parser = make_parser(argparse.ArgumentParser())
args, unknown = parser.parse_known_args()
main(args, unknown)
from setuptools import setup, find_packages
from pyodide_build import __version__
with open('README.md', 'rt') as fh:
LONG_DESCRIPTION = fh.read()
setup(name='pyodide_build',
version=__version__,
description='pyodide builder',
entry_points={
'console_scripts': [
'pyodide = pyodide_build.__main__:main'
]},
url="https://github.com/iodide-project/pyodide",
license='MPL',
packages=find_packages())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment