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

Use Bazel for repo unit tests #11749

merged 19 commits into from
Aug 22, 2018

Conversation

filipesilva
Copy link
Contributor

No description provided.

@filipesilva filipesilva force-pushed the bazel-tests branch 10 times, most recently from f3f256a to 0795013 Compare August 7, 2018 15:18
@filipesilva filipesilva force-pushed the bazel-tests branch 8 times, most recently from 2f8d914 to 42b5b39 Compare August 14, 2018 16:49
@@ -127,6 +154,9 @@ workflows:
requires:
- lint
- validate
- test-bazel:
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not wise to have separate build and test jobs for bazel. you guarantee that the first test can't start running until the slowest build step is finished, so the total time is longer. Better to let bazel be the only scheduler for its actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved into the same job.

BUILD Outdated
# 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/**/.*/**"
Copy link
Contributor

Choose a reason for hiding this comment

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

we now also add an exclude for spaces
node_modules/**/* *

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added that one too.

WORKSPACE Outdated
@@ -1,52 +1,73 @@
workspace(name = "angular_devkit")
workspace(name = "angular_cli")
Copy link
Contributor

Choose a reason for hiding this comment

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

note, this change has downstream implications for bazel usage (in angular/angular we load this workspace to get build optimizer)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hadn't considered that. Perhaps it's better to leave it as is. WDYT?

WORKSPACE Outdated

BAZEL_SKYLIB_VERSION = "0.3.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

can remove this now with rules_typescript 0.16.1

@@ -12,28 +12,19 @@ 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.

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).

@filipesilva filipesilva added target: patch This PR is targeted for the next patch release and removed state: WIP labels Aug 15, 2018
alexeagle
alexeagle previously approved these changes Aug 15, 2018
@@ -123,7 +142,7 @@ workflows:
requires:
- lint
- validate
- build-bazel:
- bazel:
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

BUILD Outdated

load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

buildifier(
Copy link
Contributor

Choose a reason for hiding this comment

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

does this work all the way now?
I'm curious if it picks up .bzl files too
If this approach works well, I might want to update my other repos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It worked locally when I hacked buildifier to work on windows at all.

Can I ask you to test though? I haven't tested on linux/osx. Plus the hacks to make it work on windows involve setting absolute paths and it's always a bit of a hassle.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried testing it and it made edits.
Can we move buildifier to a separate PR?

WORKSPACE Outdated
)

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")
rules_nodejs_dependencies()
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to load nodejs dependencies, the rules_typescript_dependencies() will do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't it better to avoid relying on that transitively though? Inside this project we don't know what rules_typescript depends on, but we depend directly on rules_nodejs for node_repositories and jasmine_node_test (maybe others too).

Copy link
Contributor

Choose a reason for hiding this comment

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

the advantage is we're sure to get a version of rules_nodejs that works with rules_typescript.

Unlike under NPM, we don't get two versions of rules_nodejs installed if us and one of our deps disagree on the version. So it's our responsibility to get working versions of both, and I think that's easier if we use the same rules_nodejs version as rules_typescript declares a dependency on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a note that we're using it transitively then.

WORKSPACE Outdated
# 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().
RULES_GO_VERSION = "0.14.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

picking out the versions into variables doesn't seem that useful to me, I've avoided it so we can set up renovate to update automatically (I don't think it understands this)

many repos use git_repository, I avoided that because I thought it might fetch the whole git history and therefore wasteful, but I don't know that for sure. It has the advantage of the version appearing once instead of twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using git_repository before but asked @gregmagolan and he mentioned that it had been historically flaky (@gregmagolan correct me if I'm wrong).

I think it makes sense to ditch the variable if Renovate doesn't play ball with it though.

WORKSPACE Outdated
go_rules_dependencies()

go_register_toolchains()
# # We get Buildifier from here.
Copy link
Contributor

Choose a reason for hiding this comment

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

delete comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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

if not tsconfig:
tsconfig = DEFAULT_TSCONFIG
_ts_library(tsconfig = tsconfig, **kwargs)
if not tsconfig:
Copy link
Contributor

Choose a reason for hiding this comment

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

actually you can remove this now, ts_library#tsconfig defaults to //:tsconfig.json as of release 0.15 or so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -52,7 +52,7 @@ describe('TsLintTaskExecutor', () => {
testRunner.runSchematicAsync('run-task', null, tree),
new Observable<void>(obs => {
process.chdir(getSystemPath(host.root));
testRunner.logger.subscribe(x => messages.push(x.message));
testRunner.logger.subscribe((x: logging.LogEntry) => messages.push(x.message));
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 need this change? logger is already a Observable<LogEntry>, so curious as to why TypeScript doesn't infer this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When made the initial PR this was not being inferred correctly, and I was not sure why. Tried again now and it wasn't a problem anymore. Maybe an older version of tooling?

@filipesilva filipesilva force-pushed the bazel-tests branch 3 times, most recently from a99726b to f1a7c81 Compare August 21, 2018 09:32
alexeagle
alexeagle previously approved these changes Aug 21, 2018
It stops the function from being imported in the unit test.
@hansl hansl merged commit f1f987b into angular:master Aug 22, 2018
],
),
module_name = "@angular-devkit/schematics/tasks",
module_root = "tasks",
tsconfig = "//:tsconfig.json",
module_root = "tasks/index.d.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing it to index.d.ts will hide the tasks/node, is that on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean, can you elaborate? I didn't mean to hide any package.

Copy link
Contributor

Choose a reason for hiding this comment

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

tasks/index.ts only export all the tasks, the task executors are exported through tasks/node
Changing module_root to "tasks/index.d.ts" will make tasks/node is not reachable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qiyigg #12008 should make them available again, sorry about that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, thanks!

@filipesilva filipesilva deleted the bazel-tests branch August 24, 2018 22:50
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants