Skip to content

Commit

Permalink
introduce settings.get_llvm_build_dir with automatic fallback/lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed Sep 27, 2024
1 parent 3bd8a58 commit a777a30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
19 changes: 7 additions & 12 deletions seal5/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,7 @@ def prepare_environment(self):
cdsl2llvm_build_dir = None
integrated_pattern_gen = self.settings.tools.pattern_gen.integrated
if integrated_pattern_gen:
default_config_name = self.settings.llvm.default_config
non_default_config_names = [
config_name for config_name in self.settings.llvm.configs.keys() if config_name != default_config_name
]
config_names = [default_config_name, *non_default_config_names]
for config_name in config_names:
cdsl2llvm_build_dir = self.settings.build_dir / config_name
if cdsl2llvm_build_dir.is_dir():
break
cdsl2llvm_build_dir = self.settings.get_llvm_build_dir(fallback=True, check=False)
else:
cdsl2llvm_build_dir = self.settings.deps_dir / "cdsl2llvm" / "llvm" / "build"
if cdsl2llvm_build_dir.is_dir():
Expand Down Expand Up @@ -506,7 +498,7 @@ def build(self, config=None, target="all", verbose: bool = False, **kwargs):
cmake_options = llvm_config.options
llvm.build_llvm(
Path(self.settings.directory),
self.settings.build_dir / config,
self.settings.get_llvm_build_dir(config=config, fallback=True, check=False),
cmake_options=cmake_options,
target=target,
use_ninja=self.settings.llvm.ninja or kwargs.get("use_ninja", False),
Expand Down Expand Up @@ -538,7 +530,7 @@ def install(self, dest: Optional[Union[str, Path]] = None, config=None, verbose:
cmake_options = llvm_config.options
llvm.build_llvm(
Path(self.settings.directory),
self.settings.build_dir / config,
self.settings.get_llvm_build_dir(config=config, fallback=True, check=True),
cmake_options=cmake_options,
use_ninja=self.settings.llvm.ninja or kwargs.get("use_ninja", False),
enable_ccache=self.settings.llvm.ccache or kwargs.get("enable_ccache", False),
Expand Down Expand Up @@ -792,7 +784,10 @@ def test(
config = self.settings.llvm.default_config
test_paths = self.settings.test.paths
failing_tests = llvm.test_llvm(
self.directory / "llvm" / "test", self.settings.build_dir / config, test_paths, verbose=verbose
self.directory / "llvm" / "test",
self.settings.get_llvm_build_dir(config=config, fallback=True, check=True),
test_paths,
verbose=verbose
)
if len(failing_tests) > 0:
logger.error("%d tests failed: %s", len(failing_tests), ", ".join(failing_tests))
Expand Down
3 changes: 1 addition & 2 deletions seal5/pass_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,8 +1461,7 @@ def convert_llvmir_to_gmir(
cdsl2llvm_build_dir = None
integrated_pattern_gen = settings.tools.pattern_gen.integrated
if integrated_pattern_gen:
config = settings.llvm.default_config
cdsl2llvm_build_dir = str(settings.build_dir / config)
cdsl2llvm_build_dir = str(settings.get_llvm_build_dir(fallback=True, check=True))
else:
cdsl2llvm_build_dir = str(settings.deps_dir / "cdsl2llvm" / "llvm" / "build")
# TODO: migrate with pass to cmdline backend
Expand Down
20 changes: 20 additions & 0 deletions seal5/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,26 @@ def build_dir(self):
"""Seal5 build_dir getter."""
return self._meta_dir / "build"

def get_llvm_build_dir(self, config: Optional[str] = None, fallback: bool = True, check: bool = False):
if config is None:
# check if default_exists
assert self.llvm is not None
config = self.llvm.default_config

assert config is not None, "Could not resolve LLVM build dir"

llvm_build_dir = self.build_dir / config

if not llvm_build_dir.is_dir():
assert fallback, f"LLVM build dir {llvm_build_dir} does not exist and fallback is disabled."
# Look for non-empty subdirs for .seal5/build
candidates = [f for f in self.build_dir.iterdir() if f.is_dir() and any(f.iterdir())]
if len(candidates) > 0:
llvm_build_dir = candidates[0]
if check:
assert llvm_build_dir.is_dir(), f"LLVM build dir does not exist: {llvm_build_dir}"
return llvm_build_dir

@property
def install_dir(self):
"""Seal5 install_dir getter."""
Expand Down

0 comments on commit a777a30

Please sign in to comment.