Skip to content

Instantly share code, notes, and snippets.

View gregestren's full-sized avatar

Greg gregestren

  • Google
View GitHub Profile
@gregestren
gregestren / gist:e7afc5a3c3622af326ec49c9e2419c3e
Created June 7, 2023 17:40
genrule reading a build_setting
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
string_flag(
name = "my_flag",
build_setting_default = "",
)
config_setting(
name = "apple",
flag_values = {":my_flag": "apple"},
@gregestren
gregestren / config_stripped_outputs_test.sh
Last active May 22, 2023 20:12
Unexported path stripping tests
#!/bin/bash
#
# Tests stripping config prefixes from output paths for better caching.
#
# What is this?
# -------------------
# Output paths are the paths of files created in a build. For example:
# "blaze-out/k8-fastbuild/bin/myproj/my.output".
#
# The config prefix is the "/k8-fastbuild/" part. That includes the CPU and

query language parsing details

  • The query language parses deps(//foo) as deps(WORD)

  • review of WORD: https://bazel.build/query/language#expressions

  • deps(//label with spaces) doesn't parse because //label with spaces isn't a WORD

  • Quotes can solve this. From https://bazel.build/query/language#kind :

    Quotation of the pattern argument is often required because without it, many regular expressions, such as source file and .*_test, are not considered words by the parser.

@gregestren
gregestren / BUILD
Last active June 24, 2022 01:11
https://github.com/bazelbuild/bazel/issues/15732 demo: transition cache keys don't consider build setting defaults
load("@bazel_skylib/rules:common_settings.bzl", "string_flag")
load("test.bzl", "test_rule")
string_flag(
name = "myflag",
build_setting_default = "a",
)
test_rule(name = "test")
@gregestren
gregestren / BUILD
Last active June 24, 2022 00:41
Demo: transition incrementality bug
load("@bazel_skylib//rules:common_settings.bzl", "string_list_flag")
load("test.bzl", "test_rule")
string_list_flag(
name = "string_list_flag",
build_setting_default = ["default_orig"],
)
test_rule(
name = "test",
@gregestren
gregestren / BUILD
Last active February 1, 2022 01:02
platforms, toolchains, config_settings, and aliases
load(":defs.bzl", "my_rule", "my_toolchain")
# Declare a constraint value and an alias to it.
constraint_setting(name = "test_setting")
constraint_value(
name = "actual_constraint",
constraint_setting = ":test_setting",
)
$ cat flagtest/defs.bzl
def _transition_impl(settings, attr):
return {"//flagtest:other": "b"}
_transition = transition(
implementation = _transition_impl,
inputs = [],
outputs = ["//flagtest:other"],
)