Skip to content
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

chore(NA): bazel machinery installation on kbn bootstrap #89469

Merged
merged 4 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions .bazeliskversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.7.3
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0
3 changes: 3 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
workspace(
name = "kibana",
tylersmalley marked this conversation as resolved.
Show resolved Hide resolved
)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"@babel/register": "^7.12.10",
"@babel/traverse": "^7.12.12",
"@babel/types": "^7.12.12",
"@bazel/ibazel": "^0.14.0",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.5.0",
"@elastic/apm-rum": "^5.6.1",
Expand Down
1,875 changes: 985 additions & 890 deletions packages/kbn-pm/dist/index.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion packages/kbn-pm/src/commands/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ import { getAllChecksums } from '../utils/project_checksums';
import { BootstrapCacheFile } from '../utils/bootstrap_cache_file';
import { readYarnLock } from '../utils/yarn_lock';
import { validateDependencies } from '../utils/validate_dependencies';
import { installBazelTools } from '../utils/bazel';

export const BootstrapCommand: ICommand = {
description: 'Install dependencies and crosslink projects',
name: 'bootstrap',

async run(projects, projectGraph, { options, kbn }) {
async run(projects, projectGraph, { options, kbn, rootPath }) {
const batchedProjects = topologicallyBatchProjects(projects, projectGraph);
const kibanaProjectPath = projects.get('kibana')?.path;
const extraArgs = [
...(options['frozen-lockfile'] === true ? ['--frozen-lockfile'] : []),
...(options['prefer-offline'] === true ? ['--prefer-offline'] : []),
];

// Install bazel machinery tools if needed
await installBazelTools(rootPath);

// Install monorepo npm dependencies
for (const batch of batchedProjects) {
for (const project of batch) {
const isExternalPlugin = project.path.includes(`${kibanaProjectPath}${sep}plugins`);
Expand Down
9 changes: 9 additions & 0 deletions packages/kbn-pm/src/utils/bazel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

export * from './install_tools';
69 changes: 69 additions & 0 deletions packages/kbn-pm/src/utils/bazel/install_tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import { resolve } from 'path';
import { spawn } from '../child_process';
import { readFile } from '../fs';
import { log } from '../log';

export interface BazelToolsVersion {
bazelisk: string;
bazel: string;
}

async function readBazelToolsVersionFile(repoRootPath: string, versionFilename: string) {
const version = (await readFile(resolve(repoRootPath, versionFilename)))
.toString()
.split('\n')[0];

if (!version) {
throw new Error(`${versionFilename} file do not contain any version set`);
}

return version;
}

async function readBazelToolsVersion(repoRootPath: string) {
try {
const bazeliskVersion = await readBazelToolsVersionFile(repoRootPath, '.bazeliskversion');
const bazelVersion = await readBazelToolsVersionFile(repoRootPath, '.bazelversion');

return {
bazelisk: bazeliskVersion,
bazel: bazelVersion,
} as BazelToolsVersion;
} catch (e) {
throw new Error(`[bazel_tools] Failed on reading bazel tools versions\n ${e}`);
}
}

export async function installBazelTools(repoRootPath: string) {
log.debug(`[bazel_tools] reading bazel tools versions from version files`);
const bazelToolsVersions = await readBazelToolsVersion(repoRootPath);
tylersmalley marked this conversation as resolved.
Show resolved Hide resolved

// Check what globals are installed
log.debug(`[bazel_tools] verify if bazelisk is installed`);
const { stdout } = await spawn('yarn', ['global', 'list'], { stdio: 'pipe' });

// Install bazelisk if not installed
if (!stdout.includes(`@bazel/bazelisk@${bazelToolsVersions.bazelisk}`)) {
log.info(`[bazel_tools] installing Bazel tools`);

log.debug(
`[bazel_tools] bazelisk is not installed. Installing @bazel/bazelisk@${bazelToolsVersions.bazelisk} and bazel@${bazelToolsVersions.bazel}`
);
await spawn('yarn', ['global', 'add', `@bazel/bazelisk@${bazelToolsVersions.bazelisk}`], {
env: {
USE_BAZEL_VERSION: bazelToolsVersions.bazel,
},
stdio: 'pipe',
});
}

log.success(`[bazel_tools] all bazel tools are correctly installed`);
}
4 changes: 4 additions & 0 deletions src/dev/precommit_hook/casing_check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export const IGNORE_FILE_GLOBS = [
'x-pack/test/fleet_api_integration/apis/fixtures/test_packages/**/*',

'.teamcity/**/*',

// Bazel default files
'**/WORKSPACE.bazel',
'**/BUILD.bazel',
];

/**
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,11 @@
resolved "https://registry.yarnpkg.com/@base2/pretty-print-object/-/pretty-print-object-1.0.0.tgz#860ce718b0b73f4009e153541faff2cb6b85d047"
integrity sha512-4Th98KlMHr5+JkxfcoDT//6vY8vM+iSPrLNpHhRyLx2CFYi8e2RfqPLdpbnpo0Q5lQC5hNB79yes07zb02fvCw==

"@bazel/ibazel@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.14.0.tgz#86fa0002bed2ce1123b7ad98d4dd4623a0d93244"
integrity sha512-s0gyec6lArcRDwVfIP6xpY8iEaFpzrSpyErSppd3r2O49pOEg7n6HGS/qJ8ncvme56vrDk6crl/kQ6VAdEO+rg==

"@bcoe/v8-coverage@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
Expand Down