Seems like setting DAML_PROJECT
affects daml codegen
as well, and it seems this is intentional. Why is that? What is missing if I run this command:
daml codegen java --output=java_files an_example.dar
daml codegen java
defaults to reading the information from the daml.yaml
which we locate in DAML_PROJECT
. The codegen uses either CLI args or DAML_PROJECT
but not both atm, so in your example DAML_PROJECT
won’t be used.
Assume I am in a valid Daml project. If I issue the following commands:
unset DAML_PROJECT
daml build --output=example.dar
export DAML_PROJECT=an_unrelated_path
daml codegen java --output=java_files example.dar
the last command will fail. If I understood you correctly, this should not happen.
The fix in my use case was pretty easy, I was just a bit surprised.
Oh sorry, you are right and this is expected. We use DAML_PROJECT
to figure out the SDK version. Otherwise (if you don’t have DAML_SDK_VERSION set) we use whatever SDK version you currently have globally which is rarely what you want and definitely not consistent across developers in your team.
So specifying the DAML_SDK_VERSION
would also work, or using DAML_PROJECT
consistently (which I did in my case).
For education purposes: would it hard/impractical/impossible to figure out the SDK version from the DAR file?
The SDK version is figured out by the assistant before invoking the underlying tool (the codegen in this case). The assistant has no understanding of the command line parameters of the underlying tool (it just passes them through) so it can’t know what refers to a DAR and what doesn’t. The codegen does understand the parameters of course but once the codegen is invoked the SDK version is already fix. The assistant only understands a few environment variables and parts of daml.yaml
so that’s the only thing that affects the SDK version.
As for whether the codegen could figure out the SDK version (ignoring whether that would be useful since as mentioned above, it’s too late), you
you can technically get the SDK version a DAR was built with but it’s perfectly reasonable to run a newer codegen against that (and even older codegens assuming they support the lf version) so inferring the SDK version from the DAR isn’t all that useful.