Skip to content

Commit 285678f

Browse files
committed
build(bazel): update bazel integration to build angular from source
1 parent e90875a commit 285678f

File tree

13 files changed

+127
-775
lines changed

13 files changed

+127
-775
lines changed

WORKSPACE

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,30 @@ http_archive(
1010
sha256 = "2977cdbc8ae0eed7d4186385af56a50a3321a549e2136a959998bba89d2edb6e",
1111
)
1212

13-
http_archive(
14-
name = "bazel_skylib",
15-
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/0.3.1.zip"],
16-
strip_prefix = "bazel-skylib-0.3.1",
17-
sha256 = "95518adafc9a2b656667bbf517a952e54ce7f350779d0dd95133db4eb5c27fb1",
18-
)
19-
20-
http_archive(
21-
name = "io_bazel_rules_webtesting",
22-
url = "https://github.com/bazelbuild/rules_webtesting/archive/0.2.1.zip",
23-
strip_prefix = "rules_webtesting-0.2.1",
24-
sha256 = "7d490aadff9b5262e5251fa69427ab2ffd1548422467cb9f9e1d110e2c36f0fa",
25-
)
26-
2713
http_archive(
2814
name = "build_bazel_rules_typescript",
2915
url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.2.zip",
3016
strip_prefix = "rules_typescript-0.16.2",
3117
sha256 = "31601b777840fbf600dbd1893ade0d1de37166e7ba52b90735b107cfb67e38c7",
3218
)
19+
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
20+
rules_typescript_dependencies()
21+
22+
http_archive(
23+
name = "bazel_toolchains",
24+
urls = [
25+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/5124557861ebf4c0b67f98180bff1f8551e0b421.tar.gz",
26+
"https://github.com/bazelbuild/bazel-toolchains/archive/5124557861ebf4c0b67f98180bff1f8551e0b421.tar.gz",
27+
],
28+
strip_prefix = "bazel-toolchains-5124557861ebf4c0b67f98180bff1f8551e0b421",
29+
sha256 = "c3b08805602cd1d2b67ebe96407c1e8c6ed3d4ce55236ae2efe2f1948f38168d",
30+
)
3331

3432
http_archive(
35-
name = "io_bazel_rules_go",
36-
url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz",
37-
sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a",
33+
name = "io_bazel_rules_sass",
34+
url = "https://github.com/bazelbuild/rules_sass/archive/1.11.0.zip",
35+
strip_prefix = "rules_sass-1.11.0",
36+
sha256 = "dbe9fb97d5a7833b2a733eebc78c9c1e3880f676ac8af16e58ccf2139cbcad03",
3837
)
3938

