Skip to content

Commit 4641fc7

Browse files
devversionthePunderWoman
authored andcommitted
build: wire up new CLDR generation tool within Bazel (angular#42230)
Introduces a few Starlark macros for running the new Bazel CLDR generation tool. Wires up the new tool so that locales are generated properly. Also updates the existing `closure-locale` file to match the new output generated by the Bazel tool. This commit also re-adds a few locale files that aren't generated by CLDR 37, but have been accidentally left in the repository as the Gulp script never removed old locales from previous CLDR versions. This problem is solved with the Bazel generation of locale files, but for now we re-add these old CLDR 33 locale files to not break developers relying on these (even though the locale data indicies are incorrect; but there might be users accessing the data directly) PR Close angular#42230
1 parent 1f75a65 commit 4641fc7

File tree

17 files changed

+1427
-5631
lines changed

17 files changed

+1427
-5631
lines changed

.ng-dev/format.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export const format: FormatConfig = {
2626
'!dev-infra/build-worker.js',
2727
// Do not format compliance test-cases since they must match generated code
2828
'!packages/compiler-cli/test/compliance/test_cases/**/*.js',
29+
// Do not format the locale files which are checked-in for Google3, but generated using
30+
// the `generate-locales-tool` from `packages/common/locales`.
31+
'!packages/core/src/i18n/locale_en.ts',
32+
'!packages/common/locales/closure-locale.ts',
33+
'!packages/common/src/i18n/currencies.ts',
2934
]
3035
},
3136
'buildifier': true

packages/common/BUILD.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
2+
load("//packages/common/locales:index.bzl", "generate_base_currencies_file")
13
load("//tools:defaults.bzl", "ng_module", "ng_package", "ts_api_guardian_test_npm_package")
24

35
package(default_visibility = ["//visibility:public"])
46

7+
# This generates the `src/i18n/currencies.ts` file through the `generate-locales` tool. Since
8+
# the base currencies file is checked-in for Google3, we add a `generated_file_test` to ensure
9+
# the checked-in file is up-to-date. To disambiguate from the test, we use a more precise target
10+
# name here.
11+
generate_base_currencies_file(
12+
name = "base_currencies_file_generated",
13+
output_file = "base_currencies_generated.ts",
14+
)
15+
16+
generated_file_test(
17+
name = "base_currencies_file",
18+
src = "src/i18n/currencies.ts",
19+
generated = ":base_currencies_file_generated",
20+
)
21+
522
ng_module(
623
name = "common",
724
srcs = glob(

packages/common/locales/BUILD.bazel

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1+
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
2+
load("//packages/common/locales:index.bzl", "LOCALES", "generate_all_locale_files", "generate_closure_locales_file")
13
load("//tools:defaults.bzl", "pkg_npm", "ts_library")
24

35
package(default_visibility = ["//visibility:public"])
46

7+
# This generates the `closure-locale.ts` file through the `generate-locales` tool. Since
8+
# the `closure-locale.ts` file is checked-in for Google3, we add a `generated_file_test` to
9+
# ensure the checked-in file is up-to-date. To disambiguate from the test, we use a more
10+
# precise target name here.
11+
generate_closure_locales_file(
12+
name = "closure_locales_file_generated",
13+
output_file = "closure_locales_generated.ts",
14+
)
15+
16+
generated_file_test(
17+
name = "closure_locale_file",
18+
src = "closure-locale.ts",
19+
generated = ":closure_locales_file_generated",
20+
)
21+
22+
generate_all_locale_files(
23+
name = "locale_files",
24+
)
25+
526
ts_library(
627
name = "locales",
7-
srcs = glob(
8-
["**/*.ts"],
28+
# TODO(devversion): Remove glob for checked-in legacy locale files that haven't been
29+
# removed in the past (when CLDR has been updated). These can be removed in a major.
30+
srcs = [file for l in LOCALES for file in [
31+
"%s.ts" % l,
32+
"extra/%s.ts" % l,
33+
]] + glob(
34+
[
35+
"*.ts",
36+
"extra/*.ts",
37+
],
938
exclude = ["closure-locale.ts"],
1039
),
1140
)
1241

1342
pkg_npm(
1443
name = "package",
15-
srcs = glob(["global/*.js"]) + ["package.json"],
44+
srcs = ["package.json"],
1645
substitutions = {
1746
# Workaround for `.d.ts`` containing `/// <amd-module .../>`
1847
# which are generated in TypeScript v2.9, but not before.
@@ -25,5 +54,7 @@ pkg_npm(
2554
# null out the require reference passed into the module.
2655
"factory\\(require, exports\\)": "factory(null, exports)",
2756
},
28-
deps = [":locales"],
57+
# TODO(devversion): Remove glob for checked-in legacy locale files that haven't been
58+
# removed in the past (when CLDR has been updated). These can be removed in a major.
59+
deps = ["global/%s.js" % l for l in LOCALES] + [":locales"] + glob(["global/*.js"]),
2960
)

0 commit comments

Comments
 (0)