Copy build tree

Former-commit-id: 3b55d012be
This commit is contained in:
David Boreham 2023-02-21 06:56:33 -07:00
parent 02335795fb
commit c769fce491

View File

@ -20,6 +20,7 @@
import os import os
import sys import sys
from shutil import rmtree, copytree
from decouple import config from decouple import config
import click import click
import importlib.resources import importlib.resources
@ -65,11 +66,17 @@ def command(ctx, include, exclude):
else: else:
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc")) dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
if not quiet: build_root_path = os.path.join(dev_root_path, "build-trees")
if verbose:
print(f'Dev Root is: {dev_root_path}') print(f'Dev Root is: {dev_root_path}')
if not os.path.isdir(dev_root_path): if not os.path.isdir(dev_root_path):
print('Dev root directory doesn\'t exist, creating') print('Dev root directory doesn\'t exist, creating')
os.makedirs(dev_root_path)
if not os.path.isdir(dev_root_path):
print('Build root directory doesn\'t exist, creating')
os.makedirs(build_root_path)
# See: https://stackoverflow.com/a/20885799/1701505 # See: https://stackoverflow.com/a/20885799/1701505
from . import data from . import data
@ -92,7 +99,19 @@ def command(ctx, include, exclude):
print(f"Building npm package: {package}") print(f"Building npm package: {package}")
repo_dir = package repo_dir = package
repo_full_path = os.path.join(dev_root_path, repo_dir) repo_full_path = os.path.join(dev_root_path, repo_dir)
# TODO: make the npm registry url configurable. # Copy the repo and build that to avoid propagating JS tooling file changes back into the cloned repo
repo_copy_path = os.path.join(build_root_path, repo_dir)
# First delete any old build tree
if os.path.isdir(repo_copy_path):
if verbose:
print(f"Deleting old build tree: {repo_copy_path}")
if not dry_run:
rmtree(repo_copy_path)
# Now copy the repo into the build tree location
if verbose:
print(f"Copying build tree from: {repo_full_path} to: {repo_copy_path}")
if not dry_run:
copytree(repo_full_path, repo_copy_path)
build_command = ["sh", "-c", f"cd /workspace && build-npm-package-local-dependencies.sh {npm_registry_url}"] build_command = ["sh", "-c", f"cd /workspace && build-npm-package-local-dependencies.sh {npm_registry_url}"]
if not dry_run: if not dry_run:
if verbose: if verbose:
@ -107,7 +126,7 @@ def command(ctx, include, exclude):
envs=envs, envs=envs,
# TODO: detect this host name in npm_registry_url rather than hard-wiring it # TODO: detect this host name in npm_registry_url rather than hard-wiring it
add_hosts=[("gitea.local", "host-gateway")], add_hosts=[("gitea.local", "host-gateway")],
volumes=[(repo_full_path, "/workspace")], volumes=[(repo_copy_path, "/workspace")],
command=build_command command=build_command
) )
# Note that although the docs say that build_result should contain # Note that although the docs say that build_result should contain