Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
6ce7592
Add `onlinejudge.verify.languages.rust`
qryxip Nov 10, 2020
8f6c759
Apply mypy, pylint, isrot, and yapf
qryxip Nov 11, 2020
43e55ba
Pass `__init__`s
qryxip Nov 11, 2020
9e8a52f
Implement `RustLanguageEnvironment.compile`
qryxip Nov 11, 2020
2f6a531
Implement `RustLanguageEnvironment.get_execute_command`
qryxip Nov 11, 2020
ae99c7b
Implement `RustLanguage.is_verification_file`
qryxip Nov 11, 2020
b55759c
Implement `RustLanguage.list_dependencies`
qryxip Nov 11, 2020
ae69757
Prepend _ to private functions
qryxip Nov 11, 2020
35ebfcb
Cache "cargo metadata"
qryxip Nov 11, 2020
9226ea5
Use `RootLogger.warning` instead of `print`
qryxip Nov 11, 2020
7d7fec8
Combine `path` with `basedir`
qryxip Nov 12, 2020
835d5dd
Include `path` itself in `list_dependencies`
qryxip Nov 12, 2020
6016508
Include `path` itself in `list_dependencies`
qryxip Nov 12, 2020
ffcc800
Include `path` itself in `list_dependencies`
qryxip Nov 12, 2020
3c94d54
`Exception` → `RuntimeError`
qryxip Nov 12, 2020
5f65a52
Don't repeat yourself
qryxip Nov 12, 2020
907ad4d
Minor refactor
qryxip Nov 12, 2020
ee5dcb3
Raise an error when `cargo-udeps` is not found
qryxip Nov 12, 2020
007b15e
Query "cargo metadata" in `is_verification_file`
qryxip Nov 12, 2020
94c171a
Treat `example` targets as verification
qryxip Nov 12, 2020
f9570de
Read config
qryxip Nov 12, 2020
e0cadc8
Add `_NoBackend`
qryxip Nov 12, 2020
7e3290d
Add `toolchain` parameter for `_CargoUdeps`
qryxip Nov 12, 2020
9514528
Fix a bug
qryxip Nov 12, 2020
5e5bf17
Write Japanese documentation
qryxip Nov 12, 2020
3807d5e
Refer to GitHub Actions
qryxip Nov 12, 2020
ba00ec3
Update document.ja.md
qryxip Nov 12, 2020
bfd3c2e
Fix a code block
qryxip Nov 12, 2020
eae8662
Read `target/debug/deps/$name-*.d`
qryxip Nov 13, 2020
0bc062f
"main source file" → "root source file"
qryxip Nov 13, 2020
9373a77
Remove an empty `__init__`
qryxip Nov 13, 2020
aff6c7b
Add a comment
qryxip Nov 14, 2020
22a5042
Remove `--no-deps` since cargo metadata is cached
qryxip Nov 14, 2020
aeaa747
`yapf: disable` for a line
qryxip Nov 14, 2020
18bb792
Group source files by `target`s
qryxip Nov 15, 2020
20cefe4
Read "attributes" in `is_varification_file`
qryxip Nov 15, 2020
b448bc6
Fix `get_execute_command`
qryxip Nov 16, 2020
3cc03d8
Do not assume manifests are above source files
qryxip Nov 16, 2020
5352b76
Insert '、'
qryxip Nov 16, 2020
ffdf3be
Update .verify-helper/docs/static/document.ja.md
qryxip Nov 16, 2020
4ce326e
Apply cargo-udeps for `lib`s and `proc-macro`s
qryxip Nov 16, 2020
050f1e2
Correct a description around cargo-udeps
qryxip Nov 16, 2020
99d0047
Modify the description about `kind = "cargo-udeps"`
qryxip Nov 16, 2020
92bec30
Install Rust and cargo-udeps
qryxip Nov 16, 2020
c4e3257
Add a Rust example
qryxip Nov 16, 2020
d995ee7
Add `rust_test`
qryxip Nov 16, 2020
fc56bee
Do not verify for problems from yukicoder
qryxip Nov 17, 2020
95e89a3
Fix a test
qryxip Nov 17, 2020
589e4f3
Explicitly cast a `Path` to `str`
qryxip Nov 17, 2020
d03321d
Fix a file path
qryxip Nov 17, 2020
c449e83
Fix error messages
qryxip Nov 17, 2020
567f681
Remove a duplicated link
qryxip Nov 18, 2020
db5cbe2
"`bin`" → "binary", "`example`" → "example"
qryxip Nov 18, 2020
3c24627
Update the description around cargo-udeps
qryxip Nov 18, 2020
586c525
Remove the installation part
qryxip Nov 18, 2020
8c4adef
Add a comment
qryxip Nov 18, 2020
6e9fb98
Add a comment
qryxip Nov 18, 2020
4660a3a
Merge remote-tracking branch 'origin/master' into rust
qryxip Nov 29, 2020
f7225ad
Fix `useless-object-inheritance` and `logging-fstring-interpolation`
qryxip Nov 29, 2020
7639796
Fill the "ファイル例"
qryxip Nov 29, 2020
67beabc
`p1 / p2` instead of `p1.joinpath(p2)`
qryxip Nov 29, 2020
1fa912a
Use `tests/utils.load_files_pathlib` directly
qryxip Nov 29, 2020
0b8b583
Fix the `lru_cache` for `_cargo_metadata`
qryxip Nov 29, 2020
f071111
Add `assert cwd.is_absolute()`
qryxip Nov 29, 2020
8f50eec
Add docstring to `_cargo_metadata` and `_cargo_metadata_by_manifest_p…
qryxip Nov 29, 2020
2f3bc69
Raise a `ValueError` instead of asserting
qryxip Nov 29, 2020
80dbb88
Move `package_and_target`
qryxip Nov 29, 2020
ad250ae
Insert several empty lines
qryxip Nov 29, 2020
8c69e1b
Add a comment
qryxip Nov 29, 2020
e598473
Modify a comment
qryxip Nov 29, 2020
fa18b1d
s/source_file_sets/related_source_files/g
qryxip Nov 29, 2020
fa23b67
Distinguish `src_path`s from the others
qryxip Nov 29, 2020
cf91456
Cache "related source files" by workspace instead of by package
qryxip Nov 29, 2020
eaf6cd0
Add docstrings
qryxip Nov 29, 2020
4bfb9af
Flatten nests
qryxip Nov 30, 2020
e6475ff
Move `source_files_in_same_targets` in the module scope
qryxip Nov 30, 2020
019ec08
Move `ret`
qryxip Nov 30, 2020
817375d
"ws" → "workspace"
qryxip Nov 30, 2020
dc179fa
Rename a local variable
qryxip Nov 30, 2020
92dd291
Simplify the construction of `neighbors_on_no_dev_graph`
qryxip Nov 30, 2020
b917527
Add comments to `_list_dependencies_by_crate`
qryxip Nov 30, 2020
49668da
Add `functools.lru_cache` to `_list_dependencies_by_crate`
qryxip Nov 30, 2020
e8313b7
Update document.ja.md
qryxip Nov 30, 2020
1474439
Rename an unused state
qryxip Nov 30, 2020
d9f2675
Rename local variables
qryxip Nov 30, 2020
3f264c2
Refactor `_related_source_files`
qryxip Nov 30, 2020
9981c41
Update the examples
qryxip Nov 30, 2020
379e452
Rename some local variables
qryxip Dec 3, 2020
ee33de0
`logger.error` when resolving a `name_in_toml` fails
qryxip Dec 3, 2020
27f9fcb
Move an assertion
qryxip Dec 3, 2020
7a6a213
Flatten nests
qryxip Dec 3, 2020
6299607
Rename some local variables
qryxip Dec 3, 2020
337883c
Replace a `for` statement with `_ = next(..); if ..`
qryxip Dec 3, 2020
9181364
Fix the problem around external crates
qryxip Dec 3, 2020
84db367
Include `dev-dependencies` for `example`s
qryxip Dec 3, 2020
68f5fa2
Change the type of `values` for `dependencies`
qryxip Dec 3, 2020
ee41c50
Refactor
qryxip Dec 3, 2020
29a181e
Set `cwd` for `cargo udeps ...`
qryxip Dec 3, 2020
497e81a
Consider `build-dependencies` correctly
qryxip Dec 3, 2020
97bf2b5
Introduce a enum of `NORMAL_DEVELOPMENT | BUILD`
qryxip Dec 4, 2020
443d415
Minor refactor
qryxip Dec 4, 2020
bae159e
Add a test
qryxip Dec 4, 2020
4e9a355
Fix `_related_source_files`
qryxip Dec 4, 2020
068c87e
`try` `PurePath.relative_to` to exclude files outside the repository
qryxip Dec 4, 2020
0a454dc
Fix `_related_source_files` for `example`s
qryxip Dec 4, 2020
8ea259c
Add "verificaton"s to the two tests
qryxip Dec 4, 2020
052da00
Add more tests
qryxip Dec 4, 2020
20731a2
Consider `..` in `src_path`s
qryxip Dec 4, 2020
c649ca2
Fix for `custom-build`s
qryxip Dec 4, 2020
bb52cd7
Add a test
qryxip Dec 5, 2020
1fcf031
Reduce the number of `cargo metadata`
qryxip Dec 8, 2020
43a0c97
Update the example for Rust
qryxip Dec 8, 2020
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ jobs:
- name: Install dependencies (Nim)
run: sudo apt install nim

- name: Set up Rust (1.42.0)
uses: actions-rs/toolchain@v1
with:
toolchain: 1.42.0-x86_64-unknown-linux-gnu
default: true
profile: minimal

# required by cargo-udeps
- name: Set up Rust (nightly)
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-x86_64-unknown-linux-gnu
default: true
profile: minimal

# required only if you set `languages.rust.list_dependencies_backend.kind` to `"cargo-udeps"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo-udeps v0.16.0をリリースしたのでoj-verify-playgroundに空コミットしたところよくないことに...

