Skip to content

Commit 6c3349e

Browse files
devversionandrewseguin
authored andcommitted
build: apply angular bazel ng_module fix to unblock framework (#19276)
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 771b4ba commit 6c3349e

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, '../..');
@@ -86,13 +86,13 @@ searchAndReplace(
8686
`$1#\n$2results = depset(dep.angular.metadata, transitive = [results])`,
8787
'node_modules/@angular/bazel/src/ng_module.bzl');
8888
searchAndReplace(
89-
/^((\s*)results = depset\(target.angular.summaries if hasattr\(target, "angular"\) else \[]\))$/m,
90-
`$1#\n$2results = depset(target.angular.metadata if hasattr(target, "angular") else [], transitive = [results])`,
89+
/^((\s*)results = depset\(target.angular\.summaries if _has_target_angular_summaries\(target\) else \[]\))$/m,
90+
`$1#\n$2results = depset(target.angular.metadata if _has_target_angular_summaries(target) else [], transitive = [results])`,
9191
'node_modules/@angular/bazel/src/ng_module.bzl');
9292
// Ensure that "metadata" of transitive dependencies can be collected.
9393
searchAndReplace(
94-
/("metadata": outs.metadata),/,
95-
`$1 + [m for dep in ctx.attr.deps if hasattr(dep, "angular") for m in dep.angular.metadata],`,
94+
/providers\["angular"]\["metadata"] = outs\.metadata/,
95+
`$& + [m for dep in ctx.attr.deps if (hasattr(dep, "angular") and hasattr(dep.angular, "metadata")) for m in dep.angular.metadata]`,
9696
'node_modules/@angular/bazel/src/ng_module.bzl');
9797

9898
// Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1208.
@@ -103,7 +103,15 @@ try {
103103
// Can be removed once @angular/bazel is updated here to include this patch.
104104
// try/catch needed for this the material CI tests to work in angular/repo
105105
applyPatch(path.join(__dirname, './@angular_bazel_ng_module.patch'));
106-
} catch (_) {}
106+
} catch {}
107+
108+
try {
109+
// Temporary patch pre-req for https://github.com/angular/angular/pull/36971.
110+
// Can be removed once @angular/bazel is updated here to include this patch.
111+
// try/catch needed for this as the framework repo has this patch already applied,
112+
// and re-applying again causes an error.
113+
applyPatch(path.join(__dirname, './@angular_bazel_ivy_flat_module.patch'));
114+
} catch {}
107115

108116
// Workaround for https://github.com/angular/angular/issues/33452:
109117
searchAndReplace(/angular_compiler_options = {/, `$&
@@ -191,7 +199,8 @@ function searchAndReplace(search, replacement, relativeFilePath) {
191199
fileEdits.push(originalContent => {
192200
const newFileContent = originalContent.replace(search, replacement);
193201
if (originalContent === newFileContent) {
194-
throw Error(`Could not perform replacement in: ${filePath}.`);
202+
throw Error(`Could not perform replacement in: ${filePath}.\n` +
203+
`Searched for pattern: ${search}`);
195204
}
196205
return newFileContent;
197206
});

0 commit comments

Comments
 (0)