Skip to content

Commit 030609f

Browse files
committed
build: apply angular bazel ng_module fix to unblock framework
Due to our weird cyclic dependency with the framework repository, we need to apply changes from angular/angular#36971 before the PR can actually land in framework. This is because the changes of that PR fail in the components repo job as we apply patches that conflict with the new changes. At the same time though, we cannot make the components repo compatible until the framework PR landed. We work around this as usually done, by applying the upstream changes through a patch. Then we can resolve conflicts and the framework PR can land. Eventually we can then remove the patch again from the components repo.
1 parent c05a07e commit 030609f

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
diff --git node_modules/@angular/bazel/src/ng_module.bzl node_modules/@angular/bazel/src/ng_module.bzl
2+
index 9480c4b679dc..cf6f8ebaf437 100644
3+
--- node_modules/@angular/bazel/src/ng_module.bzl
4+
+++ node_modules/@angular/bazel/src/ng_module.bzl
5+
@@ -334,8 +334,11 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
6+
"angularCompilerOptions": angular_compiler_options,
7+
})
8+
9+
+def _has_target_angular_summaries(target):
10+
+ return hasattr(target, "angular") and hasattr(target.angular, "summaries")
11+
+
12+
def _collect_summaries_aspect_impl(target, ctx):
13+
- results = depset(target.angular.summaries if hasattr(target, "angular") else [])
14+
+ results = depset(target.angular.summaries if _has_target_angular_summaries(target) else [])
15+
16+
# If we are visiting empty-srcs ts_library, this is a re-export
17+
srcs = ctx.rule.attr.srcs if hasattr(ctx.rule.attr, "srcs") else []
18+
@@ -343,7 +346,7 @@ def _collect_summaries_aspect_impl(target, ctx):
19+
# "re-export" rules should expose all the files of their deps
20+
if not srcs and hasattr(ctx.rule.attr, "deps"):
21+
for dep in ctx.rule.attr.deps:
22+
- if (hasattr(dep, "angular")):
23+
+ if (_has_target_angular_summaries(dep)):
24+
results = depset(dep.angular.summaries, transitive = [results])
25+
26+
return struct(collect_summaries_aspect_result = results)
27+
@@ -588,20 +591,23 @@ def ng_module_impl(ctx, ts_compile_actions):
28+
29+
outs = _expected_outs(ctx)
30+
31+
+ providers["angular"] = {}
32+
+
33+
if is_legacy_ngc:
34+
- providers["angular"] = {
35+
- "summaries": outs.summaries,
36+
- "metadata": outs.metadata,
37+
- }
38+
+ providers["angular"]["summaries"] = outs.summaries
39+
+ providers["angular"]["metadata"] = outs.metadata
40+
providers["ngc_messages"] = outs.i18n_messages
41+
42+
- if is_legacy_ngc and _should_produce_flat_module_outs(ctx):
43+
- if len(outs.metadata) > 1:
44+
+ if _should_produce_flat_module_outs(ctx):
45+
+ # Sanity error if more than one metadata file has been created in the
46+
+ # legacy ngc compiler while a flat module should be produced.
47+
+ if is_legacy_ngc and len(outs.metadata) > 1:
48+
fail("expecting exactly one metadata output for " + str(ctx.label))
49+
50+
providers["angular"]["flat_module_metadata"] = struct(
51+
module_name = ctx.attr.module_name,
52+
- metadata_file = outs.metadata[0],
53+
+ # Metadata files are only generated in the legacy ngc compiler.
54+
+ metadata_file = outs.metadata[0] if is_legacy_ngc else None,
55+
typings_file = outs.bundle_index_typings,
56+
flat_module_out_file = _flat_module_out_file(ctx),
57+
)

tools/postinstall/apply-patches.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const fs = require('fs');
1212
* Version of the post install patch. Needs to be incremented when
1313
* existing patches or edits have been modified.
1414
*/
15-
const PATCH_VERSION = 5;
15+
const PATCH_VERSION = 6;
1616

1717
/** Path to the project directory. */
1818
const projectDir = path.join(__dirname, '../..');
@@ -72,13 +72,13 @@ searchAndReplace(
7272
`$1#\n$2results = depset(dep.angular.metadata, transitive = [results])`,
7373
'node_modules/@angular/bazel/src/ng_module.bzl');
7474
searchAndReplace(
75-
/^((\s*)results = depset\(target.angular.summaries if hasattr\(target, "angular"\) else \[]\))$/m,
76-
`$1#\n$2results = depset(target.angular.metadata if hasattr(target, "angular") else [], transitive = [results])`,
75+
/^((\s*)results = depset\(target.angular\.summaries if _has_target_angular_summaries\(target\) else \[]\))$/m,
76+
`$1#\n$2results = depset(target.angular.metadata if _has_target_angular_summaries(target) else [], transitive = [results])`,
7777
'node_modules/@angular/bazel/src/ng_module.bzl');
7878
// Ensure that "metadata" of transitive dependencies can be collected.
7979
searchAndReplace(
80-
/("metadata": outs.metadata),/,
81-
`$1 + [m for dep in ctx.attr.deps if hasattr(dep, "angular") for m in dep.angular.metadata],`,
80+
/providers\["angular"]\["metadata"] = outs\.metadata/,
81+
`$& + [m for dep in ctx.attr.deps if (hasattr(dep, "angular") and hasattr(dep.angular, "metadata")) for m in dep.angular.metadata]`,
8282
'node_modules/@angular/bazel/src/ng_module.bzl');
8383

8484
// Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1208.
@@ -89,7 +89,15 @@ try {
8989
// Can be removed once @angular/bazel is updated here to include this patch.
9090
// try/catch needed for this the material CI tests to work in angular/repo
9191
applyPatch(path.join(__dirname, './@angular_bazel_ng_module.patch'));
92-
} catch (_) {}
92+
} catch {}
93+
94+
try {
95+
// Temporary patch pre-req for https://github.com/angular/angular/pull/36971.
96+
// Can be removed once @angular/bazel is updated here to include this patch.
97+
// try/catch needed for this as the framework repo has this patch already applied,
98+
// and re-applying again causes an error.
99+
applyPatch(path.join(__dirname, './@angular_bazel_ivy_flat_module.patch'));
100+
} catch {}
93101

94102
// Workaround for https://github.com/angular/angular/issues/33452:
95103
searchAndReplace(/angular_compiler_options = {/, `$&
@@ -177,7 +185,8 @@ function searchAndReplace(search, replacement, relativeFilePath) {
177185
fileEdits.push(originalContent => {
178186
const newFileContent = originalContent.replace(search, replacement);
179187
if (originalContent === newFileContent) {
180-
throw Error(`Could not perform replacement in: ${filePath}.`);
188+
throw Error(`Could not perform replacement in: ${filePath}.\n` +
189+
`Searched for pattern: ${search}`);
181190
}
182191
return newFileContent;
183192
});

0 commit comments

Comments
 (0)