diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 44d65f67aa611..c61daf90bc024 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -13,26 +13,42 @@ ports_dir = os.path.dirname(os.path.abspath(__file__)) -def read_ports(): +def load_port(port): expected_attrs = ['get', 'clear', 'process_args', 'show', 'needed'] + ports.append(port) + ports_by_name[port.name] = port + for a in expected_attrs: + assert hasattr(port, a), 'port %s is missing %s' % (port, a) + if not hasattr(port, 'process_dependencies'): + port.process_dependencies = lambda x: 0 + if not hasattr(port, 'deps'): + port.deps = [] + +def read_ports(): for filename in os.listdir(ports_dir): if not filename.endswith('.py') or filename == '__init__.py': continue filename = os.path.splitext(filename)[0] port = __import__(filename, globals(), level=1) - ports.append(port) port.name = filename - ports_by_name[port.name] = port - for a in expected_attrs: - assert hasattr(port, a), 'port %s is missing %s' % (port, a) - if not hasattr(port, 'process_dependencies'): - port.process_dependencies = lambda x: 0 - if not hasattr(port, 'deps'): - port.deps = [] - - for dep in port.deps: - if dep not in ports_by_name: - exit_with_error('unknown dependency in port: %s' % dep) + load_port(port) + + contrib_dir = os.path.join(ports_dir, 'contrib') + for filename in os.listdir(contrib_dir): + if not filename.endswith('.py') or filename == '__init__.py': + continue + filename = os.path.splitext(filename)[0] + print(filename) + port = __import__('contrib.' + filename, globals(), level=1, fromlist=[None]) + print(port) + port.name = filename + load_port(port) + + for port in ports: + for dep in port.deps: + if dep not in ports_by_name: + exit_with_error('unknown dependency in port: %s' % dep) + read_ports() diff --git a/tools/ports/contrib/README.md b/tools/ports/contrib/README.md new file mode 100644 index 0000000000000..6486dc80810c4 --- /dev/null +++ b/tools/ports/contrib/README.md @@ -0,0 +1,11 @@ +Emscripten "Contib" Ports +========================= + +Ports in this directory are contributed by the wider community and are +supported on the "best effort" basis. Since they are not run as part of +emscripten CI they are not always guaranteed to build or function. + +To using the ports in this directory you must build them using the `embuilder` +command. e.g.: + + ./embuilder build foo diff --git a/tools/ports/contrib/__init__.py b/tools/ports/contrib/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/tools/ports/contrib/libarchive.py b/tools/ports/contrib/libarchive.py new file mode 100644 index 0000000000000..5e53745ffafef --- /dev/null +++ b/tools/ports/contrib/libarchive.py @@ -0,0 +1,59 @@ +# Copyright 2014 The Emscripten Authors. All rights reserved. +# Emscripten is available under two separate licenses, the MIT license and the +# University of Illinois/NCSA Open Source License. Both these licenses can be +# found in the LICENSE file. + +import os +import shutil + +TAG = 'version_1' +HASH = '77f7d8f18fe11bb66a57e358325b7422d721f7b506bd63293cfde74079f958864db66ead5a36c311a76dd8c2b089b7659641a5522de650de0f9e6865782a60dd' + + +def needed(settings): + return True + + +def get(ports, settings, shared): + ports.fetch_project('libarchive', 'https://github.com/libarchive/libarchive/releases/download/v' + TAG + '/libarchive-' + TAG + '.tar.gz', 'libarchive-' + TAG, sha512hash=HASH) + + def create(): + ports.clear_project_build('libarchive') + + source_path = os.path.join(ports.get_dir(), 'libarchive', 'libarchive-' + TAG) + dest_path = os.path.join(shared.Cache.get_path('ports-builds'), 'libarchive') + shared.try_delete(dest_path) + os.makedirs(dest_path) + shutil.rmtree(dest_path, ignore_errors=True) + shutil.copytree(source_path, dest_path) + ports.install_headers(dest_path) + + # build + srcs = 'adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c gzwrite.c infback.c' + 'inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c'.split() + commands = [] + o_s = [] + for src in srcs: + o = os.path.join(ports.get_build_dir(), 'libarchive', src + '.o') + shared.safe_ensure_dirs(os.path.dirname(o)) + commands.append([shared.EMCC, os.path.join(dest_path, src), '-O2', '-o', o, '-I' + dest_path, '-w', '-c']) + o_s.append(o) + ports.run_commands(commands) + + final = os.path.join(ports.get_build_dir(), 'libarchive', 'libarchive.a') + ports.create_lib(final, o_s) + return final + + return [shared.Cache.get('libarchive.a', create, what='port')] + + +def clear(ports, settings, shared): + shared.Cache.erase_file('libarchive.a') + + +def process_args(ports): + return [] + + +def show(): + return 'libarchive'