Compare commits
No commits in common. "229567c9b008526e02f4a7445e2e10213fd7d6c4" and "72f82e0ace184fe862f1b19c4f71c3bc36cf335b" have entirely different histories.
229567c9b0
...
72f82e0ace
4 changed files with 30 additions and 49 deletions
|
@ -40,9 +40,6 @@ py_test(
|
||||||
name = "hello_native",
|
name = "hello_native",
|
||||||
main = "hello.py",
|
main = "hello.py",
|
||||||
srcs = ["hello.py"],
|
srcs = ["hello.py"],
|
||||||
deps = [
|
|
||||||
py_requirement("pyyaml"),
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
zapp_test(
|
zapp_test(
|
||||||
|
@ -76,6 +73,7 @@ zapp_test(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
zapp_test(
|
zapp_test(
|
||||||
name = "hello_unzipped",
|
name = "hello_unzipped",
|
||||||
zip_safe = False,
|
zip_safe = False,
|
||||||
|
|
|
@ -35,7 +35,7 @@ toolchain(
|
||||||
# Zapp plugins used as a runtime library by rules_zapp
|
# Zapp plugins used as a runtime library by rules_zapp
|
||||||
py_library(
|
py_library(
|
||||||
name = "zapp_support",
|
name = "zapp_support",
|
||||||
srcs = ["__init__.py"] + glob(["support/**/*.py"]),
|
srcs = glob(["support/**/*.py"]),
|
||||||
imports = [
|
imports = [
|
||||||
"..",
|
"..",
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,11 +6,9 @@ import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
from collections import defaultdict
|
|
||||||
from email.parser import Parser
|
from email.parser import Parser
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -22,9 +20,6 @@ from zapp.support.unpack import cache_wheel_path
|
||||||
parser = argparse.ArgumentParser(description="The (bootstrap) Zapp compiler")
|
parser = argparse.ArgumentParser(description="The (bootstrap) Zapp compiler")
|
||||||
parser.add_argument("-o", "--out", dest="output", help="Output target file")
|
parser.add_argument("-o", "--out", dest="output", help="Output target file")
|
||||||
parser.add_argument("-d", "--debug", dest="debug", action="store_true", default=False)
|
parser.add_argument("-d", "--debug", dest="debug", action="store_true", default=False)
|
||||||
parser.add_argument(
|
|
||||||
"--use-wheels", dest="use_wheels", action="store_true", default=False
|
|
||||||
)
|
|
||||||
parser.add_argument("manifest", help="The (JSON) manifest")
|
parser.add_argument("manifest", help="The (JSON) manifest")
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,9 +51,6 @@ for script in {scripts!r}:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
whl_workspace_pattern = re.compile(r"^external/(?P<workspace>[^/]*?)/site-packages/")
|
|
||||||
|
|
||||||
|
|
||||||
def dsub(d1: dict, d2: dict) -> dict:
|
def dsub(d1: dict, d2: dict) -> dict:
|
||||||
"""Dictionary subtraction. Remove k/vs from d1 if they occur in d2."""
|
"""Dictionary subtraction. Remove k/vs from d1 if they occur in d2."""
|
||||||
|
|
||||||
|
@ -84,7 +76,7 @@ def dir_walk_prefixes(path):
|
||||||
yield os.path.join(*segments)
|
yield os.path.join(*segments)
|
||||||
|
|
||||||
|
|
||||||
def load_wheel(opts, path):
|
def load_wheel(opts, manifest, path):
|
||||||
"""Load a single wheel, returning ..."""
|
"""Load a single wheel, returning ..."""
|
||||||
|
|
||||||
def _parse_email(msg):
|
def _parse_email(msg):
|
||||||
|
@ -105,8 +97,17 @@ def load_wheel(opts, path):
|
||||||
with open(os.path.join(path, "WHEEL")) as wheelf:
|
with open(os.path.join(path, "WHEEL")) as wheelf:
|
||||||
wheel = _parse_email(wheelf.read())
|
wheel = _parse_email(wheelf.read())
|
||||||
|
|
||||||
|
prefix = os.path.dirname(path)
|
||||||
|
|
||||||
# Naive glob of sources; note that bazel may hvae inserted empty __init__.py trash
|
# Naive glob of sources; note that bazel may hvae inserted empty __init__.py trash
|
||||||
sources = []
|
sources = [
|
||||||
|
(
|
||||||
|
dest,
|
||||||
|
spec,
|
||||||
|
)
|
||||||
|
for dest, spec in manifest["sources"].items()
|
||||||
|
if spec["source"].startswith(prefix)
|
||||||
|
]
|
||||||
|
|
||||||
# Retain only manifest-listed sources (dealing with __init__.py trash, but maybe not all conflicts)
|
# Retain only manifest-listed sources (dealing with __init__.py trash, but maybe not all conflicts)
|
||||||
with open(os.path.join(path, "RECORD")) as recordf:
|
with open(os.path.join(path, "RECORD")) as recordf:
|
||||||
|
@ -186,23 +187,13 @@ def rezip_wheels(opts, manifest):
|
||||||
|
|
||||||
Wheels which are unzipped should be re-zipped into the cache, if not present in the cache.
|
Wheels which are unzipped should be re-zipped into the cache, if not present in the cache.
|
||||||
|
|
||||||
Files sourced from unzipped wheels should be removed, and a single wheel reference inserted.
|
Files sourced from unzipped wheels should be removed, and a single wheel reference inserted."""
|
||||||
"""
|
|
||||||
|
|
||||||
whl_srcs = defaultdict(dict)
|
wheels = [
|
||||||
for k, s in list(manifest["sources"].items()):
|
load_wheel(opts, manifest, os.path.dirname(s["source"]))
|
||||||
src = s["source"]
|
for _, s in manifest["sources"].items()
|
||||||
m = re.match(whl_workspace_pattern, src)
|
if s["source"].endswith("/WHEEL")
|
||||||
if m:
|
]
|
||||||
whl_srcs[m.group(1)][re.sub(whl_workspace_pattern, "", src)] = s
|
|
||||||
del manifest["sources"][k]
|
|
||||||
|
|
||||||
wheels = []
|
|
||||||
for bundle in whl_srcs.values():
|
|
||||||
whlk = next((k for k in bundle.keys() if k.endswith("WHEEL")), None)
|
|
||||||
whl_manifest = load_wheel(opts, os.path.dirname(bundle[whlk]["source"]))
|
|
||||||
whl_manifest["sources"].update(bundle)
|
|
||||||
wheels.append(whl_manifest)
|
|
||||||
|
|
||||||
manifest["requirements"] = {}
|
manifest["requirements"] = {}
|
||||||
|
|
||||||
|
@ -210,6 +201,8 @@ def rezip_wheels(opts, manifest):
|
||||||
for w in wheels:
|
for w in wheels:
|
||||||
# Try to cheat and hit in the local cache first rather than building wheels every time
|
# Try to cheat and hit in the local cache first rather than building wheels every time
|
||||||
wn = wheel_name(w)
|
wn = wheel_name(w)
|
||||||
|
# Expunge sources available in the wheel
|
||||||
|
manifest["sources"] = dsub(manifest["sources"], w["sources"])
|
||||||
|
|
||||||
# We may have a double-path dependency.
|
# We may have a double-path dependency.
|
||||||
# If we DON'T, we have to zip
|
# If we DON'T, we have to zip
|
||||||
|
@ -309,6 +302,7 @@ def enable_unzipping(opts, manifest):
|
||||||
|
|
||||||
|
|
||||||
def fix_sources(opts, manifest):
|
def fix_sources(opts, manifest):
|
||||||
|
|
||||||
manifest["sources"] = {f: m for f, m in manifest["sources"]}
|
manifest["sources"] = {f: m for f, m in manifest["sources"]}
|
||||||
|
|
||||||
return manifest
|
return manifest
|
||||||
|
@ -324,7 +318,6 @@ def main():
|
||||||
setattr(opts, "tmpdir", d)
|
setattr(opts, "tmpdir", d)
|
||||||
|
|
||||||
manifest = fix_sources(opts, manifest)
|
manifest = fix_sources(opts, manifest)
|
||||||
if opts.use_wheels:
|
|
||||||
manifest = rezip_wheels(opts, manifest)
|
manifest = rezip_wheels(opts, manifest)
|
||||||
manifest = ensure_srcs_map(opts, manifest)
|
manifest = ensure_srcs_map(opts, manifest)
|
||||||
manifest = enable_unzipping(opts, manifest)
|
manifest = enable_unzipping(opts, manifest)
|
||||||
|
@ -346,15 +339,11 @@ def main():
|
||||||
"manifest": manifest,
|
"manifest": manifest,
|
||||||
},
|
},
|
||||||
sys.stdout,
|
sys.stdout,
|
||||||
indent=2,
|
indent=2
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(opts.output, "w") as zapp:
|
with open(opts.output, "w") as zapp:
|
||||||
shebang = manifest["shebang"]
|
shebang = "#!" + manifest["shebang"] + "\n"
|
||||||
if not shebang.endswith("\n"):
|
|
||||||
shebang = shebang + "\n"
|
|
||||||
if not shebang.startswith("#!"):
|
|
||||||
shebang = "#!" + shebang
|
|
||||||
zapp.write(shebang)
|
zapp.write(shebang)
|
||||||
|
|
||||||
# Now we're gonna build the zapp from the manifest
|
# Now we're gonna build the zapp from the manifest
|
||||||
|
|
|
@ -141,14 +141,6 @@ def _zapp_impl(ctx):
|
||||||
is_executable = False,
|
is_executable = False,
|
||||||
)
|
)
|
||||||
|
|
||||||
args = [
|
|
||||||
"--debug",
|
|
||||||
"-o", ctx.outputs.executable.path,
|
|
||||||
manifest_file.path
|
|
||||||
]
|
|
||||||
if ctx.attr.use_wheels:
|
|
||||||
args = ["--use-wheels"] + args
|
|
||||||
|
|
||||||
# Run compiler
|
# Run compiler
|
||||||
ctx.actions.run(
|
ctx.actions.run(
|
||||||
inputs = [
|
inputs = [
|
||||||
|
@ -158,7 +150,10 @@ def _zapp_impl(ctx):
|
||||||
outputs = [ctx.outputs.executable],
|
outputs = [ctx.outputs.executable],
|
||||||
progress_message = "Building zapp file %s" % ctx.label,
|
progress_message = "Building zapp file %s" % ctx.label,
|
||||||
executable = ctx.executable.compiler,
|
executable = ctx.executable.compiler,
|
||||||
arguments = args,
|
arguments = [
|
||||||
|
"-o", ctx.outputs.executable.path,
|
||||||
|
manifest_file.path
|
||||||
|
],
|
||||||
mnemonic = "PythonCompile",
|
mnemonic = "PythonCompile",
|
||||||
use_default_shell_env = True,
|
use_default_shell_env = True,
|
||||||
execution_requirements = {
|
execution_requirements = {
|
||||||
|
@ -182,14 +177,13 @@ _zapp_attrs = {
|
||||||
"entry_point": attr.string(),
|
"entry_point": attr.string(),
|
||||||
"prelude_points": attr.string_list(),
|
"prelude_points": attr.string_list(),
|
||||||
"zip_safe": attr.bool(default = True),
|
"zip_safe": attr.bool(default = True),
|
||||||
"use_wheels": attr.bool(default = False),
|
|
||||||
# FIXME: These are really toolchain parameters, probably.
|
# FIXME: These are really toolchain parameters, probably.
|
||||||
"compiler": attr.label(
|
"compiler": attr.label(
|
||||||
default = Label(DEFAULT_COMPILER),
|
default = Label(DEFAULT_COMPILER),
|
||||||
executable = True,
|
executable = True,
|
||||||
cfg = "host",
|
cfg = "host",
|
||||||
),
|
),
|
||||||
"shebang": attr.string(default = "#!/usr/bin/env %py3%"),
|
"shebang": attr.string(default = "/usr/bin/env %py3%"),
|
||||||
}
|
}
|
||||||
|
|
||||||
_zapp = rule(
|
_zapp = rule(
|
||||||
|
|
Loading…
Reference in a new issue