-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bazel.getTargetOutput command (#275)
* Add bazel.getTargetOutputs command This command can be used in launch configurations to obtain the path to an executable built by Bazel. For example, you can set the "program" attribute of a launch configuration to an input variable: "program": "${input:binaryOutputLocation}" Then define a command input variable: "inputs" [ { "id": "binaryOutputLocation", "type": "command", "command": "bazel.getOutputTarget", "args": ["//my/binary:target"], } ] Addresses #273 and could form the basis of #217, #207, and #115. * Add/update docs * Lint
- Loading branch information
1 parent
efbdb1f
commit 8039f64
Showing
11 changed files
with
245 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2022 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. | ||
|
||
import { BazelQuery } from "./bazel_query"; | ||
|
||
/** Provides a promise-based API around a Bazel cquery. */ | ||
export class BazelCQuery extends BazelQuery { | ||
/** | ||
* Constructs and executes a cquery command that obtains the output files of | ||
* a given target. | ||
* | ||
* @param target The target to query. | ||
* @param options Additional command line options that should be | ||
* passed just to this specific invocation of the query. | ||
* @returns The files that are outputs of the given target, as paths relative | ||
* to the execution root. | ||
*/ | ||
public async queryOutputs( | ||
target: string, | ||
options: string[] = [], | ||
): Promise<string[]> { | ||
return ( | ||
await this.run([ | ||
target, | ||
...options, | ||
"--output=starlark", | ||
"--starlark:expr", | ||
'"\\n".join([f.path for f in target.files.to_list()])', | ||
]) | ||
) | ||
.toString("utf-8") | ||
.trim() | ||
.replace(/\r\n|\r/g, "\n") | ||
.split("\n") | ||
.sort(); | ||
} | ||
|
||
protected bazelCommand(): string { | ||
return "cquery"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 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. | ||
|
||
import * as child_process from "child_process"; | ||
|
||
import { BazelCommand } from "./bazel_command"; | ||
|
||
/** Provides a promise-based API around the `bazel info` command. */ | ||
export class BazelInfo extends BazelCommand { | ||
/** | ||
* Runs `bazel info <key>` and returns the output. | ||
* | ||
* @param key The info key to query. | ||
* @returns The output of `bazel info <key>`. | ||
*/ | ||
public async run(key: string): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
child_process.execFile( | ||
this.bazelExecutable, | ||
this.execArgs([key]), | ||
{ cwd: this.workingDirectory }, | ||
(error: Error, stdout: string) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(stdout.trim()); | ||
} | ||
}, | ||
); | ||
}); | ||
} | ||
|
||
protected bazelCommand(): string { | ||
return "info"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.