online-judge-tools / verification-helper

a testing framework for snippet libraries used in competitive programming

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust でターゲットの root source file が存在しないときエラーになる

kuretchi opened this issue · comments

Description

Rust において,cargo metadata で列挙されるターゲットの root source file が (パッケージから exclude されるなどして?) ローカルに存在しない場合にエラーになることがあります.

例えば,次のようにライブラリを作ります:

cargo new --lib /tmp/zzz  # `log` より辞書順で大きい名前
cd /tmp/zzz
cargo add --dev log@=0.4.14
mkdir examples
cat <<'EOF' >examples/hello.rs
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A
fn main() {
  println!("Hello World");
}
EOF

ここで cargo metadata を実行すると,

$ cargo metadata --format-version 1 | jq '.packages[] | .targets[] | .src_path'
"/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-1.0.0/src/lib.rs"
"/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-1.0.0/tests/xcrate.rs"
"/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/src/lib.rs"
"/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/filters.rs"
"/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/macros.rs"
"/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/benches/value.rs"
"/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs"
"/tmp/zzz/src/lib.rs"
"/tmp/zzz/examples/hello.rs"

のようになりますが,/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests は存在せず,oj-verify run を実行すると下記のエラーになります.

Error log

$ oj-verify run
INFO:onlinejudge_verify.config:no config file
Traceback (most recent call last):
  File "/home/kuretchi/.local/bin/oj-verify", line 8, in <module>
    sys.exit(main())
  File "/home/kuretchi/.local/lib/python3.9/site-packages/onlinejudge_verify/main.py", line 301, in main
    summary = subcommand_run(paths=parsed.path, timeout=parsed.timeout, tle=parsed.tle, jobs=parsed.jobs)
  File "/home/kuretchi/.local/lib/python3.9/site-packages/onlinejudge_verify/main.py", line 80, in subcommand_run
    paths = sorted(list(onlinejudge_verify.utils.iterate_verification_files()))
  File "/home/kuretchi/.local/lib/python3.9/site-packages/onlinejudge_verify/utils.py", line 20, in is_verification_file
    return language is not None and language.is_verification_file(path, basedir=basedir)
  File "/home/kuretchi/.local/lib/python3.9/site-packages/onlinejudge_verify/languages/rust.py", line 293, in is_verification_file
    package_and_target = _find_target(metadata, path)
  File "/home/kuretchi/.local/lib/python3.9/site-packages/onlinejudge_verify/languages/rust.py", line 366, in _find_target
    if pathlib.Path(target['src_path']).resolve(strict=True) == src_path:
  File "/usr/lib/python3.9/pathlib.py", line 1204, in resolve
    s = self._flavour.resolve(self, strict=strict)
  File "/usr/lib/python3.9/pathlib.py", line 362, in resolve
    return _resolve(base, str(path)) or sep
  File "/usr/lib/python3.9/pathlib.py", line 346, in _resolve
    target = accessor.readlink(newpath)
  File "/usr/lib/python3.9/pathlib.py", line 451, in readlink
    return os.readlink(path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/kuretchi/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests'

Other notes

$ cargo --version
cargo 1.49.0 (d00d64df9 2020-12-05)
  • Will you try to create a pull request?
    • yes