Skip to content

Commit eeb8d64

Browse files
authored
Merge pull request epage#80 from GitaWei/rm_cgo_deps_37
fix!: Remove `cargo-deps: syntax`
2 parents 42e9ea5 + b236e42 commit eeb8d64

File tree

8 files changed

+20
-249
lines changed

8 files changed

+20
-249
lines changed

docs/README.md

+6-43
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Under the hood, a Cargo project will be generated and built (with the Cargo outp
4949

5050
As seen from the above example, using a `fn main() {}` function is not required. If not present, the script file will be wrapped in a `fn main() { ... }` block.
5151

52-
`rust-script` will look for embedded dependency and manifest information in the script as shown by the below two equivalent `now.rs` variants:
52+
`rust-script` will look for embedded dependency and manifest information in the script as shown by the below `now.rs` variants:
5353

5454
```rust
5555
#!/usr/bin/env rust-script
@@ -66,26 +66,6 @@ fn main() {
6666
}
6767
```
6868

69-
```rust
70-
// cargo-deps: time="0.1.25"
71-
// You can also leave off the version number, in which case, it's assumed
72-
// to be "*". Also, the `cargo-deps` comment *must* be a single-line
73-
// comment, and it *must* be the first thing in the file, after the
74-
// shebang.
75-
// Multiple dependencies should be separated by commas:
76-
// cargo-deps: time="0.1.25", libc="0.2.5"
77-
fn main() {
78-
println!("{}", time::now().rfc822z());
79-
}
80-
```
81-
82-
The output from running one of the above scripts may look something like:
83-
84-
```sh
85-
$ rust-script now
86-
Wed, 28 Oct 2020 00:38:45 +0100
87-
```
88-
8969
Useful command-line arguments:
9070

9171
- `--bench`: Compile and run benchmarks. Requires a nightly toolchain.
@@ -122,27 +102,7 @@ The code given is embedded into a block expression, evaluated, and printed out u
122102

123103
## Filters
124104

125-
You can use `rust-script` to write a quick filter, by specifying a closure to be called for each line read from stdin, like so:
126-
127-
```sh
128-
$ cat now.ers | rust-script --loop \
129-
"let mut n=0; move |l| {n+=1; println!(\"{:>6}: {}\",n,l.trim_right())}"
130-
1: // cargo-deps: time="0.1.25"
131-
3: fn main() {
132-
4: println!("{}", time::now().rfc822z());
133-
5: }
134-
```
135-
136-
You can achieve a similar effect to the above by using the `--count` flag, which causes the line number to be passed as a second argument to your closure:
137-
138-
```sh
139-
$ cat now.ers | rust-script --count --loop \
140-
"|l,n| println!(\"{:>6}: {}\", n, l.trim_right())"
141-
1: // cargo-deps: time="0.1.25"
142-
2: fn main() {
143-
3: println!("{}", time::now().rfc822z());
144-
4: }
145-
```
105+
TBD
146106

147107
Note that, like with expressions, you can specify a custom template for stream filters.
148108

@@ -167,7 +127,10 @@ Templates are Rust source files with two placeholders: `#{prelude}` for the auto
167127
For example, a minimal expression template that adds a dependency and imports some additional symbols might be:
168128
169129
```rust
170-
// cargo-deps: itertools="0.6.2"
130+
//! ```cargo
131+
//! [dependencies]
132+
//! itertools="0.6.2"
133+
//! ```
171134
#![allow(unused_imports)]
172135
#{prelude}
173136
use std::io::prelude::*;

src/manifest.rs

+1-149
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ use crate::Input;
1414
use log::{error, info};
1515
use std::ffi::OsString;
1616

17-
static RE_SHORT_MANIFEST: once_cell::sync::Lazy<Regex> = once_cell::sync::Lazy::new(|| {
18-
Regex::new(r"^(?i)\s*//\s*cargo-deps\s*:(.*?)(\r\n|\n)").unwrap()
19-
});
2017
static RE_MARGIN: once_cell::sync::Lazy<Regex> =
2118
once_cell::sync::Lazy::new(|| Regex::new(r"^\s*\*( |$)").unwrap());
2219
static RE_SPACE: once_cell::sync::Lazy<Regex> =
@@ -184,59 +181,6 @@ fn main() {}
184181
)
185182
);
186183

