|
26 | 26 | _BUILD_DIR = "__build"
|
27 | 27 | _DEP_FILES_DIR = paths.join(_BUILD_DIR, "__dep_files")
|
28 | 28 | _DEP_INFO_FILE = paths.join(_DEP_FILES_DIR, "app.info.dep")
|
| 29 | +_GENERATED_DIR = paths.join(_BUILD_DIR, "__generated") |
29 | 30 |
|
30 | 31 | BuildEnvironment = record(
|
31 | 32 | includes = field(IncludesMapping, {}),
|
@@ -86,21 +87,16 @@ def _prepare_build_environment(
|
86 | 87 | beams = beams,
|
87 | 88 | )
|
88 | 89 |
|
89 |
| -def _generated_source_artifacts(ctx: AnalysisContext, toolchain: Toolchain, name: str) -> PathArtifactMapping: |
| 90 | +def _generated_source_artifacts(ctx: AnalysisContext, toolchain: Toolchain) -> list[Artifact]: |
90 | 91 | """Generate source output artifacts and build actions for generated erl files."""
|
91 | 92 |
|
92 |
| - def build(src, custom_include_opt): |
93 |
| - return _build_xyrl( |
94 |
| - ctx, |
95 |
| - toolchain, |
96 |
| - src, |
97 |
| - custom_include_opt, |
98 |
| - ctx.actions.declare_output(generated_erl_path(name, src)), |
99 |
| - ) |
100 |
| - |
101 |
| - yrl_outputs = {module_name(src): build(src, "yrl_includefile") for src in ctx.attrs.srcs if _is_yrl(src)} |
102 |
| - xrl_outputs = {module_name(src): build(src, "xrl_includefile") for src in ctx.attrs.srcs if _is_xrl(src)} |
103 |
| - return yrl_outputs | xrl_outputs |
| 93 | + results = [] |
| 94 | + for src in ctx.attrs.srcs: |
| 95 | + if _is_yrl(src): |
| 96 | + results.append(_build_xyrl(ctx, toolchain, src, "yrl_includefile")) |
| 97 | + elif _is_xrl(src): |
| 98 | + results.append(_build_xyrl(ctx, toolchain, src, "xrl_includefile")) |
| 99 | + return results |
104 | 100 |
|
105 | 101 | # mutates build_environment in place
|
106 | 102 | def _generate_include_artifacts(
|
@@ -245,9 +241,9 @@ def _build_xyrl(
|
245 | 241 | ctx: AnalysisContext,
|
246 | 242 | toolchain: Toolchain,
|
247 | 243 | xyrl: Artifact,
|
248 |
| - custom_include_opt: str, |
249 |
| - output: Artifact) -> Artifact: |
| 244 | + custom_include_opt: str) -> Artifact: |
250 | 245 | """Generate an erl file out of an xrl or yrl input file."""
|
| 246 | + output = ctx.actions.declare_output(_GENERATED_DIR, "{}.erl".format(module_name(xyrl))) |
251 | 247 | erlc = toolchain.otp_binaries.erlc
|
252 | 248 | custom_include = getattr(ctx.attrs, custom_include_opt, None)
|
253 | 249 | cmd = cmd_args(erlc)
|
@@ -446,14 +442,6 @@ def _preserved_opts(opts: list[str]) -> cmd_args:
|
446 | 442 | joined = cmd_args(preserved, delimiter = ", ")
|
447 | 443 | return cmd_args(joined, format = "{options, [{}]}")
|
448 | 444 |
|
449 |
| -def generated_erl_path(appname: str, src: Artifact) -> str: |
450 |
| - """The output path for generated erl files.""" |
451 |
| - return paths.join( |
452 |
| - _BUILD_DIR, |
453 |
| - "__generated_%s" % (appname,), |
454 |
| - "%s.erl" % (module_name(src),), |
455 |
| - ) |
456 |
| - |
457 | 445 | def module_name(in_file: Artifact) -> str:
|
458 | 446 | """ Returns the basename of the artifact without extension """
|
459 | 447 | end = in_file.basename.rfind(".")
|
|
0 commit comments