毎日実行されていたactions-rs/tool-cacheのジョブが「60日間activity無し」によって20日ほど前に停止されていて、0.15.0を明示的に指定しない限り4分近くかかるようになってしまいました (しかもこの場合1.42でcargo-udepsをビルドしようとして失敗してる)。というかactions-rs/install共々issue/prが結構放置されているような...

https://github.com/qryxip/oj-verify-playground/runs/1432309559?check_suite_focus=true

インストール方法の代替を考えると

  1. cargo install + actions/cache
  2. 前のようにGitHub Actionsから.tar.gzwgetしてtar xf
    の2つですがどっちにしても設定ファイルが膨らむ気がします。1.に至っては数時間試行錯誤してますがベストな方法がわからないです。
- name: Install cargo-udeps for Rust
uses: actions-rs/install@v0.1
with:
crate: cargo-udeps
use-tool-cache: true
Comment on lines +65 to +68
Copy link
Contributor Author

@qryxip qryxip Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmyk actions-rs/installはunmaintainedだし、結局他に良い方法が思い浮かばなかったのでGitHub Releasesからダウンロードする方法に戻していいでしょうか。

(cargo installすると4分、--debug付きでも90秒ほどかかります。)

Suggested change
uses: actions-rs/install@v0.1
with:
crate: cargo-udeps
use-tool-cache: true
run: |
version="$(curl https://crates.io/api/v1/crates/cargo-udeps | jq -r '.crate.max_version')"
wget "https://github.com/est31/cargo-udeps/releases/download/v$version/cargo-udeps-v$version-x86_64-unknown-linux-gnu"
tar xzvf "./cargo-udeps-v$version-x86_64-unknown-linux-gnu.tar.gz" -C /tmp/
echo "/tmp/cargo-udeps-v$version-x86_64-unknown-linux-gnu" >> $GITHUB_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qryxip 戻した方がよさそうということならお願いします。このプルリクはもうマージしてしまったので、新しいプルリクを作ってください


