Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in tools.deps by
Enhancement Description

Add main opts to {{-Sdescribe}} output. This could simply be a new {{:main-opts}} key along with a string value representing the content of the main opts cache file, if one exists, or an empty string otherwise.

Rationale

Downstream execution environments can make use of the main opt information when using {{clojure}} for dependency download, classpath construction, and main opt selection via aliases. Another way to look at this is that, in the same way that {{-Spath}} provides useful information when composing {{clojure}} with other executable environments that can consume classpaths, access to the main opts is also similarly useful when composing. This need probably isn't sufficiently strong to warrant polluting the options list with a new {{-Smain-opts}} flag; putting this into {{-Sdescribe}} output is likely sufficient.

A secondary rationale might be that this could be useful to humans for debugging purposes.

Implementation Considerations

This could be as simple as a single new line in the script, perhaps placed after the line that emits {{:main-aliases}} in the {{-Sdescribe}} output.

:main-opts "$(cat "$main_file")"

This would work for most normal use cases, but could perhaps be dependent upon what happens with TDEPS-56, where there might end up being some platform-specific changes made to properly handle the case when a main opt has a space embedded in it. (Perhaps in light of this, {{clojure}} could take the stance that {{:main-opts}} isn't guaranteed to be final; this is consistent with things still being in alpha, and perhaps also consistent with {{-Sdescribe}} not really being formal API.)

3 Answers

0 votes
by
_Comment made by: mfikes_

With

{code:title=deps.edn}
{:aliases {:foo {:main-opts ["-m" "foo.core" 1 2 3]}}}


the attached patch causes {{clojure -Sdescribe -A:foo}} to emit


{:version "1.9.0.358"
 :config-files ["/usr/local/lib/clojure/deps.edn" "/home/ubuntu/.clojure/deps.edn" "deps.edn" ]
 :install-dir "/usr/local/lib/clojure"
 :config-dir "/home/ubuntu/.clojure"
 :cache-dir ".cpcache"
 :force false
 :repro false
 :main-opts "-m foo.core 1 2 3"
 :resolve-aliases ""
 :classpath-aliases ""
 :jvm-aliases ""
 :main-aliases ""
 :all-aliases ":foo"}


on both macOS and Ubuntu 16.04. And {{clojure -Sdescribe}} emits


{:version "1.9.0.358"
 :config-files ["/usr/local/lib/clojure/deps.edn" "/home/ubuntu/.clojure/deps.edn" "deps.edn" ]
 :install-dir "/usr/local/lib/clojure"
 :config-dir "/home/ubuntu/.clojure"
 :cache-dir ".cpcache"
 :force false
 :repro false
 :main-opts ""
 :resolve-aliases ""
 :classpath-aliases ""
 :jvm-aliases ""
 :main-aliases ""
 :all-aliases ""}


The patch redirects error to {{/dev/null}} to handle the second case above where the main cache file doesn't exist.
0 votes
by

Comment made by: alexmiller

There are actually two sources of main options to consider: 1) the .main file which holds the outcome of main opts aliases and 2) any additional options specified on the command line. Seems like either these should be combined into a single unified main options set or should be included as separate keys. My first instinct would be the former, but would need to think about that a bit more.

The suggested approach also does not "clojure-ify" the data and just treats the whole thing as a string. We already have issues around escaping and I'd like to solve this in the most correct way possible, probably in light of other changes necessary around quoting in the .main file.

0 votes
by
Reference: https://clojure.atlassian.net/browse/TDEPS-72 (reported by mfikes)
...