Skip to content

Commit

Permalink
Port over some changes from #798
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgodbolt committed Dec 9, 2024
1 parent 36e04be commit d43ba1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
21 changes: 12 additions & 9 deletions bin/lib/ce_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

from lib.amazon_properties import get_properties_compilers_and_libraries
from lib.config_safe_loader import ConfigSafeLoader
from lib.installable.installable import Installable
from lib.installation import installers_for
from lib.installation_context import InstallationContext
from lib.installable.installable import Installable
from lib.library_yaml import LibraryYaml

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -91,10 +91,10 @@ def filter_aggregate(filters: list, installable: Installable, filter_match_all:
return all(filter_generator) if filter_match_all else any(filter_generator)


def squash_mount_check(rootfolder, subdir, context):
for filename in os.listdir(os.path.join(rootfolder, subdir)):
def squash_mount_check(rootfolder: Path, subdir: str, context: CliContext) -> None:
for filename in os.listdir(rootfolder / subdir):
if filename.endswith(".img"):
checkdir = Path(os.path.join("/opt/compiler-explorer/", subdir, filename[:-4]))
checkdir = Path("/opt/compiler-explorer/") / subdir / filename[:-4]
if not checkdir.exists():
_LOGGER.error("Missing mount point %s", checkdir)
else:
Expand Down Expand Up @@ -215,7 +215,7 @@ def cli(
file_handler.setFormatter(formatter)
root_logger.addHandler(file_handler)
if not log or log_to_console:
console_handler = logging.StreamHandler(sys.stdout)
console_handler = logging.StreamHandler(sys.stderr)
console_handler.setFormatter(formatter)
root_logger.addHandler(console_handler)
context = InstallationContext(
Expand All @@ -242,12 +242,15 @@ def cli(

@cli.command(name="list")
@click.pass_obj
@click.option("--json", is_flag=True, help="Output in JSON format")
@click.option("--installed-only", is_flag=True, help="Only output installed targets")
@click.argument("filter_", metavar="FILTER", nargs=-1)
def list_cmd(context: CliContext, filter_: List[str]):
def list_cmd(context: CliContext, filter_: List[str], json: bool, installed_only: bool):
"""List installation targets matching FILTER."""
print("Installation candidates:")
for installable in context.get_installables(filter_):
print(installable.name)
if installed_only and not installable.is_installed():
continue
print(installable.to_json() if json else installable.name)
_LOGGER.debug(installable)


Expand Down Expand Up @@ -385,7 +388,7 @@ def squash_check(context: CliContext, filter_: List[str], image_dir: Path):
exit(1)

for installable in context.get_installables(filter_):
destination = Path(image_dir / f"{installable.install_path}.img")
destination = image_dir / f"{installable.install_path}.img"
if installable.nightly_like:
if destination.exists():
_LOGGER.error("Found squash: %s for nightly", installable.name)
Expand Down
12 changes: 10 additions & 2 deletions bin/lib/installable/installable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import logging
import os
import re
Expand All @@ -24,6 +25,8 @@

nightlies: NightlyVersions = NightlyVersions(_LOGGER)

SimpleJsonType = (int, float, str, bool)


class Installable:
_check_link: Optional[Callable[[], bool]]
Expand Down Expand Up @@ -60,6 +63,12 @@ def __init__(self, install_context: InstallationContext, config: Dict[str, Any])
self._logger = logging.getLogger(self.name)
self.install_path_symlink = self.config_get("symlink", False)

def to_json_dict(self) -> Dict[str, Any]:
return {key: value for key, value in self.__dict__.items() if isinstance(value, SimpleJsonType)}

def to_json(self) -> str:
return json.dumps(self.to_json_dict())

def _resolve(self, all_installables: Dict[str, Installable]):
try:
self.depends = [all_installables[dep] for dep in self.depends_by_name]
Expand Down Expand Up @@ -283,10 +292,9 @@ def squash_to(self, destination_image: Path):
self._logger.info("Squashing %s...", source_folder)
self.install_context.check_call(
[
"/usr/bin/mksquashfs",
"mksquashfs",
str(source_folder),
str(temp_image),
"-all-root",
"-progress",
"-comp",
"zstd",
Expand Down

0 comments on commit d43ba1b

Please sign in to comment.