1

How can I put all targets from a package into one variable in a higher-level package? I'm trying to create a simulation framework with the following architecture:

.
├── run_simulation.py
├──data
|   ├── folder1
|   │   ├── file_1.cvs
|   │   ...
|   │   └── file_k.csv
|   ├── folder2
|   │   ├── file_1.cvs
|   │   ...
|   │   └── file_k.csv
|   └── BUILD
└── BUILD

the data/BUILD file consists of:

data_dirs = [
    "folder1", 
    "folder2"
]

[
filegroup(
    name = "my_cool_data_" + data_dir,
    srcs = glob(["{}/*.csv".format(data_dir)]),
    ...
) for data_dir in data_dirs
]

and produce a target with experimental data per a folder. I'd like to run the script run_simulation.py with inputs from folders in the data directory with a command like:

$ bazel run run_simulation_<data target name>

so I have to add to the ./BUILD file

data_targets=[*do smth to get all targets from data/BUILD file*]

[
py_binary(
    name = "run_simulation_" + data_target,
    ...
    data = ["//data:{}".format(data_target)],
    ...
) for data_target in data_targets
]

The problem is how can I put all targets from the data package into a variable in the ./BUILD file? I couldn't find a way to do this in the official documentation.

slsy
  • 1,257
  • 8
  • 21
falsekeel
  • 157
  • 5
  • 1
    Potentially related question/answer: https://stackoverflow.com/questions/62304448/use-bazel-query-inside-a-build-file. In our case, since `data_dirs` drives both `filegroup` and `py_binary` targets, you could simply share the list and use it in both BUILD files, see _Sharing variables across multiple BUILD files_ https://docs.bazel.build/versions/main/skylark/tutorial-sharing-variables.html#sharing-variables-across-multiple-build-files – dms Jul 26 '21 at 02:34

0 Answers0