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

Support running buildifier through Bazel #350

Conversation

vogelsgesang
Copy link
Collaborator

@vogelsgesang vogelsgesang commented Feb 29, 2024

Buildifier is frequently installed through Bazel as described on https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md#setup-and-usage-via-bazel such that it can be run through bazel run.

This commit allows the bazel.buildifierExecutable setting to refer to a Bazel target. All paths starting with @ are interpreted as Bazel target names and are executed through bazel run. Bazel targets could also start with // but we interpret those as normal file system paths. If someone wants to run a target in the own workspace, they can simply use, e.g., @//:buildifier instead of //:buildifier.

As a drive-by fix, I also fixed #329 since it was a one-line fix.

Fixes #185, #329

BEGIN_COMMIT_OVERRIDE
feat: Support running buildifier through Bazel (#350)

feat: Support relative paths for bazel.buildifierExecutable (#350)
feat: Pick up .buildifier.json configuration from the Bazel workspace root (#350)
END_COMMIT_OVERRIDE

Buildifier is frequently installed through Bazel as described on
https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md#setup-and-usage-via-bazel
such that it can be run through `bazel run`.

This commit allows the `bazel.buildifierExecutable` setting to refer
to a Bazel target. All paths starting with `@` are interpreted as Bazel
target names and are executed through `bazel run`. Bazel targets could
also start with `//` but we interpret those as normal file system paths.
If someone wants to run a target in the own workspace, they can simply
use, e.g., `@//:buildifier` instead of `//:buildifier`.

As a drive-by fix, I also fixed bazelbuild#329 since it was a one-line fix.

Fixes bazelbuild#185, bazelbuild#329
@vogelsgesang vogelsgesang force-pushed the avogelsgesang-buildifier-bazel-target branch from 5437d95 to d48ff7d Compare February 29, 2024 21:56
Copy link
Collaborator

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

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

Thank you!

@jfirebaugh jfirebaugh merged commit c2f3f8c into bazelbuild:master Mar 1, 2024
4 checks passed
@Zemnmez
Copy link

Zemnmez commented Mar 12, 2024

Thank you for this!

Zemnmez added a commit to zemn-me/monorepo that referenced this pull request Mar 12, 2024
CauhxMilloy added a commit to CauhxMilloy/vscode-bazel that referenced this pull request Mar 17, 2024
This PR adds the `buildifierConfigJsonPath` setting, which allows a custom path to be set to pull the json configuration file for `buildifier` (this is often `.buildifier.json`). If the `buildifierConfigJsonPath` path is set, when `buildifier` is run within this extension, the `--config <path>` CLI arguments will be passed to `buildifier`.

While it could be said that this PR is now adding support for the `.buildifier.json` file -- it's only adding support for the customization of that file path. bazelbuild#350 actually pulled out yet another drive-by fix (of bazelbuild#208) by adding the working directory. In that PR, `cwd: vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath` is setting the working directory for the `buildifier` execution local into the workspace. This means any local `.buildifier.json` file will automatically get pulled in and used. This PR is allowing further customization on top of that.

The logic of this PR was tested by manually editing the js of my local extension installation with the equivalent changes (that's how I found that `cwd: ...` ended up working with a local `.buildifier.json`).
CauhxMilloy added a commit to CauhxMilloy/vscode-bazel that referenced this pull request Mar 17, 2024
This PR adds the `buildifierConfigJsonPath` setting, which allows a custom path to be set to pull the json configuration file for `buildifier` (this is often `.buildifier.json`). If the `buildifierConfigJsonPath` path is set, when `buildifier` is run within this extension, the `--config <path>` CLI arguments will be passed to `buildifier`.

While it could be said that this PR is now adding support for the `.buildifier.json` file -- it's only adding support for the customization of that file path. bazelbuild#350 actually pulled out yet another drive-by fix (of bazelbuild#208) by adding the working directory. In that PR, `cwd: vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath` is setting the working directory for the `buildifier` execution local to be the workspace. This means any local `.buildifier.json` file will automatically get pulled in and used. This PR is allowing further customization on top of that.

The logic of this PR was tested by manually editing the js of my local extension installation with the equivalent changes (that's how I found that `cwd: ...` ended up working with a local `.buildifier.json`).
CauhxMilloy added a commit to CauhxMilloy/vscode-bazel that referenced this pull request Mar 17, 2024
This PR adds the `buildifierConfigJsonPath` setting, which allows a custom path to be set to pull the json configuration file for `buildifier` (this is often `.buildifier.json`). If the `buildifierConfigJsonPath` path is set, when `buildifier` is run within this extension, the `--config <path>` CLI arguments will be passed to `buildifier`.

While it could be said that this PR is now adding support for the `.buildifier.json` file -- it's only adding support for the customization of that file path. bazelbuild#350 actually pulled out yet another drive-by fix (of bazelbuild#208) by adding the working directory. In that PR, `cwd: vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath` is setting the working directory for the `buildifier` execution to be the local workspace. This means any local `.buildifier.json` file will automatically get pulled in and used. This PR is allowing further customization on top of that.

The logic of this PR was tested by manually editing the js of my local extension installation with the equivalent changes (that's how I found that `cwd: ...` ended up working with a local `.buildifier.json`).
@vogelsgesang vogelsgesang deleted the avogelsgesang-buildifier-bazel-target branch March 26, 2024 02:08
cameron-martin added a commit that referenced this pull request Mar 26, 2024
This PR adds the `buildifierConfigJsonPath` setting, which allows a custom path to be set to pull the json configuration file for `buildifier` (this is often `.buildifier.json`). If the `buildifierConfigJsonPath` path is set, when `buildifier` is run within this extension, the `--config <path>` CLI arguments will be passed to `buildifier`.

While it could be said that this PR is now adding support for the `.buildifier.json` file -- it's only adding support for the customization of that file path. #350 actually pulled out yet another drive-by fix (of #208) by adding the working directory. In that PR, `cwd: vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath` is setting the working directory for the `buildifier` execution to be the local workspace. This means any local `.buildifier.json` file will automatically get pulled in and used. This PR is allowing further customization on top of that.

The logic of this PR was tested by manually editing the js of my local extension installation with the equivalent changes (that's how I found that `cwd: ...` ended up working with a local `.buildifier.json`).

---------

Co-authored-by: Cameron Martin <cameronmartin123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants