Skip to content

Use Bazel for repo unit tests #11749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
version: 2
# Configuration file for https://circleci.com/gh/angular/angular-cli

# Note: YAML anchors allow an object to be re-used, reducing duplication.
# The ampersand declares an alias for an object, then later the `<<: *name`
# syntax dereferences it.
# See http://blog.daemonl.com/2016/02/yaml.html
# To validate changes, use an online parser, eg.
# http://yaml-online-parser.appspot.com/

# Variables

## IMPORTANT
# If you change the `docker_image` version, also change the `cache_key` suffix and the version of
# `com_github_bazelbuild_buildtools` in the `/WORKSPACE` file.
var_1: &docker_image angular/ngcontainer:0.3.3
var_2: &cache_key angular_devkit-{{ checksum "yarn.lock" }}-0.3.3-2

_defaults: &defaults
# Settings common to each job
anchor_1: &defaults
working_directory: ~/ng
docker:
- image: angular/ngcontainer:0.3.3
- image: *docker_image

_post_checkout: &post_checkout
# After checkout, rebase on top of master.
# Similar to travis behavior, but not quite the same.
# See https://discuss.circleci.com/t/1662
anchor_2: &post_checkout
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"

_root_package_lock_key: &root_package_lock_key
key: angular_devkit-{{ checksum "yarn.lock" }}-0.3.3-2

_attach_options: &attach_options
anchor_3: &root_package_lock_key
key: *cache_key
anchor_4: &attach_options
at: .

# Job definitions
version: 2
jobs:
install:
<<: *defaults
Expand Down Expand Up @@ -80,7 +99,7 @@ jobs:
steps:
- attach_workspace: *attach_options
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
- run: bazel build //packages/...
- run: bazel test //packages/...

snapshot_publish:
<<: *defaults
Expand Down
20 changes: 19 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ exports_files([
# @external_begin
filegroup(
name = "node_modules",
srcs = glob(["node_modules/**/*"]),
srcs = glob(
# Only include files we might use, to reduce the file count and surface size of
# filename problems.
[
"node_modules/**/*.js",
"node_modules/**/*.json",
"node_modules/**/*.d.ts",
],
exclude = [
# e.g. node_modules/adm-zip/test/assets/attributes_test/New folder/hidden.txt
"node_modules/**/test/**",
# e.g. node_modules/xpath/docs/function resolvers.md
"node_modules/**/docs/**",
# e.g. node_modules/puppeteer/.local-chromium/mac-536395/chrome-mac/Chromium.app/Contents/Versions/66.0.3347.0/Chromium Framework.framework/Chromium Framework
"node_modules/**/.*/**",
# Ignore paths with spaces.
"node_modules/**/* *",
],
) + glob(["node_modules/.bin/*"]),
)
# @external_end
80 changes: 47 additions & 33 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,52 +1,66 @@
workspace(name = "angular_devkit")

# We get Buildifier from here.
http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.4.1.zip",
strip_prefix = "rules_nodejs-0.4.1",
sha256 = "e9bc013417272b17f302dc169ad597f05561bb277451f010043f4da493417607",
name = "com_github_bazelbuild_buildtools",
url = "https://github.com/bazelbuild/buildtools/archive/0.15.0.zip",
strip_prefix = "buildtools-0.15.0",
sha256 = "76d1837a86fa6ef5b4a07438f8489f00bfa1b841e5643b618e01232ba884b1fe",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies")
buildifier_dependencies()

check_bazel_version("0.9.0")
node_repositories(package_json = ["//:package.json"])
# The Go toolchain is used for Buildifier.
# rules_typescript_dependencies() also tries to load it but we add it explicitely so we
# don't have hidden dependencies.
# This also means we need to load it before rules_typescript_dependencies().
http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/archive/0.14.0.zip",
strip_prefix = "rules_go-0.14.0",
sha256 = "9bd7c2743f014e4e112b671098ba1da6aec036fe07093b10ca39a9f81ec5cc33",
)

local_repository(
name = "rxjs",
path = "node_modules/rxjs/src",
load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains()

# We need a minimum of this version to include https://github.com/bazelbuild/rules_nodejs/pull/281.
http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/c75e3dd0571b0937e3ce0c4f0e6b6b50d90468f0.zip",
strip_prefix = "rules_nodejs-c75e3dd0571b0937e3ce0c4f0e6b6b50d90468f0",
sha256 = "b78506ddaed7c682027f873d2bd50086a28570b3187da9fa16fe1672eed3015e",
)

# Pick up the fix for source-map typings
RULES_TYPESCRIPT_VERSION = "00f8fd5467f2b12ac2fbb8d74ea81d2dd5636d31"
# Load the TypeScript rules, its dependencies, and setup the workspace.
http_archive(
name = "build_bazel_rules_typescript",
url = "https://github.com/bazelbuild/rules_typescript/archive/%s.zip" % RULES_TYPESCRIPT_VERSION,
strip_prefix = "rules_typescript-%s" % RULES_TYPESCRIPT_VERSION,
sha256 = "3606b97a4859cc3f73b47888618b14290cf4b93c411b1bedd821e8bb39b3442b",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.1.zip",
strip_prefix = "rules_typescript-0.16.1",
sha256 = "5b2b0bc63cfcffe7bf97cad2dad3b26a73362f806de66207051f66c87956a995",
)

load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
# build_bazel_rules_nodejs is loaded transitively through rules_typescript_dependencies.
rules_typescript_dependencies()

load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
ts_setup_workspace()

# We get tools like Buildifier from here
git_repository(
name = "com_github_bazelbuild_buildtools",
remote = "https://github.com/bazelbuild/buildtools.git",
commit = "b3b620e8bcff18ed3378cd3f35ebeb7016d71f71",
)
# Load the nodejs dependencies, check minimum Bazel version, and define the local node_modules.
load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")
rules_nodejs_dependencies()

# The Go toolchain is used for Buildifier and some TypeScript tooling.
http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.7.1/rules_go-0.7.1.tar.gz",
sha256 = "341d5eacef704415386974bc82a1783a8b7ffbff2ab6ba02375e1ca20d9b031c",
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
check_bazel_version("0.15.0")
node_repositories(
package_json = ["//:package.json"],
preserve_symlinks = True,
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains()

local_repository(
name = "rxjs",
path = "node_modules/rxjs/src",
)
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"typescript": "~2.9.2"
},
"devDependencies": {
"@bazel/typescript": "0.16.1",
"@ngtools/json-schema": "^1.1.0",
"@types/copy-webpack-plugin": "^4.4.1",
"@types/express": "^4.16.0",
Expand Down Expand Up @@ -91,6 +92,7 @@
"license-checker": "^20.1.0",
"minimatch": "^3.0.4",
"minimist": "^1.2.0",
"rxjs": "^6.0.0",
"semver": "^5.3.0",
"source-map": "^0.5.6",
"source-map-support": "^0.5.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

licenses(["notice"]) # MIT

load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

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

Expand All @@ -19,6 +19,7 @@ ts_library(
],
),
data = glob(["**/*.json"]),
module_name = "@angular/cli",
deps = [
"//packages/angular_devkit/architect",
"//packages/angular_devkit/core",
Expand All @@ -30,5 +31,4 @@ ts_library(
# @typings: node
# @typings: semver
],
tsconfig = "//:tsconfig.json"
)
9 changes: 4 additions & 5 deletions packages/angular/pwa/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

licenses(["notice"]) # MIT

load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

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

Expand All @@ -24,12 +24,11 @@ ts_library(
"**/*_spec_large.ts",
],
),
# Borrow the compile-time deps of the typescript compiler
# Just to avoid an extra npm install action.
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
deps = [
"//packages/angular_devkit/core",
"//packages/angular_devkit/schematics",
],
tsconfig = "//:tsconfig.json",
# Borrow the compile-time deps of the typescript compiler
# Just to avoid an extra npm install action.
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
)
17 changes: 4 additions & 13 deletions packages/angular_devkit/architect/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,26 @@

