diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2024-11-14 15:55:45 +0100 |
---|---|---|
committer | Alberto Sartori <alberto.sartori@huawei.com> | 2024-11-27 10:18:48 +0100 |
commit | 576cef0810e78805e4ac5d8b019e4773bc58bebb (patch) | |
tree | d2132be5fab3f74fbc00a0b9e61fab6440a4781b | |
parent | 433d4a4b8360ee96021ebf6ee3069fd31387a5d1 (diff) | |
download | rules-rust-576cef0810e78805e4ac5d8b019e4773bc58bebb.tar.gz |
just-import-cargo: handle special case when a local repository is staged...
...in a directory with the same name of the crate. If crate "foo",
version 1.0.0 is staged in directory "/dir/bar", it will reported in
the output of `cargo metadata` as
path+file:///dir/bar#foo@1.0.0
However, if the same crate "foo" is staged is "/dir/foo", `cargo
metadata` will report
path+file:///dir/foo#1.0.0
-rwxr-xr-x | bin/just-import-cargo.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/bin/just-import-cargo.py b/bin/just-import-cargo.py index ad22478..86d55da 100755 --- a/bin/just-import-cargo.py +++ b/bin/just-import-cargo.py @@ -107,7 +107,7 @@ def split_id(id: str): # metadata provided by stable cargo, as of 2024-03-18 name, version, source = id.split() source = source[1:-1] - except Exception as e: + except ValueError as e: if id.startswith("registry"): # "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.153" source, name_version = id.split("#") @@ -115,11 +115,20 @@ def split_id(id: str): elif id.startswith("path"): # path+file:///home/username/opt/src/commonlibrary_rust_ylong_runtime#ylong_io@1.0.0 - source, name_version = id.split("#") - name, version = name_version.split("@") + # or + # path+file:///tmp/hashbrown#0.14.3 + if id.find("@") >= 0: + source, name_version = id.split("#") + name, version = name_version.split("@") + else: + source, version = id.split("#") + name = source.split("/")[-1] else: print(f"while processing {id=}: {e}", file=sys.stderr) exit(1) + except Exception as e: + print(f"while processing {id=}: {e}", file=sys.stderr) + exit(1) return name, version, source |