fresh-continent-76371
11/09/2022, 9:48 PMjava -Xmx500M -cp "/usr/local/lib/antlr-4.9.3-complete.jar:.:/usr/local/lib/antlr-4.9.3-complete.jar" org.antlr.v4.Tool
At a simple level this is experimental_shell_command
,
am I correct in thinking i can get Pants to "supply" the JVM, and the antlr dependency.
adding the jvm backend, gives me the jvm_artifact(...)
to pull antlr,
How do i make the "jvm" a tool / dependency to the experimental_shell_command
or is there a "java run" type target instead ?bitter-ability-32190
11/09/2022, 10:00 PMfresh-continent-76371
11/09/2022, 10:06 PMfresh-continent-76371
11/09/2022, 10:08 PMbitter-ability-32190
11/09/2022, 10:09 PMbitter-ability-32190
11/09/2022, 10:10 PMfresh-continent-76371
11/09/2022, 10:21 PMjvm_artifact
name look like, that I am able to add it to the shell_command( ..., dependencies["whatgoeshere"], ...)
I have my artifact as
jvm_artifact(
group="org.antlr",
artifact="antlr-complete",
version="4.9.3",
)
witty-crayon-22786
11/09/2022, 10:50 PMwitty-crayon-22786
11/09/2022, 10:51 PMdeploy_jar
target which depended on the jvm_artifact
(explicitly), and then have your experimental_shell_command
depend on the deploy_jar
witty-crayon-22786
11/09/2022, 10:52 PMdeploy_jar
using its name, which is well defined: https://www.pantsbuild.org/docs/reference-deploy_jar#codeoutput_pathcode
java -Xmx500M -jar $my_deploy_jars_name
witty-crayon-22786
11/09/2022, 10:54 PMfresh-continent-76371
11/09/2022, 11:12 PMfresh-continent-76371
11/09/2022, 11:13 PM[jvm]
jdk = "temurin:1.17"
[jvm.resolves]
jvm-default = "lib/3rdparty/jvm/default.lock"
and now
10:11:07.92 [ERROR] 1 Exception encountered:
KeyError: 'entries'
which is
• not a great error mesaage 🙂witty-crayon-22786
11/09/2022, 11:13 PMfresh-continent-76371
11/09/2022, 11:14 PMwitty-crayon-22786
11/09/2022, 11:14 PM./pants generate-lockfiles
to generate the filefresh-continent-76371
11/09/2022, 11:14 PMwitty-crayon-22786
11/09/2022, 11:15 PMbitter-ability-32190
11/09/2022, 11:15 PMbitter-ability-32190
11/09/2022, 11:15 PMwitty-crayon-22786
11/09/2022, 11:15 PMfresh-continent-76371
11/09/2022, 11:16 PM10:14:46.00 [ERROR] 1 Exception encountered:
Exception: Unmatched glob from The resolve `jvm-default` from `[jvm].resolves`: "lib/3rdparty/jvm/default.lock"
Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.14/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
witty-crayon-22786
11/09/2022, 11:16 PMfresh-continent-76371
11/09/2022, 11:16 PM./pants generate-lockfiles
witty-crayon-22786
11/09/2022, 11:16 PMfresh-continent-76371
11/09/2022, 11:17 PMexperimental_shell_command
witty-crayon-22786
11/09/2022, 11:23 PMwitty-crayon-22786
11/09/2022, 11:23 PMwitty-crayon-22786
11/09/2022, 11:24 PMfresh-continent-76371
11/09/2022, 11:25 PMjvm_artifact(
name="antlr",
group="org.antlr",
artifact="antlr4",
version="4.11.1",
)
deploy_jar(
name="pkg",
main="org.antlr.v4.Tool",
dependencies=[":antlr"],
)
#
# just a shell to see what it going on, inside
#
experimental_shell_command(
name="asm_parser",
command="tree",
outputs=[ "./" ],
dependencies=[":pkg"], # ":org.antlrantlr-complete"],
tools=["tree"]
)
./pants run path/to/generator
10:22:03.95 [INFO] Completed: Assemble combined JAR file
ANTLR Parser Generator Version 4.11.1
-o ___ specify output directory where all output is generated
-lib ___ specify location of grammars, tokens files
-atn generate rule augmented transition network diagrams
-encoding ___ specify grammar file encoding; e.g., euc-jp
-message-format ___ specify output style for messages in antlr, gnu, vs2005
-long-messages show exception details when available for errors and warnings
-listener generate parse tree listener (default)
-no-listener don't generate parse tree listener
-visitor generate parse tree visitor
-no-visitor don't generate parse tree visitor (default)
-package ___ specify a package/namespace for the generated code
-depend generate file dependencies
-D<option>=value set/override a grammar-level option
-Werror treat warnings as errors
-XdbgST launch StringTemplate visualizer on generated code
-XdbgSTWait wait for STViz to close before continuing
-Xforce-atn use the ATN simulator for all predictions
-Xlog dump lots of logging info to antlr-timestamp.log
-Xexact-output-dir all output goes into -o dir regardless of paths/package
I assume that, whilst run did run the jar, that was not running the "experimental_shell_command" - but rather the "deploy_jar"witty-crayon-22786
11/09/2022, 11:28 PMexperimental_shell_command
, you’ll want to pass its name: ./pants run path/to/generator:asm_parser
witty-crayon-22786
11/09/2022, 11:28 PMpkg
ended up selected there. @bitter-ability-32190 might know better.bitter-ability-32190
11/09/2022, 11:33 PMwitty-crayon-22786
11/09/2022, 11:33 PMbitter-ability-32190
11/09/2022, 11:34 PMwitty-crayon-22786
11/09/2022, 11:35 PMwitty-crayon-22786
11/09/2022, 11:35 PMpkg
?witty-crayon-22786
11/09/2022, 11:36 PMfresh-continent-76371
11/09/2022, 11:37 PMexperimental_shell_command
is not runnable anyway .
looks like it just picked the "first" off the list of possibles.
❯ ./pants run apps/generator:asm_parser
10:33:45.90 [ERROR] 1 Exception encountered:
NoApplicableTargetsException: No applicable files or targets matched. The `run` goal works with these target types:
* deploy_jar
* docker_image
* experimental_run_shell_command
* pex_binary
* python_source
* python_test
However, you only specified target arguments with these target types:
* experimental_shell_command
Please specify relevant file and/or target arguments. Run `./pants --filter-target-type=deploy_jar,docker_image,experimental_run_shell_command,pex_binary,python_source,python_test list ::` to find all applicable targets in your project, or run `./pants --filter-target-type=deploy_jar,docker_image,experimental_run_shell_command,pex_binary,python_source,python_test filedeps ::` to find all applicable files.
witty-crayon-22786
11/09/2022, 11:38 PMshunit_test
that depends on the experimental_shell_command
to test its outputsfresh-continent-76371
11/09/2022, 11:39 PMpackage
is not for experimental_shell_command
bitter-ability-32190
11/09/2022, 11:39 PMwitty-crayon-22786
11/09/2022, 11:41 PMexperimental_shell_command
just produces loose files, which aren’t really packaged in any particular way… if you want to emit files as an archive
, you could add an archive
target that depends on your experimental_shell_command
, and then ./pants package $my-archive
would put them under $buildroot/dist
witty-crayon-22786
11/09/2022, 11:41 PMshunit_test
for ./pants test
, etcwitty-crayon-22786
11/09/2022, 11:41 PMpython_test
, for that matterhappy-kitchen-89482
11/10/2022, 1:13 AMenough-analyst-54434
11/10/2022, 2:31 AMenough-analyst-54434
11/10/2022, 2:31 AMenough-analyst-54434
11/10/2022, 2:33 AMfresh-continent-76371
11/10/2022, 3:38 AMfresh-continent-76371
11/10/2022, 3:52 AMexperimental_run_command
cannot by "executed" directly from the command line, by a goalenough-analyst-54434
11/10/2022, 4:01 AM--keep-sandboxes=always
. You should get Pants log lines noting the various sandbox directories left laying around. You can CD into the one you care about (hopefully which one is easy enough to figure out) and you can look at __run.sh
to see what Pants runs and play around with things.fresh-continent-76371
11/10/2022, 4:03 AMfresh-continent-76371
11/10/2022, 4:04 AMfresh-continent-76371
11/10/2022, 6:35 AMexperimental_shell_command
and feed it to python_distribution
- which then means maybe I should just write a codegen antlr plugin
4. It would be good to be given variables to the dependencies (path or file), by name,
5. also a variable of the "ROOT" of the sanbox, It is brittle to be depending on the path (depth) and full paths to dependencies generated.
jvm_artifact(
name="antlr-dependency",
group="org.antlr",
artifact="antlr4",
version="4.11.1",
)
deploy_jar(
name="antlr-complete",
main="org.antlr.v4.Tool",
dependencies=[":antlr-dependency"],
)
resource(
name="my_antlr_grammar",
source="folder/my_grammar.g4"
)
experimental_shell_command(
name="asm_parser",
command="""
mkdir out && \
java -jar $(find ../../../../ -name antlr-complete.jar ) \
-o out/ \
-visitor \
-Dlanguage=Python3 folder/my_grammar.g4
""",
outputs=[ "out/" ],
dependencies=[":antlr-complete", ":qps_asm_antlr_grammar"],
tools=["tree", "java", "find"],
)
archive(
name="qps_asm_lexer",
files=[":asm_parser"],
format="zip"
)
gorgeous-winter-99296
11/10/2022, 3:03 PMpants.backend.docker
is the one I end up using. That gives you export-codegen
, which does that. I'm using that for my codegen-adventures. 🙂 I.,e in your case you'd pants export-codegen //some/path:asm-parser
and you can skip the archive step if you don't need it.gorgeous-winter-99296
11/10/2022, 3:06 PMexperimental_run_shell_command
will work for that - my plan is to use that to generate goldens for CI but using the shell command output directly in all build steps.happy-kitchen-89482
11/10/2022, 4:57 PMhappy-kitchen-89482
11/10/2022, 4:57 PMdist
sounds necessary? Could be export
, or package
, both of which do that today in their respective areasancient-vegetable-10556
11/10/2022, 5:00 PMexperimental_shell_command
and friends would benefit from having a way to export filesancient-vegetable-10556
11/10/2022, 5:05 PMexperimental_run_shell_command
with a command of cp {chroot]/artifact.txt *PATH_IN_WORKSPACE*
and dependencies of the step that you want to run ion the sandboxfresh-continent-76371
11/11/2022, 2:40 AMat the moment, the “obvious” way to do it is to create anso to make that work the best, injecting thewith a command ofexperimental_run_shell_command
and dependencies of the step that you want to run ion the sandboxcp {chroot]/artifact.txt *PATH_IN_WORKSPACE*
PATH_IN_WORKSPACE
value to the ...shell...
is the need, as this full path varies across CI, and user workstations.fresh-continent-76371
11/11/2022, 2:43 AMfresh-continent-76371
11/11/2022, 3:07 AMexperimental_shell_command
like
experimental_shell_command(
...
extra_env_vars = [ "BUILDROOT=" + GetBuildRoot(), "BUILD_FILE_PATH=" + GetBuildFilePath() ],
...
)
ancient-vegetable-10556
11/15/2022, 5:13 PMancient-vegetable-10556
11/15/2022, 5:14 PMdependencies
, so that they get copied into the sandbox.ancient-vegetable-10556
01/09/2023, 10:46 PMmain
(i.e. future 2.16)fresh-continent-76371
01/27/2023, 8:44 PMancient-vegetable-10556
01/27/2023, 9:37 PM