187-
assert_eq!(
188-
si!(f(r#"
189-
// Cargo-Deps: time="0.1.25"
190-
fn main() {}
191-
"#)),
192-
r!(
193-
r#"[[bin]]
194-
name = "n_input_id"
195-
path = "n.rs"
196-
197-
[dependencies]
198-
time = "0.1.25"
199-
200-
[package]
201-
authors = ["Anonymous"]
202-
edition = "2018"
203-
name = "n"
204-
version = "0.1.0"
205-
"#,
206-
r#"
207-
// Cargo-Deps: time="0.1.25"
208-
fn main() {}
209-
"#
210-
)
211-
);
212-
213-
assert_eq!(
214-
si!(f(r#"
215-
// Cargo-Deps: time="0.1.25", libc="0.2.5"
216-
fn main() {}
217-
"#)),
218-
r!(
219-
r#"[[bin]]
220-
name = "n_input_id"
221-
path = "n.rs"
222-
223-
[dependencies]
224-
libc = "0.2.5"
225-
time = "0.1.25"
226-
227-
[package]
228-
authors = ["Anonymous"]
229-
edition = "2018"
230-
name = "n"
231-
version = "0.1.0"
232-
"#,
233-
r#"
234-
// Cargo-Deps: time="0.1.25", libc="0.2.5"
235-
fn main() {}
236-
"#
237-
)
238-
);
239-
240184
assert_eq!(
241185
si!(f(r#"
242186
/*!
@@ -329,8 +273,6 @@ enum Manifest<'s> {
329273
/// The manifest is a valid TOML fragment (owned).
330274
// TODO: Change to Cow<'s, str>.
331275
TomlOwned(String),
332-
/// The manifest is a comma-delimited list of dependencies.
333-
DepList(&'s str),
334276
}
335277

336278
impl<'s> Manifest<'s> {
@@ -339,7 +281,6 @@ impl<'s> Manifest<'s> {
339281
match self {
340282
Toml(s) => toml::from_str(s),
341283
TomlOwned(ref s) => toml::from_str(s),
342-
DepList(s) => Manifest::dep_list_to_toml(s),
343284
}
344285
.map_err(|e| {
345286
MainError::Tag(
@@ -348,26 +289,6 @@ impl<'s> Manifest<'s> {
348289
)
349290
})
350291
}
351-
352-
fn dep_list_to_toml(s: &str) -> ::std::result::Result<toml::value::Table, toml::de::Error> {
353-
let mut r = String::new();
354-
r.push_str("[dependencies]\n");
355-
for dep in s.trim().split(',') {
356-
// If there's no version specified, add one.
357-
match dep.contains('=') {
358-
true => {
359-
r.push_str(dep);
360-
r.push('\n');
361-
}
362-
false => {
363-
r.push_str(dep);
364-
r.push_str("=\"*\"\n");
365-
}
366-
}
367-
}
368-
369-
toml::from_str(&r)
370-
}
371292
}
372293

373294
/**
@@ -376,7 +297,7 @@ Locates a manifest embedded in Rust source.
376297
Returns `Some((manifest, source))` if it finds a manifest, `None` otherwise.
377298
*/
378299
fn find_embedded_manifest(s: &str) -> Option<(Manifest, &str)> {
379-
find_short_comment_manifest(s).or_else(|| find_code_block_manifest(s))
300+
find_code_block_manifest(s)
380301
}
381302

382303
#[test]
@@ -433,59 +354,6 @@ fn main() {
433354
None
434355
);
435356

436-
assert_eq!(
437-
fem("// cargo-deps: time=\"0.1.25\"
438-
fn main() {}
439-
"),
440-
Some((
441-
DepList(" time=\"0.1.25\""),
442-
"// cargo-deps: time=\"0.1.25\"
443-
fn main() {}
444-
"
445-
))
446-
);
447-
448-
assert_eq!(
449-
fem("// cargo-deps: time=\"0.1.25\", libc=\"0.2.5\"
450-
fn main() {}
451-
"),
452-
Some((
453-
DepList(" time=\"0.1.25\", libc=\"0.2.5\""),
454-
"// cargo-deps: time=\"0.1.25\", libc=\"0.2.5\"
455-
fn main() {}
456-
"
457-
))
458-
);
459-
460-
assert_eq!(
461-
fem("
462-
// cargo-deps: time=\"0.1.25\" \n\
463-
fn main() {}
464-
"),
465-
Some((
466-
DepList(" time=\"0.1.25\" "),
467-
"
468-
// cargo-deps: time=\"0.1.25\" \n\
469-
fn main() {}
470-
"
471-
))
472-
);
473-
474-
assert_eq!(
475-
fem("/* cargo-deps: time=\"0.1.25\" */
476-
fn main() {}
477-
"),
478-
None
479-
);
480-
481-
assert_eq!(
482-
fem(r#"//! [dependencies]
483-
//! time = "0.1.25"
484-
fn main() {}
485-
"#),
486-
None
487-
);
488-
489357
assert_eq!(
490358
fem(r#"//! ```Cargo
491359
//! [dependencies]
@@ -584,22 +452,6 @@ fn main() {}
584452
);
585453
}
586454

587-
/**
588-
Locates a "short comment manifest" in Rust source.
589-
*/
590-
fn find_short_comment_manifest(s: &str) -> Option<(Manifest, &str)> {
591-
/*
592-
This is pretty simple: the only valid syntax for this is for the first, non-blank line to contain a single-line comment whose first token is `cargo-deps:`. That's it.
593-
*/
594-
let re = &*RE_SHORT_MANIFEST;
595-
if let Some(cap) = re.captures(s) {
596-
if let Some(m) = cap.get(1) {
597-
return Some((Manifest::DepList(m.as_str()), s));
598-
}
599-
}
600-
None
601-
}
602-
603455
/**
604456
Locates a "code block manifest" in Rust source.
605457
*/

tests/data/script-short-without-main.rs

-9
This file was deleted.

tests/data/script-short.rs

-10
This file was deleted.

tests/data/templates/boolinate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// cargo-deps: boolinator="0.1.0"
1+
//! ```cargo
2+
//! [dependencies]
3+
//! boolinator="0.1.0"
4+
//! ```
25
36
extern crate boolinator;
47
use boolinator::Boolinator;

tests/data/templates/override/expr.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// cargo-deps: boolinator="0.1.0"
1+
//! ```cargo
2+
//! [dependencies]
3+
//! boolinator="0.1.0"
4+
//! ```
25
36
extern crate boolinator;
47
use boolinator::Boolinator;

tests/data/time.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
// cargo-deps: chrono
1+
//! ```cargo
2+
//! [dependencies]
3+
//! chrono="*"
4+
//! ```
25
extern crate chrono;
36
fn main() {
47
println!("--output--");
58
println!("Hello");
6-
}
9+
}

tests/integration/script.rs

-34
Original file line numberDiff line numberDiff line change
@@ -147,40 +147,6 @@ Hello, World!
147147
fixture.close();
148148
}
149149

150-
#[test]
151-
fn test_script_short() {
152-
let fixture = crate::util::Fixture::new();
153-
fixture
154-
.cmd()
155-
.arg("tests/data/script-short.rs")
156-
.assert()
157-
.success()
158-
.stdout_eq(
159-
"--output--
160-
Some(1)
161-
",
162-
);
163-
164-
fixture.close();
165-
}
166-
167-
#[test]
168-
fn test_script_short_without_main() {
169-
let fixture = crate::util::Fixture::new();
170-
fixture
171-
.cmd()
172-
.arg("tests/data/script-short-without-main.rs")
173-
.assert()
174-
.success()
175-
.stdout_eq(
176-
"--output--
177-
Some(1)
178-
",
179-
);
180-
181-
fixture.close();
182-
}
183-
184150
#[test]
185151
fn test_script_test() {
186152
let fixture = crate::util::Fixture::new();

0 commit comments

Comments
 (0)