Greetings Pants friends! I have a script that pro...
# general
a
Greetings Pants friends! I have a script that produces our Flutter build artifacts called, creatively,
./build.sh
. I am able to configure this to run successfully using Pants 1.16
run_shell_command
. Executing via
./pants run :build-flutter
produces the expected artifacts. These are then copied into our docker container. If the files are present in the source files, then the
files
and
docker_image
targets work perfectly. I'm having trouble sequencing dependencies so that the script is executed before other targets. Is this supported? Here's my BUILD file
Copy code
files(
    name="flutter-source",
    sources=[
        "./**",
    ]
)

shell_sources(name="shell-scripts")

# produces build artifacts in source code workspace
run_shell_command(
    name="build-flutter",
    command="cd realtime/cloud_ui && ./build.sh",
    execution_dependencies=[":shell-scripts", ":flutter-source"]
)

files(
    name="docker-assets",
    dependencies=[":build-flutter"],
    sources=[
        "./Caddyfile",
        "./docker_entrypoint.sh",
        "./build/web/**",
    ]
)

docker_image(
    name="neuroedge_cloud_ui",
    dependencies=[
        ":docker-assets"
    ],
    image_tags=["latest"]
)
when I execute
./pants package :neuroedge_cloud_ui
, I expect the dependency chain will invoke
:build-flutter
to produce the required "_./build/web/**"_ files matched by
:docker-assets
but this is not the case. If I run
:build-flutter
and then package
:neuroedge_cloud_ui
all is well. Is it possible to ensure that
:build-flutter
is always run as a dependency of
:build-flutter
?
👋🏽 1
👋 2
Well, hot damn! I think I figured it out.
Copy code
files(
    name="flutter-source",
    sources=[
        "./**",
    ]
)

shell_sources(name="shell-scripts")

shell_command(
    name="build-flutter",
    command="./build.sh",
    tools=["basename", "bash", "cat", "chmod", "dirname", "env", "git", "flutter", "mkdir", "readlink", "rm", "sleep", "sw_vers", "uname", "which"],
    execution_dependencies=[":shell-scripts", ":flutter-source"],
    output_directories=["build"],
    log_output=True,
    timeout=120
)


files(
    name="docker-assets",
    sources=[
        "./Caddyfile",
        "./docker_entrypoint.sh",
        # "./build/web/**", <- produced by :build-flutter
    ]
)

docker_image(
    name="neuroedge_cloud_ui",
    dependencies=[
        ":build-flutter",
        ":docker-assets"
    ],
    image_tags=["latest"]
)
I am concerned about the need to specify each tool that should be available in the PATH as an update to Flutter will very likely change this but it will be rather challenging to troubleshoot for people lacking Pants expertise.
h
@ancient-vegetable-10556 can you weigh in?
a
Sure, I'll be back at my desk shortly
@aloof-appointment-30987 Hi! We’re looking at a way of being able to specify
runnable_dependencies
transitively, but that doesn’t exist at the moment. In the meantime, it’s useful to remember that
BUILD
files are actually Python files, which means you can define variables if you want to (so you could make the
tools
list a variable. Better still, you can define a macro for a
flutter_build
, which would just specify the input files, and output most of the
shell_command
boilerplate for each target. Finally, I recommend looking at
system_binary
as a way to version test your
flutter
binary — that way you can make sure that you’re always running a correct version of
flutter
(see https://www.pantsbuild.org/v2.16/docs/adhoc-tool#using-externally-managed-tools)
a
hi @ancient-vegetable-10556, could you point me to docs or example where a variable is used in a target property and can be configured either in pants.toml or bootstrap?
a
@aloof-appointment-30987 You can generally only define variables in
BUILD
files, I think
Defining a macro may be better here, since you can define them once, and reuse them in multiple files.