licenses(["notice"]) # MIT

load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

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

ts_library(
name = "architect",
srcs = glob(
["src/**/*.ts"],
# Currently, this library is used only with the rollup plugin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the comment? was it stale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is not applicable at all. It looks like it was copy pasted from the build-optimizer BUILD file.

# To make it simpler for downstream repositories to compile this, we
# neither provide compile-time deps as an `npm_install` rule, nor do we
# expect the downstream repository to install @types/webpack[-*]
# So we exclude files that depend on webpack typings.
include = ["src/**/*.ts"],
exclude = [
"**/*_spec.ts",
"**/*_spec_large.ts",
],
),
module_name = "@angular-devkit/architect",
module_root = "src/index.d.ts",
data = glob(["**/*.json"]),
deps = [
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node",
"@rxjs",
"@rxjs//operators",
],
tsconfig = "//:tsconfig.json",
module_name = "@angular-devkit/architect",
module_root = "src",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we no longer need module root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, but it's added above (before data).

# Borrow the compile-time deps of the typescript compiler
# Just to avoid an extra npm install action.
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
)
8 changes: 3 additions & 5 deletions packages/angular_devkit/architect_cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
# found in the LICENSE file at https://angular.io/license
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

licenses(["notice"]) # MIT

ts_library(
name = "architect-cli",
name = "architect_cli",
srcs = [
"bin/architect.ts",
],
module_name = "@angular-devkit/architect-cli",
deps = [
"//packages/angular_devkit/architect",
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node",
"@rxjs",
"@rxjs//operators",
],
tsconfig = "//:tsconfig.json",
module_name = "@angular-devkit/architect-cli",
module_root = "bin",
)
49 changes: 32 additions & 17 deletions packages/angular_devkit/build_optimizer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,44 @@

licenses(["notice"]) # MIT

load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")

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

ts_library(
name = "lib",
name = "build_optimizer",
srcs = glob(
["**/*.ts"],
# Currently, this library is used only with the rollup plugin.
# To make it simpler for downstream repositories to compile this, we
# neither provide compile-time deps as an `npm_install` rule, nor do we
# expect the downstream repository to install @types/webpack[-*]
# So we exclude files that depend on webpack typings.
include = ["src/**/*.ts"],
exclude = [
"src/build-optimizer/webpack-loader.ts",
"src/purify/**",
"src/index.ts",
"**/*_spec.ts",
"**/*_spec_large.ts",
# TODO(@filipesilva): shouldn't need to exclude the cli files but can't exclude them
# from jasmine_node_test.
"src/**/cli.ts",
"src/**/*_spec.ts",
"src/**/*_spec_large.ts",
"src/**/*_benchmark.ts",
],
),
tsconfig = "//:tsconfig.json",
# Borrow the compile-time deps of the typescript compiler
# Just to avoid an extra npm install action.
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
deps = [],
)

ts_library(
name = "build_optimizer_test_lib",
srcs = glob(
include = [
"src/**/*_spec.ts",
"src/**/*_spec_large.ts",
],
),
deps = [
":build_optimizer",
"//packages/angular_devkit/core",
# @typings: jasmine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be interesting to sync this to google3 and see if all the tests pass there too

# @typings: node
],
)

jasmine_node_test(
name = "build_optimizer_test",
srcs = [":build_optimizer_test_lib"],
)
Loading