4039
# This commit matches the version of buildifier in angular/ngcontainer
@@ -72,9 +71,9 @@ http_archive(
7271

7372
http_archive(
7473
name = "org_brotli",
75-
url = "https://github.com/google/brotli/archive/f9b8c02673c576a3e807edbf3a9328e9e7af6d7c.zip",
76-
strip_prefix = "brotli-f9b8c02673c576a3e807edbf3a9328e9e7af6d7c",
77-
sha256 = "8a517806d2b7c8505ba5c53934e7d7c70d341b68ffd268e9044d35b564a48828",
74+
url = "https://github.com/google/brotli/archive/v1.0.5.zip",
75+
strip_prefix = "brotli-1.0.5",
76+
sha256 = "774b893a0700b0692a76e2e5b7e7610dbbe330ffbe3fe864b4b52ca718061d5a",
7877
)
7978

8079
#

integration/bazel/BUILD.bazel

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,33 @@ exports_files([
44
"protractor.conf.js",
55
])
66

7+
# ts_library and ng_module use the `//:tsconfig.json` target
8+
# by default. This alias allows omitting explicit tsconfig
9+
# attribute.
10+
alias(
11+
name = "tsconfig.json",
12+
actual = "//src:tsconfig.json",
13+
)
14+
715
filegroup(
816
name = "node_modules",
917
srcs = glob(
10-
["node_modules/**/*"],
18+
[
19+
# Include only .js, .json & .d.ts files to reduce the number of
20+
# files in the //:node_modules filegroup
21+
"node_modules/**/*.js",
22+
"node_modules/**/*.json",
23+
"node_modules/**/*.d.ts",
24+
# All the files in the http-server package are necesssary
25+
"node_modules/http-server/**",
26+
# All the files in the protractor package are necesssary
27+
"node_modules/protractor/**",
28+
# Also include all files in node_modules/.bin
29+
"node_modules/.bin/*",
30+
],
1131
exclude = [
12-
# Exclude rxjs because we build it from sources using the label @rxjs//:rxjs
13-
"node_modules/rxjs/**",
14-
15-
# Exclude directories that commonly contain filenames which are
16-
# illegal bazel labels
17-
# e.g. node_modules/adm-zip/test/assets/attributes_test/New folder/hidden.txt
18-
"node_modules/**/test/**",
19-
# e.g. node_modules/xpath/docs/function resolvers.md
20-
"node_modules/**/docs/**",
32+
# Exclude files with spaces which are illegal bazel labels
33+
"node_modules/**/* *",
2134
],
2235
),
2336
)
24-
25-
ANGULAR_TESTING = [
26-
"node_modules/@angular/*/bundles/*-testing.umd.js",
27-
# We use AOT, so the compiler and the dynamic platform-browser should be
28-
# visible only in tests
29-
"node_modules/@angular/compiler/bundles/*.umd.js",
30-
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
31-
]
32-
33-
filegroup(
34-
name = "angular_bundles",
35-
srcs = glob(
36-
["node_modules/@angular/*/bundles/*.umd.js"],
37-
exclude = ANGULAR_TESTING,
38-
),
39-
)
40-
41-
filegroup(
42-
name = "angular_test_bundles",
43-
testonly = 1,
44-
srcs = glob(ANGULAR_TESTING),
45-
)

integration/bazel/WORKSPACE

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,18 @@ workspace(name = "bazel_integration_test")
44
# Download Bazel toolchain dependencies as needed by build actions
55
#
66

7-
http_archive(
8-
name = "build_bazel_rules_nodejs",
9-
urls = ["https://github.com/bazelbuild/rules_nodejs/archive/0.11.4.zip"],
10-
strip_prefix = "rules_nodejs-0.11.4",
11-
sha256 = "c31c4ead696944a50fad2b3ee9dfbbeffe31a8dcca0b21b9bf5b3e6c6b069801",
12-
)
13-
14-
http_archive(
15-
name = "bazel_skylib",
16-
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/0.3.1.zip"],
17-
strip_prefix = "bazel-skylib-0.3.1",
18-
sha256 = "95518adafc9a2b656667bbf517a952e54ce7f350779d0dd95133db4eb5c27fb1",
19-
)
20-
21-
http_archive(
22-
name = "io_bazel_rules_webtesting",
23-
url = "https://github.com/bazelbuild/rules_webtesting/archive/0.2.1.zip",
24-
strip_prefix = "rules_webtesting-0.2.1",
25-
sha256 = "7d490aadff9b5262e5251fa69427ab2ffd1548422467cb9f9e1d110e2c36f0fa",
26-
)
27-
28-
http_archive(
7+
local_repository(
298
name = "build_bazel_rules_typescript",
30-
url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.2.zip",
31-
strip_prefix = "rules_typescript-0.16.2",
32-
sha256 = "31601b777840fbf600dbd1893ade0d1de37166e7ba52b90735b107cfb67e38c7",
33-
)
34-
35-
http_archive(
36-
name = "io_bazel_rules_go",
37-
url = "https://github.com/bazelbuild/rules_go/releases/download/0.11.0/rules_go-0.11.0.tar.gz",
38-
sha256 = "f70c35a8c779bb92f7521ecb5a1c6604e9c3edd431e50b6376d7497abc8ad3c1",
9+
path = "node_modules/@bazel/typescript",
3910
)
11+
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
12+
rules_typescript_dependencies()
4013

4114
http_archive(
4215
name = "io_bazel_rules_sass",
43-
url = "https://github.com/bazelbuild/rules_sass/archive/0.1.0.zip",
44-
strip_prefix = "rules_sass-0.1.0",
45-
sha256 = "b243c4d64f054c174051785862ab079050d90b37a1cef7da93821c6981cb9ad4",
16+
url = "https://github.com/bazelbuild/rules_sass/archive/1.11.0.zip",
17+
strip_prefix = "rules_sass-1.11.0",
18+
sha256 = "dbe9fb97d5a7833b2a733eebc78c9c1e3880f676ac8af16e58ccf2139cbcad03",
4619
)
4720

4821
#
@@ -51,7 +24,7 @@ http_archive(
5124

5225
local_repository(
5326
name = "angular",
54-
path = "node_modules/@angular/bazel",
27+
path = "../..",
5528
)
5629

5730
local_repository(

integration/bazel/angular.tsconfig.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

integration/bazel/package.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@
44
"version": "0.0.0",
55
"license": "MIT",
66
"dependencies": {
7-
"@angular/animations": "file:../../dist/packages-dist/animations",
8-
"@angular/common": "file:../../dist/packages-dist/common",
9-
"@angular/compiler": "file:../../dist/packages-dist/compiler",
10-
"@angular/core": "file:../../dist/packages-dist/core",
11-
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
12-
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
7+
"reflect-metadata": "file:../../node_modules/reflect-metadata",
138
"rxjs": "file:../../node_modules/rxjs",
9+
"tslib": "file:../../node_modules/tslib",
1410
"zone.js": "file:../../node_modules/zone.js"
1511
},
1612
"devDependencies": {
17-
"@angular/bazel": "file:../../dist/packages-dist/bazel",
18-
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
19-
"@types/jasmine": "2.8.7",
13+
"@bazel/typescript": "0.16.2",
14+
"@types/jasmine": "file:../../node_modules/@types/jasmine",
2015
"@types/source-map": "0.5.1",
2116
"http-server": "0.11.1",
2217
"protractor": "file:../../node_modules/protractor",
23-
"tsutils": "file:../../node_modules/tsutils",
18+
"tsickle": "file:../../node_modules/tsickle",
2419
"typescript": "file:../../node_modules/typescript"
2520
},
2621
"scripts": {
27-
"postinstall": "ngc -p angular.tsconfig.json",
2822
"test": "bazel build ... --noshow_progress && bazel test ..."
2923
}
3024
}

integration/bazel/src/BUILD.bazel

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@ exports_files(["tsconfig.json"])
88
ng_module(
99
name = "src",
1010
srcs = glob(["*.ts"]),
11-
tsconfig = ":tsconfig.json",
12-
deps = ["//src/hello-world"],
11+
deps = [
12+
"//src/hello-world",
13+
"@angular//packages/common/http",
14+
"@angular//packages/core",
15+
"@angular//packages/platform-browser",
16+
],
1317
)
1418

1519
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
1620

1721
ts_devserver(
1822
name = "devserver",
1923
additional_root_paths = [
24+
"bazel_integration_test/node_modules/tslib",
2025
"bazel_integration_test/node_modules/zone.js/dist",
2126
],
2227
entry_module = "bazel_integration_test/src/main",
23-
scripts = ["//:angular_bundles"],
2428
serving_path = "/bundle.min.js",
2529
static_files = [
30+
"//:node_modules/tslib/tslib.js",
2631
"//:node_modules/zone.js/dist/zone.min.js",
2732
"index.html",
2833
],

integration/bazel/src/hello-world/BUILD.bazel

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ ng_module(
1616
exclude = ["*.spec.ts"],
1717
),
1818
assets = [":hello-world-styles"],
19-
tsconfig = "//src:tsconfig.json",
20-
# FIXME(alexeagle): the rxjs dep should come from Angular, but if we use the
21-
# npm distro of angular there is no ts_library rule to propagate the dep.
22-
deps = ["@rxjs"],
19+
deps = [
20+
"@angular//packages/core",
21+
],
2322
)
2423

2524
ng_package(
@@ -32,20 +31,27 @@ ts_library(
3231
name = "test_lib",
3332
testonly = 1,
3433
srcs = glob(["*.spec.ts"]),
35-
tsconfig = "//src:tsconfig.json",
36-
deps = [":hello-world"],
34+
deps = [
35+
":hello-world",
36+
"@angular//packages/core",
37+
"@angular//packages/core/testing",
38+
"@angular//packages/platform-browser",
39+
"@angular//packages/platform-browser-dynamic/testing",
40+
],
3741
)
3842

3943
ts_web_test_suite(
4044
name = "test",
41-
bootstrap = ["//:node_modules/zone.js/dist/zone-testing-bundle.js"],
45+
srcs = ["//:node_modules/tslib/tslib.js"],
46+
bootstrap = [
47+
"//:node_modules/zone.js/dist/zone-testing-bundle.js",
48+
"//:node_modules/reflect-metadata/Reflect.js",
49+
],
4250
browsers = [
4351
"@io_bazel_rules_webtesting//browsers:chromium-local",
4452
"@io_bazel_rules_webtesting//browsers:firefox-local",
4553
],
4654
deps = [
4755
":test_lib",
48-
"//:angular_bundles",
49-
"//:angular_test_bundles",
5056
],
5157
)

integration/bazel/test/e2e/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ ts_library(
1313
testonly = 1,
1414
srcs = ["on-prepare.ts"],
1515
tsconfig = ":tsconfig.json",
16-
deps = ["@angular//src/protractor/utils"],
16+
deps = ["@angular//packages/bazel/src/protractor/utils"],
1717
)
1818

1919
protractor_web_test_suite(
2020
name = "devserver_test",
2121
configuration = "//:protractor.conf.js",
22-
data = ["@angular//src/protractor/utils"],
22+
data = ["@angular//packages/bazel/src/protractor/utils"],
2323
on_prepare = ":ts_on_prepare",
2424
server = "//src:devserver",
2525
deps = [":e2e"],
@@ -28,7 +28,7 @@ protractor_web_test_suite(
2828
protractor_web_test_suite(
2929
name = "prodserver_test",
3030
configuration = "//:protractor.conf.js",
31-
data = ["@angular//src/protractor/utils"],
31+
data = ["@angular//packages/bazel/src/protractor/utils"],
3232
on_prepare = ":ts_on_prepare",
3333
server = "//src:prodserver",
3434
deps = [":e2e"],

integration/bazel/tools/bazel.rc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ test --test_output=errors
88
# Workaround https://github.com/bazelbuild/bazel/issues/3645
99
# Limit Bazel to consuming 3072K of RAM
1010
build --local_resources=3072,2.0,1.0
11+
12+
# Use the Angular 6 compiler
13+
build --define=compile=legacy

0 commit comments

Comments
 (0)