Skip to content

Commit

Permalink
Prepare for pruning output directories
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Aug 12, 2024
1 parent eeead9f commit 5ebe393
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
6 changes: 6 additions & 0 deletions ifgen/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
def create_common_test(task: GenerateTask) -> None:
"""Create a unit test for the enum string-conversion methods."""

if task.is_python:
return

with unit_test_boilerplate(task, declare_namespace=True) as writer:
writer.cpp_comment("TODO.")


def create_common(task: GenerateTask) -> None:
"""Create a unit test for the enum string-conversion methods."""

if task.is_python:
return

streams = task.stream_implementation

includes = [
Expand Down
3 changes: 3 additions & 0 deletions ifgen/enum/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
def enum_source(task: GenerateTask, writer: IndentedFileWriter) -> None:
"""Create a source file for an enumeration."""

if task.is_python:
return

enum_to_string_function(task, writer, task.instance["use_map"])
writer.empty()
string_to_enum_function(task, writer, task.instance["use_map"])
Expand Down
3 changes: 3 additions & 0 deletions ifgen/enum/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def unit_test_body(task: GenerateTask, writer: IndentedFileWriter) -> None:
def create_enum_test(task: GenerateTask) -> None:
"""Create a unit test for the enum string-conversion methods."""

if task.is_python:
return

if task.instance["unit_test"]:
with unit_test_boilerplate(task) as writer:
unit_test_body(task, writer)
33 changes: 17 additions & 16 deletions ifgen/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,17 @@ def runtime_enum_data(data: dict[str, Any]) -> dict[str, int]:
class Directories(NamedTuple):
"""A collection of directories relevant to code generation outputs."""

config_parts: list[str]
source: Path
output: Path
test_dir: Path

def prune_empty(self) -> None:
"""Attempt to eliminate any empty output directories."""

for path in (self.source, self.output, self.test_dir):
print(path)


class IfgenEnvironment(LoggerMixin):
"""A class for managing stateful information while generating outputs."""
Expand Down Expand Up @@ -119,23 +126,28 @@ def __init__(self, root: Path, config: Config) -> None:
self._register_enums()
self._register_structs()

def prune_empty(self) -> None:
"""Attempt to eliminate any empty output directories."""

for dirs in self.directories.values():
dirs.prune_empty()

def get_dirs(self, langauge: Language) -> Optional[Directories]:
"""Get source, output and test directories."""

result = None

cfg_dir = langauge.cfg_dir_name
if cfg_dir in self.config.data:
source = combine_if_not_absolute(
self.root_path, normalize(*self.config.data[cfg_dir])
)
dirs = self.config.data[cfg_dir]
source = combine_if_not_absolute(self.root_path, normalize(*dirs))
output = combine_if_not_absolute(
source, normalize(*self.config.data["output_dir"])
)
test_dir = combine_if_not_absolute(
source, normalize(*self.config.data["test_dir"])
)
result = Directories(source, output, test_dir)
result = Directories(dirs, source, output, test_dir)

return result

Expand Down Expand Up @@ -198,13 +210,9 @@ def make_path(
language: Language,
from_output: bool = False,
track: bool = True,
alt_dir: Optional[Path] = None,
) -> Path:
"""Make part of a task's path."""

# Actually handle this.
del alt_dir

result = Path(str(generator), f"{name}.{language.header_suffix}")

if from_output:
Expand All @@ -216,17 +224,10 @@ def make_path(
return result

def make_test_path(
self,
name: str,
generator: Generator,
language: Language,
alt_dir: Optional[Path] = None,
self, name: str, generator: Generator, language: Language
) -> Path:
"""Make a path to an interface's unit-test suite."""

# Actually handle this.
del alt_dir

result = self.directories[language].test_dir.joinpath(
str(generator), f"test_{name}.{language.source_suffix}"
)
Expand Down
14 changes: 3 additions & 11 deletions ifgen/generation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ def generate(root: Path, config: Config) -> None:

with ThreadPool() as pool:
for language in languages:

# Load a possible output-directory configuration.
alt_dir = None
cfg_name = language.cfg_dir_name
if config.data.get(cfg_name):
alt_dir = root.joinpath(*config.data[cfg_name])

for generator, methods in GENERATORS.items():
for method in methods:
pool.map(
Expand All @@ -64,12 +57,9 @@ def generate(root: Path, config: Config) -> None:
name,
generator,
language,
alt_dir=alt_dir,
from_output=True,
),
env.make_test_path(
name, generator, language, alt_dir=alt_dir
),
env.make_test_path(name, generator, language),
data,
env,
)
Expand All @@ -78,3 +68,5 @@ def generate(root: Path, config: Config) -> None:
).items()
),
)

env.prune_empty()
3 changes: 0 additions & 3 deletions ifgen/struct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ def enforce_expected_size(
def create_struct(task: GenerateTask) -> None:
"""Create a header file based on a struct definition."""

if task.is_python:
return

with task.boilerplate(
includes=struct_includes(task), json=task.instance.get("json", False)
) as writer:
Expand Down

0 comments on commit 5ebe393

Please sign in to comment.