Build Linux and macOS clients with platform update feeds
This commit is contained in:
+42
-6
@@ -13,6 +13,7 @@ unchanged app is never rebuilt.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
@@ -34,10 +35,12 @@ KEEP = 3
|
||||
# Inputs that change what a build produces. Generated and machine-local paths
|
||||
# (build/, .dart_tool/, android/local.properties) are left out.
|
||||
SOURCES = {
|
||||
"web": ("lib", "web", "assets", "pubspec.yaml", "pubspec.lock", ".flutter-version", "docker"),
|
||||
"apk": ("lib", "android", "assets", "pubspec.yaml", "pubspec.lock", ".flutter-version", "docker"),
|
||||
"web": ("lib", "web", "assets", "fonts", "pubspec.yaml", "pubspec.lock", ".flutter-version", "docker"),
|
||||
"apk": ("lib", "android", "assets", "fonts", "pubspec.yaml", "pubspec.lock", ".flutter-version", "docker"),
|
||||
"linux": ("lib", "linux", "assets", "fonts", "pubspec.yaml", "pubspec.lock", ".flutter-version", "docker"),
|
||||
"macos": ("lib", "macos", "assets", "fonts", "pubspec.yaml", "pubspec.lock", ".flutter-version"),
|
||||
}
|
||||
SKIPPED = {"build", ".dart_tool", ".gradle", ".cxx", "local.properties", ".DS_Store"}
|
||||
SKIPPED = {"build", ".dart_tool", ".gradle", ".cxx", "local.properties", ".DS_Store", "ephemeral", "Pods", ".symlinks"}
|
||||
# This is part of the web cache key so entries made before release metadata was
|
||||
# generated cannot be mistaken for complete web releases.
|
||||
WEB_CACHE_SCHEMA = "web-release-metadata-v1"
|
||||
@@ -54,6 +57,12 @@ def digest(kind, app=APP, extra=()):
|
||||
hasher.update(kind.encode())
|
||||
if kind == "web":
|
||||
hasher.update(b"\0cache-schema\0" + WEB_CACHE_SCHEMA.encode())
|
||||
if kind in ("linux", "macos"):
|
||||
hasher.update(b"\0cache-schema\0desktop-v1")
|
||||
for script in (Path(__file__), Path(__file__).with_name("app_desktop_build.py")):
|
||||
hasher.update(b"\0builder\0" + script.read_bytes())
|
||||
if kind == "linux":
|
||||
hasher.update(b"\0platform\0linux/amd64")
|
||||
for item in extra:
|
||||
hasher.update(b"\0arg\0" + item.encode())
|
||||
for name in SOURCES[kind]:
|
||||
@@ -107,12 +116,12 @@ def docker_available(runner=subprocess.run):
|
||||
|
||||
def image(kind, runner, app=APP):
|
||||
"""Builds (or reuses, via Docker's layer cache) the build image for [kind]."""
|
||||
target = "android" if kind == "apk" else "web"
|
||||
target = {"apk": "android", "linux": "linux"}.get(kind, "web")
|
||||
version = flutter_version(app)
|
||||
tag = f"pipelines-flutter-{target}:{version}"
|
||||
args = ["build", "--target", target, "--build-arg", f"FLUTTER_VERSION={version}", "-t", tag,
|
||||
"-f", str(app / "docker/Dockerfile")]
|
||||
if kind == "apk":
|
||||
if kind in ("apk", "linux"):
|
||||
# Android's build tools (aapt2) ship for x86-64 Linux only.
|
||||
args += ["--platform", "linux/amd64"]
|
||||
docker(runner, *args, str(app / "docker"))
|
||||
@@ -140,6 +149,8 @@ def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=pr
|
||||
key = digest(kind, app, arguments)
|
||||
entry = cache / f"{kind}-{key}"
|
||||
usable = web_cache_complete(entry) if kind == "web" else (entry / ".complete").is_file()
|
||||
if kind == "linux":
|
||||
usable = usable and (entry / "pipelines-app").is_file() and (entry / "data/flutter_assets").is_dir() and (entry / "lib").is_dir()
|
||||
if usable:
|
||||
log(f"Reusing the {kind} build {key} (app sources unchanged).")
|
||||
return entry
|
||||
@@ -152,6 +163,8 @@ def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=pr
|
||||
command = ["run", "--rm", "--user", f"{os.getuid()}:{os.getgid()}",
|
||||
"-v", f"{app}:/src:ro", "-v", f"{work}:/out",
|
||||
"-v", "pipelines-flutter-pub:/home/builder/.pub-cache"]
|
||||
if kind == "linux":
|
||||
command += ["--platform", "linux/amd64"]
|
||||
if kind == "apk":
|
||||
command += ["--platform", "linux/amd64",
|
||||
"-v", "pipelines-flutter-gradle:/home/builder/.gradle",
|
||||
@@ -165,6 +178,8 @@ def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=pr
|
||||
# this avoids circular hashing while keeping the compiled app and
|
||||
# its published metadata on the same identity.
|
||||
build_arguments += (f"--dart-define=PIPELINES_WEB_BUILD_ID={web_build_id(key)}",)
|
||||
if kind == "linux":
|
||||
build_arguments += (f"--dart-define=PIPELINES_NATIVE_BUILD_CODE={built // 60}",)
|
||||
if kind == "apk":
|
||||
# Android installs only a higher build number over the last one, so
|
||||
# each build is stamped when it is made (minutes since the epoch);
|
||||
@@ -172,6 +187,9 @@ def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=pr
|
||||
code = built // 60
|
||||
stamp = (f"--build-number={code}", f"--build-name=0.1.{code}")
|
||||
docker(runner, *command, tag, "pipelines-app-build", kind, *build_arguments, *stamp)
|
||||
if kind == "linux" and not ((work / "pipelines-app").is_file() and
|
||||
(work / "data/flutter_assets").is_dir() and (work / "lib").is_dir()):
|
||||
raise RuntimeError("Linux build did not produce its complete executable/data/lib bundle")
|
||||
if kind == "web":
|
||||
(work / "release.json").write_text(json.dumps(web_release_metadata(key)) + "\n")
|
||||
(work / ".complete").write_text(json.dumps({"key": key, "built": built}) + "\n")
|
||||
@@ -270,11 +288,29 @@ def print_web_urls(manifest, lan_host=None):
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("kind", choices=("web", "apk"))
|
||||
parser.add_argument("kind", choices=("web", "apk", "linux", "macos"))
|
||||
parser.add_argument("--prefix", type=Path, default=DEFAULT_PREFIX)
|
||||
parser.add_argument("--server-url", help="APK default server (default: this installation's web address)")
|
||||
parser.add_argument("--notes", default="", help="APK release notes shown in Check for updates")
|
||||
parser.add_argument("--publish", action="store_true", help="Publish desktop archive and update feed to this installation")
|
||||
parser.add_argument("--output", type=Path, help="Desktop archive output directory (default: build cache)")
|
||||
parser.add_argument("--flutter", help="Native Flutter executable for macOS (or PIPELINES_FLUTTER/PATH)")
|
||||
args = parser.parse_args(argv)
|
||||
if args.kind in ("linux", "macos"):
|
||||
spec = importlib.util.spec_from_file_location("pipelines_desktop_build", Path(__file__).with_name("app_desktop_build.py"))
|
||||
desktop = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(desktop)
|
||||
bundle, archive = desktop.build_desktop(args.kind, app=APP, cache=default_cache(), runner=subprocess.run,
|
||||
source_digest=digest, docker_build=build, docker_ready=docker_available,
|
||||
server_url=args.server_url, flutter=args.flutter, output=args.output,
|
||||
prune_cache=prune)
|
||||
if args.publish:
|
||||
manifest = load_manifest(args.prefix)
|
||||
updates = (manifest.get("web") or {}).get("updates")
|
||||
if not updates:
|
||||
raise ValueError("This installation has no app update directory; rerun ./install")
|
||||
desktop.publish_desktop(args.kind, bundle, archive, Path(updates), notes=args.notes)
|
||||
return
|
||||
if not docker_available():
|
||||
raise RuntimeError("Docker is required to build the app; start Docker and retry")
|
||||
if args.kind == "apk":
|
||||
|
||||
Reference in New Issue
Block a user