- name: Run tests
env:
Expand Down
33 changes: 33 additions & 0 deletions .verify-helper/docs/static/document.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
| Ruby | `.rb` | `.test.rb` | `# verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [hello_world.test.rb](https://github.com/online-judge-tools/verification-helper/blob/master/examples/ruby/hello_world.test.rb) |
| Go | `.go` | `.test.go` | `// verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [helloworld.test.go](https://github.com/online-judge-tools/verification-helper/blob/master/examples/go/helloworld.test.go) |
| Java | `.java` | `_test.java` | `// verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [HelloWorld_test.java](https://github.com/online-judge-tools/verification-helper/blob/master/examples/java/HelloWorld_test.java) |
| Rust | `.rs` | 特殊 | `// verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [itp1-1-a.rs](https://github.com/online-judge-tools/verification-helper/blob/master/examples/rust/verification/src/bin/aizu-online-judge-itp1-1-a.rs) |

### C++ の設定

Expand Down Expand Up @@ -59,6 +60,38 @@ NIMFLAGS = ["--warning:on", "--opt:none"]

設定項目は特にありません。

### Rust の設定

[binary ターゲット](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries)と [example ターゲット](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#examples) (ただし`crate-type`が指定されているのは除く) の [root source file](https://docs.rs/cargo_metadata/0.12.0/cargo_metadata/struct.Target.html#structfield.src_path) のうち、[`PROBLEM`](#利用可能な属性)が設定されてあるソースファイルがテストファイルだと認識されます。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[root source file](https://docs.rs/cargo_metadata/0.12.0/cargo_metadata/struct.Target.html#structfield.src_path)

これのリンク先をもうすこし分かりやすいドキュメントで置き換えられませんか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

うーん他に言及されているのだとこれの真ん中ら辺?

 /* Absolute path to the root source file of the target. */ "src_path": "/path/to/my-package/src/main.rs",

依存ファイルを列挙する動作は `.verify-helper/config.toml` の `languages.rust.list_dependencies_backend` で変更できます。

- `kind = "none"`

デフォルトの動作です。

```toml
[languages.rust.list_dependencies_backend]
kind = "none"
```

- あるターゲットの root source file であるならば、そのターゲット及びローカルにある依存クレートの、
- どのターゲットの root source file でもなければ、自身を含むターゲットの、

`.rs`ファイルすべてを列挙して返します。

ターゲットに関連する `.rs` ファイルはすべてひとまとまりとして扱われ、「モジュール間の依存関係」等については調べません。

- `kind = "cargo-udeps"`

基本的に `kind = "none"` と同じですが、 `$PATH` 内にある [cargo-udeps](https://github.com/est31/cargo-udeps) を使い「パッケージからクレートへの依存」からさらに「クレート間の依存」を絞り込みます。

```toml
[languages.rust.list_dependencies_backend]
kind = "cargo-udeps"
toolchain = "nightly-yyyy-mm-dd" # defaults to "nightly"
```

### その他の言語の設定

上記以外の言語でも実行可能です (例: [examples/awk/circle.test.awk](https://github.com/online-judge-tools/verification-helper/blob/master/examples/awk/circle.test.awk))。
Expand Down
2 changes: 2 additions & 0 deletions examples/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Cargo.lock
/target/
17 changes: 17 additions & 0 deletions examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[workspace]
members = ["verification/"]

[package]
name = "verification-helper-rust-example"
version = "0.0.0"
edition = "2018"
publish = false

[lib]
name = "crate" # This crate itself is not intended to be used directly.

[dependencies]
verification-helper-rust-example-hello = { path = "crates/helloworld/hello" }
verification-helper-rust-example-input = { path = "crates/io/input" }
verification-helper-rust-example-scanner = { path = "crates/io/scanner" }
verification-helper-rust-example-world = { path = "crates/helloworld/world" }
8 changes: 8 additions & 0 deletions examples/rust/crates/helloworld/hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "verification-helper-rust-example-hello"
version = "0.0.0"
edition = "2018"
publish = false

[lib]
name = "hello"
3 changes: 3 additions & 0 deletions examples/rust/crates/helloworld/hello/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Provides `"Hello"`.

pub static HELLO: &str = "Hello";
8 changes: 8 additions & 0 deletions examples/rust/crates/helloworld/world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "verification-helper-rust-example-world"
version = "0.0.0"
edition = "2018"
publish = false

[lib]
name = "world"
3 changes: 3 additions & 0 deletions examples/rust/crates/helloworld/world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Provides `"World"`.

pub static WORLD: &str = "World";
11 changes: 11 additions & 0 deletions examples/rust/crates/io/input/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "verification-helper-rust-example-input"
version = "0.1.0"
authors = ["Ryo Yamashita <qryxip@gmail.com>"]
edition = "2018"

[lib]
name = "input"

[dependencies]
verification-helper-rust-example-scanner = { path = "../scanner" }
23 changes: 23 additions & 0 deletions examples/rust/crates/io/input/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! A limited `input!` macro.
//!
//! ```no_run
//! use input::input;
//!
//! input! {
//! a: u32,
//! b: u32,
//! }
//! ```

pub use scanner::Scanner;

/// A limited `input!` macro.
#[macro_export]
macro_rules! input {
($($var:ident : $ty:ty),* $(,)?) => {
let mut __scanner = $crate::Scanner::from_stdin();
$(
let $var = __scanner.read::<$ty>();
)*
};
}
8 changes: 8 additions & 0 deletions examples/rust/crates/io/scanner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "verification-helper-rust-example-scanner"
version = "0.1.0"
authors = ["Ryo Yamashita <qryxip@gmail.com>"]
edition = "2018"

[lib]
name = "scanner"
58 changes: 58 additions & 0 deletions examples/rust/crates/io/scanner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! A quite simple input scanner.
//!
//! ```no_run
//! use scanner::Scanner;
//!
//! let mut sc = Scanner::from_stdin();
//! let _: u64 = sc.read();
//! ```

use std::{
any, fmt,
io::{self, Read as _},
str::{FromStr, SplitAsciiWhitespace},
};

/// A quite simple input scanner.
pub struct Scanner {
tokens: SplitAsciiWhitespace<'static>,
}

impl Scanner {
/// Constructs a new `Self` with while input from stdin.
///
/// # Panics
///
/// Panics if an IO error occurred.
pub fn from_stdin() -> Self {
let mut input = "".to_owned();
io::stdin().read_to_string(&mut input).unwrap();
Self {
tokens: Box::leak(input.into_boxed_str()).split_ascii_whitespace(),
}
}

/// Consumes and parses the next token.
///
/// # Panics
///
/// Panics if:
///
/// - no token left
/// - failed to parse the token
pub fn read<T>(&mut self) -> T
where
T: FromStr,
T::Err: fmt::Display,
{
let token = self.tokens.next().expect("reached EOF");
token.parse().unwrap_or_else(|err| {
panic!(
"could not parse {:?} as `{}`: {}",
token,
any::type_name::<T>(),
err,
);
})
}
}
1 change: 1 addition & 0 deletions examples/rust/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.42.0
19 changes: 19 additions & 0 deletions examples/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Re-exports the crates for rustdoc.
//!
//! This crate itself is not intended to be used directly.

// With `custom-build` and `syn` crate, we can expand crate-level rustdocs.

macro_rules! re_export(($($name:ident),* $(,)?) => ($(pub mod $name { pub use ::$name::*; })*));

pub mod helloworld {
//! Crates of "hello" and "world".

re_export!(hello, world);
}

pub mod io {
//! Crates about IO.

re_export!(input, scanner);
}
10 changes: 10 additions & 0 deletions examples/rust/verification/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "verification"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies]
verification-helper-rust-example-hello = { path = "../crates/helloworld/hello" }
verification-helper-rust-example-input = { path = "../crates/io/input" }
verification-helper-rust-example-world = { path = "../crates/helloworld/world" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A

fn main() {
println!("{} {}", hello::HELLO, world::WORLD);
}
12 changes: 12 additions & 0 deletions examples/rust/verification/src/bin/library-checker-aplusb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/aplusb

use input::input;

fn main() {
input! {
a: u32,
b: u32,
}

println!("{}", a + b);
}
2 changes: 2 additions & 0 deletions onlinejudge_verify/languages/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from onlinejudge_verify.languages.nim import NimLanguage
from onlinejudge_verify.languages.python import PythonLanguage
from onlinejudge_verify.languages.ruby import RubyLanguage
from onlinejudge_verify.languages.rust import RustLanguage
from onlinejudge_verify.languages.user_defined import UserDefinedLanguage

logger = getLogger(__name__)
Expand All @@ -34,6 +35,7 @@ def _get_dict() -> Dict[str, Language]:
_dict['.ruby'] = RubyLanguage()
_dict['.go'] = GoLanguage()
_dict['.java'] = JavaLanguage()
_dict['.rs'] = RustLanguage()

for ext, config in get_config().get('languages', {}).items():
if '.' + ext in _dict:
Expand Down
Loading