Coder Social home page Coder Social logo

buildozer's Introduction

buildozer

This Bazel module provides a pinned, prebuilt version of buildozer, a tool for manipulating Bazel BUILD files.

Requirements

  • Bazel 6.2.0 or later

Usage

  1. Add the following line to your MODULE.bazel file:
bazel_dep(name = "buildozer", version = "7.1.2", dev_dependency = True)
  1. Run buildozer via bazel run:
bazel run @buildozer -- ...

The -- is optional if you don't need to pass arguments to buildozer that start with a dash.

Using buildozer in repository rules and module extensions

You can also use buildozer in a repository rule or module extension, i.e., during the loading phase:

  1. Add the following line to your MODULE.bazel file:
bazel_dep(name = "buildozer", version = "7.1.2")
  1. In your repository rule or module extension implementation function, get the path to the buildozer binary as follows:
load("@buildozer//:buildozer.bzl", "BUILDOZER_LABEL")
...
def my_impl(repository_or_module_ctx):
    buildozer = repository_or_module_ctx.path(BUILDOZER_LABEL)
    ...
    repository_or_module_ctx.execute(
        [buildozer, 'set foo bar', '//path/to/pkg:target']
    )

Keep the path call at the top of your implementation function as it may cause a restart of the repository rule.

Alternative usage

If you dont want to or can't load from @buildozer, you can also use the following approach:

  1. Add the following lines to your MODULE.bazel file:
bazel_dep(name = "buildozer", version = "7.1.2")

buildozer_binary = use_extension("@buildozer//:buildozer_binary.bzl", "buildozer_binary")
use_repo(buildozer_binary, "buildozer_binary")
  1. In your repository rule or module extension implementation function, get the path to the buildozer binary as follows:
def my_impl(repository_or_module_ctx):
    # The ".exe" suffix is *not* a typo. It is present on all platforms to support
    # Windows while maintaining a stable label.
    buildozer = repository_or_module_ctx.path(Label("@buildozer_binary//:buildozer.exe))

buildozer's People

Contributors

fmeum avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

buildozer's Issues

@buildozer//:buildozer should have public visibility

I'm using Bazel 7.0.0 and bazel_dep(name = "buildozer", version = "6.4.0").

I'm getting the error

target '@@buildozer~6.4.0//:buildozer' is not visible from target '//tools/common/bazel:make_buildozer_wrapper'.

I would expect @buildozer a.k.a. @buildozer//:buildozer to have public visibility, so that I can make a wrapper that depends on it. It is supposed to be part of the public API of the module, isn't it?

[FR] Support the usage of Buildozer present on host

Hey @fmeum,

I'm running into some issues with bazel mod tidy on Windows in a proxied environment that blocks *.exe downloads. Specifically, the problem arises when it runs: https://github.com/fmeum/buildozer/blob/main/private/buildozer_binary.bzl#L38.

I can install buildozer using:

go install github.com/bazelbuild/buildtools/buildozer@latest

So, I already have buildozer on my host PATH.

I'd like to ask for a way to use the buildozer that's already present on the host. This could be similar to how rules_go allows the use of a host toolchain, despite of its issues (enola-dev/enola#713). I believe this is where they handle it: https://github.com/bazelbuild/rules_go/blob/v0.48.1/go/private/sdk.bzl#L491.

I initially thought about raising this as a feature request for Bazel itself, but I think implementing it directly in this rule set would be more beneficial.

EDIT: I'm working on getting it available in an internal mirror and add it to bazel_downloader.cfg as a potential fix for my current use case.

Still, is this something you'd be open to get implemented? Or think it's feasible?

Potential Workaround

I also think there might be a way to override this in Bazel: https://github.com/bazelbuild/bazel/blob/7.2.1/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModTidyFunction.java#L69. However, it's not totally clear to me if a workaround is currently possible. Since you've implemented a related feature (bazelbuild/bazel#21265), I figured this would be the right place to bring it up.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.