Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate light app gen #23293

Merged
merged 3 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,25 @@
import sys
import subprocess
import logging
from dataclasses import dataclass

CHIP_ROOT_DIR = os.path.realpath(
os.path.join(os.path.dirname(__file__), '../..'))


@dataclass(eq=True, frozen=True)
class ZapDistinctOutput:
"""Defines the properties that determine if some output seems unique or
not, for the purposes of detecting codegen overlap.

Not perfect, since separate templates may use the same file names, but
better than nothing.
"""

input_template: str
output_directory: str


class ZAPGenerateTarget:
def __init__(self, zap_config, template=None, output_dir=None):
self.script = './scripts/tools/zap/generate.py'
Expand All @@ -38,6 +52,9 @@ def __init__(self, zap_config, template=None, output_dir=None):
else:
self.output_dir = None

def distinct_output(self):
return ZapDistinctOutput(input_template=self.template, output_directory=self.output_dir)
andy31415 marked this conversation as resolved.
Show resolved Hide resolved

def log_command(self):
"""Log the command that will get run for this target
"""
Expand Down Expand Up @@ -135,10 +152,17 @@ def getGlobalTemplatesTargets():
logging.info("Found example %s (via %s)" %
(example_name, str(filepath)))

generate_subdir = example_name

# Special casing lighting app because separate folders
if example_name == "lighting-app":
if 'nxp' in str(filepath):
generate_subdir = f"{example_name}/nxp"

# The name zap-generated is to make includes clear by using
# a name like <zap-generated/foo.h>
output_dir = os.path.join(
'zzz_generated', example_name, 'zap-generated')
'zzz_generated', generate_subdir, 'zap-generated')
targets.append(ZAPGenerateTarget(filepath, output_dir=output_dir))

targets.append(ZAPGenerateTarget(
Expand All @@ -162,19 +186,6 @@ def getTestsTemplatesTargets(test_target):
}
}

# Place holder has apps within each build
for filepath in Path('./examples/placeholder').rglob('*.zap'):
example_name = filepath.as_posix()
example_name = example_name[example_name.index(
'apps/') + len('apps/'):]
example_name = example_name[:example_name.index('/')]

templates[example_name] = {
'zap': filepath,
'template': 'examples/placeholder/templates/templates.json',
'output_dir': os.path.join('zzz_generated', 'placeholder', example_name, 'zap-generated')
}

targets = []
for key, target in templates.items():
if test_target == 'all' or test_target == key:
Expand Down Expand Up @@ -223,6 +234,22 @@ def getTargets(type, test_target):
for target in targets:
target.log_command()

# validate that every target as a DISTINCT directory (we had bugs here
# for various examples duplicating zap files)
distinct_outputs = set()
for target in targets:
o = target.distinct_output()

if o in distinct_outputs:
logging.error("Same output %r:" % o)
for t in targets:
if t.distinct_output() == o:
logging.error(" %s" % t.zap_config)

raise Exception("Duplicate/overlapping output directory: %r" % o)

distinct_outputs.add(o)

return targets


Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.