Skip to content

Commit

Permalink
Always build non-cached generators in work_root
Browse files Browse the repository at this point in the history
Before this change, non-cached generators were only built in work_root
if --no-export was enabled which caused race conditions when doing
multiple parallel builds.

With this change we also don't remove the temporary generator work
directory as that can be useful to have around and will be cleaned
out on subsequent builds to the same work_root anyway.
  • Loading branch information
olofk committed Dec 20, 2024
1 parent 6528646 commit 1e07014
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
23 changes: 3 additions & 20 deletions fusesoc/edalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def extract_generators(self):
def run_generators(self):
"""Run all generators"""
self._resolved_or_generated_cores = []
self._generated_core_dirs_to_remove = []
for core in self.cores:
logger.debug("Running generators in " + str(core.name))
core_flags = self._core_flags(core)
Expand All @@ -151,7 +150,7 @@ def run_generators(self):
ttptttg_data,
core,
self.generators,
self.work_root if not self.export_root else None,
self.work_root,
resolve_env_vars=self.resolve_env_vars,
)
try:
Expand All @@ -166,8 +165,6 @@ def run_generators(self):
core.direct_deps.append(str(gen_core.name))
gen_core.pos = _ttptttg.pos
self._resolved_or_generated_cores.append(gen_core)
if self.export_root and not _ttptttg.is_cacheable():
self._generated_core_dirs_to_remove.append(gen_core.core_root)

def export(self):
for core in self.cores:
Expand All @@ -186,9 +183,6 @@ def export(self):
src = os.path.join(files_root, file["name"])
self._copyto(src, file.get("copyto"))

# Clean up ttptttg temporary directories
self.clean_temp_dirs()

def _copyto(self, src, name):
dst = os.path.join(self.work_root, name)
os.makedirs(os.path.dirname(dst), exist_ok=True)
Expand Down Expand Up @@ -304,11 +298,6 @@ def create_edam(self):
for snippet in first_snippets + snippets + last_snippets:
merge_dict(self.edam, snippet)

def clean_temp_dirs(self):
for coredir in self._generated_core_dirs_to_remove:
logger.debug(f"Removing {coredir} ttptttg temporary directory")
shutil.rmtree(coredir)

def _build_parser(self, backend_class, edam):
typedict = {
"bool": {"type": str2bool, "nargs": "?", "const": True},
Expand Down Expand Up @@ -520,9 +509,7 @@ def to_yaml(self, edam_file):


class Ttptttg:
def __init__(
self, ttptttg, core, generators, temp_gen_root, resolve_env_vars=False
):
def __init__(self, ttptttg, core, generators, work_root, resolve_env_vars=False):
generator_name = ttptttg["generator"]
if not generator_name in generators:
raise RuntimeError(
Expand All @@ -535,11 +522,7 @@ def __init__(
self.name = ttptttg["name"]
self.pos = ttptttg["pos"]
self.gen_name = generator_name
self.gen_root = (
temp_gen_root
if temp_gen_root and not self.is_cacheable()
else self.core.cache_root
)
self.gen_root = self.core.cache_root if self.is_cacheable() else work_root
self.resolve_env_vars = resolve_env_vars
parameters = ttptttg["config"]

Expand Down
3 changes: 0 additions & 3 deletions tests/test_edalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ def test_generators():
assert core_name in name_to_core
core = name_to_core[core_name]

# ttptttg temporary directory should be removed by now
assert not os.path.isdir(core.core_root)

# Test generator input cache and file_input_params
core_name = f"::generate-testgenerate_with_cache:0"
assert core_name in name_to_core
Expand Down

0 comments on commit 1e07014

Please sign in to comment.