Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get CARGO_PKG_VERSION inside justfile? #655

Open
Boscop opened this issue Jul 13, 2020 · 3 comments
Open

How to get CARGO_PKG_VERSION inside justfile? #655

Boscop opened this issue Jul 13, 2020 · 3 comments

Comments

@Boscop
Copy link

Boscop commented Jul 13, 2020

I have a cmd in my justfile to package my release binary in a zip file, and I want to name the zip file after the CARGO_PKG_VERSION. How can I read the value of CARGO_PKG_VERSION in the justfile? :)

@casey
Copy link
Owner

casey commented Jul 14, 2020

There isn't direct support in Just for this, but I use the following to extract the crate version into a variable:

version := `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/v\1/p' Cargo.toml | head -1`

Does that work for your use case?

@Boscop
Copy link
Author

Boscop commented Jul 14, 2020

@casey Thanks! This works:

version_subcrate := `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/v\1/p' subcrate/Cargo.toml | head -1`

pkg-subcrate:
    echo {{version_subcrate}}

But is there a way I can make this reuseable as a function, callable like version(subcrate)?
Because I have several binary subcrates and need this for all of them.

@casey
Copy link
Owner

casey commented Jul 14, 2020

There isn't currently a way to define functions, although I could imagine letting recipes be called as functions in expressions though:

version SUBCRATE:
    sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/v\1/p' {{SUBCRATE}}/Cargo.toml | head -1

pkg-foo:
  echo {{version("foo")}}

One issue with this is that currently, Just doesn't really have a type system. Or, rather, the only type of value are strings, and a small number of built-in functions types which are special cased.

If it were possible to define functions, then these functions would have different arities, and validating statically that functions are called with the correct number of arguments might be tricky. (I would strongly prefer to do static type checking over dynamic, even though doing it dynamically would probably be easier.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants