-
Notifications
You must be signed in to change notification settings - Fork 323
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
Add an npm package output #114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build:release -c opt --stamp --workspace_status_command="$PWD/stamp.sh" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env node | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
'use strict'; | ||
|
||
// This package inspired by | ||
// https://github.com/angular/clang-format/blob/master/index.js | ||
const os = require('os'); | ||
const path = require('path'); | ||
const spawn = require('child_process').spawn; | ||
|
||
function getNativeBinary() { | ||
const arch = { | ||
'x64' : 'amd64', | ||
}[os.arch()]; | ||
// Filter the platform based on the platforms that are build/included. | ||
const platform = { | ||
'darwin' : 'darwin', | ||
'linux' : 'linux', | ||
'win32' : 'windows', | ||
}[os.platform()]; | ||
const extension = { | ||
'darwin' : '', | ||
'linux' : '', | ||
'win32' : '.exe', | ||
}[os.platform()]; | ||
|
||
if (arch == undefined || platform == undefined) { | ||
console.error(`FATAL: Your platform/architecture combination ${ | ||
os.platform()} - ${os.arch()} is not yet supported. | ||
You may need to compile Bazelisk yourself, or use the Python version. | ||
See instructions at https://github.com/bazelbuild/bazelisk/blob/master/README.md.`); | ||
return Promise.resolve(1); | ||
} | ||
|
||
const binary = | ||
path.join(__dirname, `bazelisk-${platform}_${arch}${extension}`); | ||
return binary; | ||
} | ||
|
||
function main(args) { | ||
const binary = getNativeBinary(); | ||
const ps = spawn(binary, args, {stdio : 'inherit'}); | ||
|
||
function shutdown() { | ||
ps.kill("SIGTERM") | ||
process.exit(); | ||
} | ||
|
||
process.on("SIGINT", shutdown); | ||
process.on("SIGTERM", shutdown); | ||
|
||
ps.on('close', e => process.exitCode = e); | ||
} | ||
|
||
if (require.main === module) { | ||
main(process.argv.slice(2)); | ||
} | ||
|
||
module.exports = { | ||
getNativeBinary, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@bazel/bazelisk", | ||
"description": "A user-friendly launcher for Bazel", | ||
"version": "0.0.0-PLACEHOLDER", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is the "version" here replaced with the correct version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a feature of the pkg_npm rule: https://github.com/bazelbuild/rules_nodejs/blob/master/docs/Built-ins.md#replace_with_version |
||
"license": "Apache-2.0", | ||
"bin": { | ||
"bazelisk": "bazelisk.js" | ||
}, | ||
"keywords": [ | ||
"bazel" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bazelbuild/bazelisk.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bazelbuild/bazelisk/issues" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff internal/pkg_npm/packager.js internal/pkg_npm/packager.js | ||
index ac41b585..48167a19 100644 | ||
--- internal/pkg_npm/packager.js | ||
+++ internal/pkg_npm/packager.js | ||
@@ -89,7 +89,7 @@ function main(args) { | ||
.find(s => s.startsWith('BUILD_SCM_VERSION')); | ||
// Don't assume BUILD_SCM_VERSION exists | ||
if (versionTag) { | ||
- version = versionTag.split(' ')[1].trim(); | ||
+ version = versionTag.split(' ')[1].replace(/^v/, '').trim(); | ||
} | ||
} | ||
substitutions.push([new RegExp(replaceWithVersion, 'g'), version]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ CURRENT_TAG=$(git tag -l --points-at HEAD | head -n1) | |
CURRENT_COMMIT=$(git rev-parse HEAD) | ||
|
||
echo "STABLE_VERSION ${CURRENT_TAG:-$CURRENT_COMMIT}" | ||
# rules_nodejs expects to read from volatile-status.txt | ||
echo "BUILD_SCM_VERSION ${CURRENT_TAG:-$CURRENT_COMMIT}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found it valuable to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, for Angular we use a But of course that change should be made for all the stamping here, not just npm, so I don't think it should go in this PR. @philwo do you want a separate PR for that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know that one could create platform-specific go_binary targets - that's much better than my existing approach in
build.sh
! :) Thanks!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I figured you might want to refactor that script too. If nothing else, this allows you to build all the architectures in parallel, even if you still loop through them to place them in a
bin
directory