Skip to content

Commit

Permalink
feat(bazel): update the build to use the new architect api
Browse files Browse the repository at this point in the history
With this change the builder has been updated to use the latest architect API and make it compatable with the latest CLI

Fixes angular/angular-cli#14082
  • Loading branch information
alan-agius4 committed Apr 5, 2019
1 parent 58e9283 commit 024a7d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/bazel/src/builders/builders.json
@@ -1,7 +1,7 @@
{
"builders": {
"build": {
"class": "./index",
"implementation": "./index",
"schema": "./schema.json",
"description": "Executes Bazel on a target."
}
Expand Down
59 changes: 31 additions & 28 deletions packages/bazel/src/builders/index.ts
Expand Up @@ -8,39 +8,42 @@
* @fileoverview Bazel builder
*/

import {BuildEvent, Builder, BuilderConfiguration, BuilderContext} from '@angular-devkit/architect';
import {Path} from '@angular-devkit/core';
import {Observable, from} from 'rxjs';
import {
BuilderContext,
BuilderOutput,
createBuilder,
} from '@angular-devkit/architect/src/index2';
import {JsonObject, normalize} from '@angular-devkit/core';
import {checkInstallation, copyBazelFiles, deleteBazelFiles, getTemplateDir, runBazel} from './bazel';
import {Schema} from './schema';
import {NodeJsSyncHost} from '@angular-devkit/core/node';

class BazelBuilder implements Builder<Schema> {
constructor(private context: BuilderContext) {}
async function _bazelBuilder(
options: JsonObject & Schema,
context: BuilderContext,
): Promise<BuilderOutput> {
const root = normalize(context.workspaceRoot);
const {logger} = context;
const {bazelCommand, leaveBazelFilesOnDisk, targetLabel, watch } = options;
const executable = watch ? 'ibazel' : 'bazel';
const binary = checkInstallation(executable, root);

run(config: BuilderConfiguration<Partial<Schema>>): Observable<BuildEvent> {
const {host, logger, workspace} = this.context;
const root: Path = workspace.root;
const {bazelCommand, leaveBazelFilesOnDisk, targetLabel, watch} = config.options as Schema;
const executable = watch ? 'ibazel' : 'bazel';
const binary = checkInstallation(executable, root) as Path;
const host = new NodeJsSyncHost();
const templateDir = await getTemplateDir(host, root);
const bazelFiles = await copyBazelFiles(host, root, templateDir);

return from(Promise.resolve().then(async() => {
const templateDir = await getTemplateDir(host, root);
const bazelFiles = await copyBazelFiles(host, root, templateDir);
try {
const flags: string[] = [];
await runBazel(root, binary, bazelCommand, targetLabel, flags);
return {success: true};
} catch (err) {
logger.error(err.message);
return {success: false};
} finally {
if (!leaveBazelFilesOnDisk) {
await deleteBazelFiles(host, bazelFiles); // this will never throw
}
}
}));
try {
const flags: string[] = [];
await runBazel(root, binary, bazelCommand, targetLabel, flags);
return {success: true};
} catch (err) {
logger.error(err.message);
return {success: false};
} finally {
if (!leaveBazelFilesOnDisk) {
await deleteBazelFiles(host, bazelFiles); // this will never throw
}
}
}

export default BazelBuilder;
export default createBuilder(_bazelBuilder);

0 comments on commit 024a7d2

Please sign in to comment.