Skip to content

Commit

Permalink
Fixed the erase function for CRLF code
Browse files Browse the repository at this point in the history
qryxip committed May 2, 2021
1 parent 1236924 commit 71868b7
Showing 2 changed files with 55 additions and 0 deletions.
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,8 +5,56 @@
### Fixed

- Recognizes `#[macro_export(local_inner_macros)]`.

- Fixed a problem where `$crate`s are not replaced with `$crate::lib_name` in a certain case.

- Fixed a problem where `--remove` option could not be used for CRLF code.

With the above 3 fixtures, you can bundle [proconio](https://docs.rs/crate/proconio).

```console
❯ cat <<EOF >./src/main.rs
heredoc> #[macro_use]
heredoc> extern crate proconio as _;
heredoc>
heredoc> #[fastout]
heredoc> fn main() {
heredoc> input!(abs: [(u64, u64)]);
heredoc> for (a, b) in abs {
heredoc> println!("{}", a + b);
heredoc> }
heredoc> }
heredoc> EOF
❯ cargo equip \
> --resolve-cfgs \
> --remove docs \
> --minify libs \
> --rustfmt \
> --check \
> -o ./bundled.rs
❯ ./run-cargo-equip.bash -o ./bundled.rs
Running `/home/ryo/.cargo/bin/rustup run nightly cargo udeps --output json -p bundle-proconio --bin bundle-proconio`
Checking bundle-proconio v0.1.0 (/home/ryo/src/local/bundle-proconio)
Finished dev [unoptimized + debuginfo] target(s) in 0.45s
info: Loading save analysis from "/home/ryo/src/local/bundle-proconio/target/debug/deps/save-analysis/bundle_proconio-31a013a4acd96cad.json"
Running `/home/ryo/.cargo/bin/rustup run stable-x86_64-unknown-linux-gnu cargo check --message-format json -p 'bundle-proconio:0.1.0' --bin bundle-proconio`
Checking bundle-proconio v0.1.0 (/home/ryo/src/local/bundle-proconio)
Finished dev [unoptimized + debuginfo] target(s) in 0.44s
Spawning `/home/ryo/.cache/cargo-equip/rust-analyzer-2021-03-29 proc-macro`
Readied `#[derive_readable]`
Readied `#[fastout]`
Bundling the code
warning: found `crate` paths. replacing them with `crate::proconio`
Reading the license file of `lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)`
Reading the license file of `proconio 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)`
Checking cargo-equip-check-output-fs0en4z4r1d3gd3e v0.1.0 (/tmp/cargo-equip-check-output-fs0en4z4r1d3gd3e)
Finished dev [unoptimized + debuginfo] target(s) in 0.19s
❯ stat -c %s ./bundled.rs
18024
```

[Submission Info #46571 - Library Checker](https://judge.yosupo.jp/submission/46571)

## [0.12.0] - 2021-05-01Z

### Added
7 changes: 7 additions & 0 deletions src/rust.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use maplit::{btreemap, btreeset};
use proc_macro2::{LineColumn, Spacing, Span, TokenStream, TokenTree};
use quote::{quote, ToTokens};
use std::{
borrow::Cow,
collections::{BTreeMap, BTreeSet, VecDeque},
env, fs, mem,
ops::Range,
@@ -1248,6 +1249,12 @@ fn erase(
code: &str,
visit_file: fn(&mut [FixedBitSet], TokenStream) -> syn::Result<()>,
) -> anyhow::Result<String> {
let code = &if code.contains("\r\n") {
Cow::from(code.replace("\r\n", "\n"))
} else {
Cow::from(code)
};

let code = if code.starts_with("#!") {
let (_, code) = code.split_at(code.find('\n').unwrap_or_else(|| code.len()));
code

0 comments on commit 71868b7

Please sign in to comment.