bitter-ability-32190
05/16/2023, 4:50 PMAdhocProcessRequest
construction specify the shell_command.address.spec
after the command?
https://github.com/pantsbuild/pants/blob/d12d7e2026225159219b21aba159bd0b6c3f8d39/src/python/pants/backend/shell/util_rules/shell_command.py#L147
So it looks like:
run_shell_command(
name = "foo",
command=f"echo hi",
workdir="/",
)
turns into:
/usr/bin/bash -c $'echo hi' $'//:foo'
bitter-ability-32190
05/16/2023, 4:52 PMancient-vegetable-10556
05/16/2023, 4:52 PMbash -c 'blah'
doesn’t inject a $0
bitter-ability-32190
05/16/2023, 4:53 PMancient-vegetable-10556
05/16/2023, 4:53 PM$0
, so that you can use other positional parameters. $0
is also what bash shows on errors, so it makes the error messages friendlierancient-vegetable-10556
05/16/2023, 4:53 PM$0
ancient-vegetable-10556
05/16/2023, 4:55 PMcommand
into a shell script and executing that, but that would be similarly obtuse (and less efficient)bitter-ability-32190
05/16/2023, 4:55 PMjq
in a sandbox and trying to figure out how to make these not reference a dead path:
jq - commandline JSON processor [version 1.6]
Usage: /tmp/pants-sandbox-zLIAv5/3rdparty/tools/jq-linux64 [options] <jq filter> [file...]
/tmp/pants-sandbox-zLIAv5/3rdparty/tools/jq-linux64 [options] --args <jq filter> [strings...]
/tmp/pants-sandbox-zLIAv5/3rdparty/tools/jq-linux64 [options] --jsonargs <jq filter> [JSON_TEXTS...]
jq is a tool for processing JSON inputs, applying the given filter to
its JSON text inputs and producing the filter's results as JSON on
standard output.
The simplest filter is ., which copies jq's input to its output
unmodified (except for formatting, but note that IEEE754 is used
for number representation internally, with all that that implies).
For more advanced filters see the jq(1) manpage ("man jq")
and/or <https://stedolan.github.io/jq>
Example:
$ echo '{"foo": 0}' | jq .
{
"foo": 0
}
For a listing of options, use /tmp/pants-sandbox-zLIAv5/3rdparty/tools/jq-linux64 --help.
bitter-ability-32190
05/16/2023, 4:56 PM$0
worked here, should we switch it to putting f"{bin_name() run {spec}"
?ancient-vegetable-10556
05/16/2023, 4:56 PMjq
, there’s not a world in which this should matterancient-vegetable-10556
05/16/2023, 4:57 PM{bin_name()} run {spec}
could be an improvementbitter-ability-32190
05/16/2023, 4:58 PMancient-vegetable-10556
05/16/2023, 4:58 PMrun_shell_command
that we haven’t explored fully yet. This is generally why I prefer adhoc_tool
and would prefer to make these runnablebitter-ability-32190
05/16/2023, 4:59 PMbitter-ability-32190
05/16/2023, 4:59 PMancient-vegetable-10556
05/16/2023, 4:59 PMadhoc_tool
directly invokes processes, which means you don’t have to compensate for bash being obscenebitter-ability-32190
05/16/2023, 5:00 PMancient-vegetable-10556
05/16/2023, 5:00 PMbitter-ability-32190
05/16/2023, 5:00 PMbitter-ability-32190
05/16/2023, 5:00 PMjosh@cephandrius:/tmp/pants-sandbox-zLIAv5$ tree .
.
├── 3rdparty
│ └── tools
│ └── jq-linux64
└── __run.sh
2 directories, 2 files
bitter-ability-32190
05/16/2023, 5:01 PM#!/bin/bash
# This command line should execute the same process as pants did internally.
export <a bunch of env vars>
cd /home/josh/work/<repo>
/usr/bin/bash -c $'/tmp/pants-sandbox-zLIAv5/3rdparty/tools/jq-linux64' $'3rdparty/tools:jq' --help
bitter-ability-32190
05/16/2023, 5:01 PMjq
is using argv[0]
https://github.com/stedolan/jq/blob/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8/src/main.c#L292)bitter-ability-32190
05/16/2023, 5:06 PM$0
ina shell script, but not other programs?
$ /usr/bin/bash -c $'echo $0' $'3rdparty/tools:jq'
3rdparty/tools:jq
ancient-vegetable-10556
05/16/2023, 5:07 PMancient-vegetable-10556
05/16/2023, 5:19 PMjq
shouldn’t be receiving argv[0]
from bash
. Bash should only be using the argv[0]
for its internal purposesancient-vegetable-10556
05/16/2023, 5:19 PM$@
into jq
or something like that?bitter-ability-32190
05/16/2023, 5:20 PM__run.sh
and the treebitter-ability-32190
05/16/2023, 5:20 PMancient-vegetable-10556
05/16/2023, 5:20 PMancient-vegetable-10556
05/16/2023, 5:21 PM__run.sh
, but in this case, I’ll actually need to see the target definition from your BUILD
file, and possibly also your pants invocationbitter-ability-32190
05/16/2023, 5:22 PMancient-vegetable-10556
05/16/2023, 5:22 PM__run.sh
fileancient-vegetable-10556
05/16/2023, 5:22 PM__run.sh
unless you pass it inbitter-ability-32190
05/16/2023, 5:23 PMexec -a "string" <command>
According to exec --help
Options:
-a name pass NAME as the zeroth argument to COMMAND
-c execute COMMAND with an empty environment
-l place a dash in the zeroth argument to COMMAND
ancient-vegetable-10556
05/16/2023, 5:23 PMbash -c "exec -a \"shell name\" shlexed_command"
?bitter-ability-32190
05/16/2023, 5:23 PMancient-vegetable-10556
05/16/2023, 5:24 PMcommand
is and spit it out to the terminal, that will really helpbitter-ability-32190
05/16/2023, 5:25 PMfile(
name=f"downloaded-{name}",
source = http_source(
len = len,
sha256 = sha256,
url = url,
),
)
filename = url.rsplit("/", 1)[-1]
command = f"chmod +x {filename}"
if filename.endswith(".tar.gz"):
command = f"tar -xf {filename} &&" + command
shell_command(
name = f"sandboxed-{name}",
command=command,
tools = ["tar", "chmod"],
execution_dependencies=[f":downloaded-{name}"],
output_directories = ["."],
#root_output_directory = f"unpacked-{name}",
)
run_shell_command(
name = name,
command=f"{{chroot}}/{build_file_dir() / exe}",
execution_dependencies=[f":sandboxed-{name}"],
workdir="/",
)
bitter-ability-32190
05/16/2023, 5:25 PMpeek
and see if that dumps it easilybitter-ability-32190
05/16/2023, 5:26 PM{
"address": "3rdparty/tools:jq",
"target_type": "run_shell_command",
"command": "{chroot}/3rdparty/tools/jq-linux64",
"dependencies": [
"3rdparty/tools:sandboxed-jq"
],
"description": null,
"execution_dependencies": [
":sandboxed-jq"
],
"runnable_dependencies": null,
"tags": null,
"workdir": "/"
}
ancient-vegetable-10556
05/16/2023, 5:26 PM--
?bitter-ability-32190
05/16/2023, 5:26 PM{
"address": "3rdparty/tools:downloaded-jq",
"target_type": "file",
"dependencies": [],
"dependencies_raw": null,
"description": null,
"source_raw": {
"url": "<https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64>",
"len": 3953824,
"sha256": "af986793a515d500ab2d35f8d2aecd656e764504b789b66d7e1a0b727a124c44",
"filename": "jq-linux64"
},
"sources": [],
"sources_fingerprint": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"tags": null
}
and
{
"address": "3rdparty/tools:sandboxed-jq",
"target_type": "shell_command",
"_sources_raw": null,
"command": "chmod +x jq-linux64",
"dependencies": [
"3rdparty/tools:downloaded-jq"
],
"description": null,
"environment": "__local__",
"execution_dependencies": [
":downloaded-jq"
],
"extra_env_vars": null,
"log_output": false,
"output_dependencies_raw": null,
"output_directories": [
"."
],
"output_files": [],
"outputs": null,
"root_output_directory": "/",
"runnable_dependencies": null,
"sources": [],
"sources_fingerprint": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"tags": null,
"timeout": 30,
"tools": [
"tar",
"chmod"
],
"workdir": "."
}
bitter-ability-32190
05/16/2023, 5:27 PMpants run <thing> -- --help
. Sorry there a small bit of messaging of the files before I posted herebitter-ability-32190
05/16/2023, 5:27 PMBUILD
file, one momentbitter-ability-32190
05/16/2023, 5:33 PMfile(
name="downloaded-jq",
source = http_source(
len = 3953824,
sha256 = "af986793a515d500ab2d35f8d2aecd656e764504b789b66d7e1a0b727a124c44",
url = "<https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64>",
),
)
shell_command(
name = "sandboxed-jq",
command="chmod +x jq-linux64",
tools = ["chmod"],
execution_dependencies=[":downloaded-jq"],
output_directories = ["."],
)
run_shell_command(
name = "jq",
command=f"{{chroot}}/{build_file_dir() / 'jq-linux64'}",
execution_dependencies=[":sandboxed-jq"],
workdir="/",
)
bitter-ability-32190
05/16/2023, 5:38 PM/usr/bin/bash -c "exec -a $'//:jq' /tmp/pants-sandbox-AqjSjG/jq-linux64 --help"
bitter-ability-32190
05/16/2023, 5:38 PMUsage: //:jq [options] <jq filter> [file...]
//:jq [options] --args <jq filter> [strings...]
//:jq [options] --jsonargs <jq filter> [JSON_TEXTS...]
ancient-vegetable-10556
05/16/2023, 5:39 PMrun
a system_binary
target (which I believe you can do).bitter-ability-32190
05/16/2023, 5:39 PMancient-vegetable-10556
05/16/2023, 5:39 PMbash
is always going to mean there’s some fuckery going on that’s impossible to inspect (this is why I prefer people to not use shell_command
etc)ancient-vegetable-10556
05/16/2023, 5:39 PMsystem_binary
is that it has to be on your systemancient-vegetable-10556
05/16/2023, 5:40 PMfile
dependency executableancient-vegetable-10556
05/16/2023, 5:40 PMrun_system_binary
is very easy to understand, and I’d welcome a pull request 🙂ancient-vegetable-10556
05/16/2023, 5:40 PMadhoc_tool
exists entirely to make it easier to reason about how a process is getting executedbitter-ability-32190
05/16/2023, 5:43 PMsystem_binary
has no dependencies
field 😭bitter-ability-32190
05/16/2023, 5:43 PMancient-vegetable-10556
05/16/2023, 5:45 PMsystem_binary
, but I think some concept of a file_as_binary
would make sense; in case you have an arbitrary binary in your codebase, or need to download itbitter-ability-32190
05/16/2023, 5:45 PMancient-vegetable-10556
05/16/2023, 5:45 PMbitter-ability-32190
05/16/2023, 5:46 PMancient-vegetable-10556
05/16/2023, 5:47 PMadhoc_tool
the following month 🙃bitter-ability-32190
05/16/2023, 5:47 PM2.16.x
though.ancient-vegetable-10556
05/16/2023, 5:48 PMbash
is going to continue having bugs, and directing people away from indirection through bash is the way of the future 😉ancient-vegetable-10556
05/16/2023, 5:48 PMbitter-ability-32190
05/16/2023, 5:48 PMancient-vegetable-10556
05/16/2023, 5:49 PMexec
-based alternative that fixes your issueancient-vegetable-10556
05/16/2023, 5:49 PMbitter-ability-32190
05/16/2023, 5:49 PMancient-vegetable-10556
05/16/2023, 5:50 PMcommand="blah"
, blah
is executed inside a bash shellbitter-ability-32190
05/16/2023, 5:50 PMancient-vegetable-10556
05/16/2023, 5:51 PMbitter-ability-32190
05/16/2023, 6:15 PMbitter-ability-32190
05/16/2023, 8:23 PMbitter-ability-32190
05/16/2023, 8:26 PMancient-vegetable-10556
05/16/2023, 8:28 PMbitter-ability-32190
05/16/2023, 8:28 PMexec -a
I realized I should be running it 🤦♂️bitter-ability-32190
05/16/2023, 8:30 PM