GithubHelp home page GithubHelp logo

Comments (6)

zjturner avatar zjturner commented on April 28, 2024

Try this:

In your .buckconfig file:

[gsoyka]
is_ci = false

In a BUCK file somewhere:

build_go_binary = not read_config("gsoyka", "is_ci", false)

go_binary(
    name = "hello",
    srcs = glob(["*.go"]),
    deps = [
        "//go/hello/greeting:greeting",
    ],
) if build_go_binary else None

from buck2.

gsoyka avatar gsoyka commented on April 28, 2024

Thanks, that's helpful, and I think that can be made to work for my use case. If I have a rule defined, eg. my_rule(), is it possible to generalize that logic to apply to all my_rule instances within a project when the config value is set to true?

from buck2.

zjturner avatar zjturner commented on April 28, 2024

You could make a macro. From a bzl file somewhere:

build_go_binary = not read_config("gsoyka", "is_ci", false)

def my_rule_macro(name, srcs, deps):
    go_binary(
        name = "hello",
        srcs = glob(["*.go"]),
        deps = [
            "//go/hello/greeting:greeting",
        ],
    ) if build_go_binary else None

and have people call your macro instead of your rule.

from buck2.

gsoyka avatar gsoyka commented on April 28, 2024

That makes sense to me, when I tried the example I'm seeing the behavior I want, but am getting an error about a missing symbol. Is there something the macro can return that isn't None that still does nothing?

from buck2.

zjturner avatar zjturner commented on April 28, 2024

Try:

if build_go_binary:
go_binary(…)

hard to say without seeing your error

from buck2.

cjhopman avatar cjhopman commented on April 28, 2024

Reading the docs, it seems like constraints added to our platform should work

Yeah, marking it target incompatible will cause it to be skipped without error when resolved in a pattern like //... or //foo: (but error when used explicitly like //foo:xyz).

You could actually still use the config value to set things up if you wanted, somethign like this could work:

constraint_setting(
  name = "none",
)

my_rule(
  ...
  target_compatible_with = [] if read_config("foo", "is_ci", False) else [":none"]
)

from buck2.

Related Issues (20)

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.