Created
June 22, 2017 01:01
-
-
Save kmtr/6e917786c254596cc6fa361f47061c86 to your computer and use it in GitHub Desktop.
cargo metadataでプロジェクトの情報を取得する ref: http://qiita.com/kmtr/items/21fe9fd6c25f55169e61
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo init --bin ferris | |
$ cd ferris | |
$ ls | |
Cargo.lock Cargo.toml src | |
$ cargo metadata --format-version=1 | |
{"packages":[{"name":"ferris","version":"0.1.0","id":"ferris 0.1.0 (path+file:///path/to/ferris)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["bin"],"crate_types":["bin"],"name":"ferris","src_path":"/path/to/ferris/src/main.rs"}],"features":{},"manifest_path":"/path/to/ferris/Cargo.toml"}],"workspace_members":["ferris 0.1.0 (path+file:///path/to/ferris)"],"resolve":{"nodes":[{"id":"ferris 0.1.0 (path+file:///path/to/ferris)","dependencies":[]}],"root":"ferris 0.1.0 (path+file:///path/to/ferris)"},"target_directory":"/path/to/ferris/target","version":1} | |
$ cargo metadata --format-version=1 | jq .packages[0].name | |
"ferris" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo metadata --format-version=1 | jq '.packages | map(select( .name == "ferris" )) | .[0].dependencies' | |
[] | |
$ echo 'regex = "0.2.2"' >> Cargo.toml | |
$ cargo metadata --format-version=1 | jq '.packages | map(select( .name == "ferris" )) | .[0].dependencies' | |
Updating registry `https://github.com/rust-lang/crates.io-index` | |
[ | |
{ | |
"name": "regex", | |
"source": "registry+https://github.com/rust-lang/crates.io-index", | |
"req": "^0.2.2", | |
"kind": null, | |
"optional": false, | |
"uses_default_features": true, | |
"features": [], | |
"target": null | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo metadata --format-version=1 --no-deps | jq .packages[0].dependencies | |
[ | |
{ | |
"name": "regex", | |
"source": "registry+https://github.com/rust-lang/crates.io-index", | |
"req": "^0.2.2", | |
"kind": null, | |
"optional": false, | |
"uses_default_features": true, | |
"features": [], | |
"target": null | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: version | |
version: | |
@echo $(shell cargo metadata --format-version=1 --no-deps \ | |
| jq .packages[0].version) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ make version | |
0.1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment