Skip to content

Commit de9168c

Browse files
Added build-all command
1 parent 283eea2 commit de9168c

File tree

2 files changed

+165
-1
lines changed

2 files changed

+165
-1
lines changed

wigwam/cli/build_commands.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from typing import List
44

55
from ..commands import (
6+
build_all,
67
cmake_install,
78
compile_cmake,
89
configure_cmake,
910
copy_dir,
1011
get_archive,
1112
make_distrib,
1213
)
14+
from ..defaults import universal_tag_prefix
1315
from ._utils import add_tag_argument, help_formatter
1416

1517

@@ -26,6 +28,7 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
2628
cmake-config,
2729
cmake-compile,
2830
cmake-install,
31+
build-all,
2932
and more are being added.
3033
3134
Parameters
@@ -88,7 +91,7 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
8891
archive_parser = subparsers.add_parser(
8992
"get-archive",
9093
parents=[setup_params, archive_params, no_cache_params],
91-
help="Set up the GitHub repository image, in [USER]/[REPO_NAME] format.",
94+
help="Set up the GitHub repository image.",
9295
formatter_class=help_formatter,
9396
)
9497
add_tag_argument(parser=archive_parser, default="repo")
@@ -170,6 +173,52 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
170173
' Defaults to "build-installed".',
171174
)
172175

176+
parser_build_all = subparsers.add_parser(
177+
"build-all",
178+
parents=[config_params, no_cache_params],
179+
help="Performs the complete compilation process, from initial GitHub checkout "
180+
"to installation.",
181+
formatter_class=help_formatter,
182+
)
183+
parser_build_all.add_argument(
184+
"--base",
185+
"-b",
186+
type=str,
187+
default="setup-mamba-dev",
188+
help='The name of the parent Docker image. Default is "setup-mamba-dev".',
189+
)
190+
parser_build_all.add_argument(
191+
"--tag",
192+
"-t",
193+
default="build",
194+
type=str,
195+
help="The sub-prefix of the Docker images to be created. Generated images will "
196+
f'have tags fitting "{universal_tag_prefix()}-[TAG]-*". Default: "build"',
197+
)
198+
parser_build_all.add_argument(
199+
"--copy-path",
200+
"-p",
201+
metavar="FILEPATH",
202+
type=str,
203+
default=None,
204+
help="The path to be copied to the image. If used, no github image will be "
205+
"copied. Defaults to None.",
206+
)
207+
parser_build_all.add_argument(
208+
"--archive-url",
209+
type=str,
210+
metavar="GIT_ARCHIVE",
211+
help='The URL of the Git archive to be fetched. Must be a "tar.gz" file.'
212+
"Ignored if --copy-path is used.",
213+
)
214+
parser_build_all.add_argument(
215+
"--directory",
216+
type=Path,
217+
default=Path("/src"),
218+
help="The path to place the contents of the Git archive or copied directory "
219+
"into on the image.",
220+
)
221+
173222

174223
def build_command_names() -> List[str]:
175224
"""Returns a list of all build command names."""
@@ -180,6 +229,7 @@ def build_command_names() -> List[str]:
180229
"cmake-compile",
181230
"cmake-install",
182231
"make-distrib",
232+
"build-all",
183233
]
184234

185235

@@ -196,3 +246,5 @@ def run_build(args: argparse.Namespace, command: str) -> None:
196246
cmake_install(**vars(args))
197247
elif command == "make-distrib":
198248
make_distrib(**vars(args))
249+
elif command == "build-all":
250+
build_all(**vars(args))

wigwam/commands.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,118 @@ def make_distrib(tag: str, base: str, source_tag: str, no_cache: bool = False) -
303303
return Image.build(tag=tag, dockerfile_string=dockerfile, no_cache=no_cache)
304304

305305

306+
def build_all(
307+
tag: str,
308+
base: str,
309+
copy_path: os.PathLike | None,
310+
archive_url: str | None,
311+
directory: os.PathLike,
312+
build_type: str,
313+
no_cuda: bool,
314+
no_cache: bool = False,
315+
) -> dict[str, Image]:
316+
"""
317+
Fully compiles and builds a Git repo with cmake.
318+
319+
Parameters
320+
----------
321+
tag : str
322+
The image tag prefix.
323+
base : str
324+
The base image tag.
325+
copy_path : str
326+
The path to a directory to copy to an image.
327+
archive_url : str or None
328+
The URL of the Git archive to install on an image. No archive will be installed
329+
if `copy_dir` is given.
330+
directory : str
331+
The path to place the contents of the Git archive or copied directory to.
332+
build_type : str
333+
The CMake build type. See
334+
`here <https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html>`_
335+
for possible values.
336+
no_cuda : bool
337+
If True, build without CUDA.
338+
no_cache : bool, optional
339+
Run Docker build with no cache if True. Defaults to False.
340+
341+
Returns
342+
-------
343+
dict[str, Image]
344+
A dict of images produced by this process.
345+
"""
346+
347+
prefixed_tag: str = prefix_image_tag(tag)
348+
prefixed_base_tag: str = prefix_image_tag(base)
349+
350+
images: dict[str, Image] = {}
351+
352+
# If the user has indicated a path to copy, the code should copy that.
353+
# Otherwise, the code should fetch a git repository.
354+
is_insert = copy_path is not None
355+
356+
initial_tag: str = ""
357+
if is_insert:
358+
assert isinstance(copy_path, str)
359+
path_absolute = os.path.abspath(copy_path)
360+
if os.path.isdir(copy_path):
361+
top_dir = os.path.basename(path_absolute)
362+
else:
363+
top_dir = os.path.basename(os.path.dirname(path_absolute))
364+
365+
insert_tag = f"{prefixed_tag}-file-{top_dir}"
366+
insert_image = copy_dir(
367+
base=prefixed_base_tag,
368+
tag=insert_tag,
369+
directory=directory,
370+
target_path=copy_path,
371+
no_cache=no_cache,
372+
)
373+
images[insert_tag] = insert_image
374+
initial_tag = insert_tag
375+
else:
376+
git_repo_tag = f"{prefixed_tag}-git-repo"
377+
assert archive_url is not None
378+
379+
git_repo_image = get_archive(
380+
base=prefixed_base_tag,
381+
tag=git_repo_tag,
382+
archive_url=archive_url,
383+
directory=directory,
384+
no_cache=no_cache,
385+
)
386+
images[git_repo_tag] = git_repo_image
387+
initial_tag = git_repo_tag
388+
389+
configure_tag = f"{prefixed_tag}-configured"
390+
configure_image = configure_cmake(
391+
tag=configure_tag,
392+
base=initial_tag,
393+
build_type=build_type,
394+
no_cuda=no_cuda,
395+
no_cache=no_cache,
396+
)
397+
images[configure_tag] = configure_image
398+
399+
build_tag = f"{prefixed_tag}-built"
400+
build_image = compile_cmake(
401+
tag=build_tag,
402+
base=configure_tag,
403+
no_cache=no_cache,
404+
)
405+
images[build_tag] = build_image
406+
407+
install_tag = f"{prefixed_tag}-installed"
408+
install_image = cmake_install(
409+
tag=install_tag,
410+
base=build_tag,
411+
no_cache=no_cache,
412+
)
413+
images[install_tag] = install_image
414+
415+
return images
416+
417+
306418
def test(
307419
tag: str,
308420
output_xml: os.PathLike[str] | str,

0 commit comments

Comments
 (0)