Skip to content

Commit 2930af1

Browse files
committed
add Crate::Path variant
1 parent 56d2a45 commit 2930af1

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Config {
114114
Crate::Registry(ref details) => self.crates.get(&details.name),
115115
Crate::GitHub(ref repo) => self.github_repos.get(&repo.slug()),
116116
Crate::Local(ref name) => self.local_crates.get(name),
117-
Crate::Git(_) => unimplemented!("unsupported crate"),
117+
Crate::Git(_) | Crate::Path(_) => unimplemented!("unsupported crate"),
118118
}
119119
}
120120

src/crates/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub(crate) fn get_crates(
9696
Crate::Registry(RegistryCrate { ref name, .. }) => demo_registry.remove(name),
9797
Crate::GitHub(ref repo) => demo_github.remove(&repo.slug()),
9898
Crate::Local(ref name) => demo_local.remove(name),
99-
Crate::Git(_) => unimplemented!("unsupported crate"),
99+
Crate::Git(_) | Crate::Path(_) => unimplemented!("unsupported crate"),
100100
};
101101

102102
if add {

src/crates/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use percent_encoding::{percent_decode_str, utf8_percent_encode, NON_ALPHANUMERIC
88
use rustwide::Crate as RustwideCrate;
99
use std::convert::TryFrom;
1010
use std::fmt;
11+
use std::path::Path;
1112
use std::str::FromStr;
1213

1314
pub(crate) use crate::crates::sources::github::GitHubRepo;
@@ -24,6 +25,7 @@ pub enum Crate {
2425
Registry(RegistryCrate),
2526
GitHub(GitHubRepo),
2627
Local(String),
28+
Path(String),
2729
Git(GitRepo),
2830
}
2931

@@ -39,6 +41,9 @@ impl Crate {
3941
}
4042
}
4143
Crate::Local(ref name) => format!("local/{}", name),
44+
Crate::Path(ref path) => {
45+
format!("path/{}", utf8_percent_encode(&path, &NON_ALPHANUMERIC))
46+
}
4247
Crate::Git(ref repo) => {
4348
if let Some(ref sha) = repo.sha {
4449
format!(
@@ -60,6 +65,7 @@ impl Crate {
6065
RustwideCrate::git(&format!("https://github.com/{}/{}", repo.org, repo.name))
6166
}
6267
Self::Local(name) => RustwideCrate::local(&LOCAL_CRATES_DIR.join(name)),
68+
Self::Path(path) => RustwideCrate::local(Path::new(&path)),
6369
Self::Git(repo) => RustwideCrate::git(&repo.url),
6470
}
6571
}
@@ -85,7 +91,7 @@ impl TryFrom<&'_ PackageId> for Crate {
8591
name: name.to_string(),
8692
version: version.to_string(),
8793
})),
88-
[name, _, "path", _] => Ok(Crate::Local(name.to_string())),
94+
[_, _, "path", path] => Ok(Crate::Path(path.to_string())),
8995
[_, _, "git", repo] => {
9096
if repo.starts_with("https://github.com") {
9197
Ok(Crate::GitHub(repo.replace("#", "/").parse()?))
@@ -131,6 +137,8 @@ impl fmt::Display for Crate {
131137
format!("{}/{}", repo.org, repo.name)
132138
},
133139
Crate::Local(ref name) => format!("{} (local)", name),
140+
Crate::Path(ref path) =>
141+
format!("{}", utf8_percent_encode(path, &NON_ALPHANUMERIC)),
134142
Crate::Git(ref repo) =>
135143
if let Some(ref sha) = repo.sha {
136144
format!(
@@ -175,6 +183,9 @@ impl FromStr for Crate {
175183
sha: None,
176184
})),
177185
["local", name] => Ok(Crate::Local(name.to_string())),
186+
["path", path] => Ok(Crate::Path(
187+
percent_decode_str(path).decode_utf8()?.to_string(),
188+
)),
178189
_ => bail!("unexpected crate value"),
179190
}
180191
}
@@ -203,7 +214,7 @@ mod tests {
203214
#[test]
204215
fn test_parse_from_pkgid() {
205216
test_from_pkgid! {
206-
"dummy 0.1.0 (path+file:///opt/rustwide/workdir)" => Crate::Local("dummy".to_string()),
217+
"dummy 0.1.0 (path+file:///opt/rustwide/workdir)" => Crate::Path("file:///opt/rustwide/workdir".to_string()),
207218
"dummy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" => Crate::Registry(RegistryCrate {
208219
name: "dummy".to_string(),
209220
version: "0.1.0".to_string()
@@ -270,6 +281,8 @@ mod tests {
270281

271282
test_from_str! {
272283
"local/build-fail" => Crate::Local("build-fail".to_string()),
284+
"path/pathtofile" => Crate::Path("pathtofile".to_string()),
285+
&format!("path/{}", utf8_percent_encode("path/with:stange?characters", &NON_ALPHANUMERIC)) => Crate::Path("path/with:stange?characters".to_string()),
273286
"gh/org/user" => Crate::GitHub(GitHubRepo{org: "org".to_string(), name: "user".to_string(), sha: None}),
274287
"gh/org/user/sha" => Crate::GitHub(GitHubRepo{org: "org".to_string(), name: "user".to_string(), sha: Some("sha".to_string())}),
275288
"git/url" => Crate::Git(GitRepo{url: "url".to_string(), sha: None}),

src/report/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::results::{EncodedLog, EncodingType, ReadResults, TestResult};
66
use crate::toolchain::Toolchain;
77
use crate::utils;
88
use mime::{self, Mime};
9-
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
9+
use percent_encoding::{utf8_percent_encode, AsciiSet};
1010
use std::borrow::Cow;
1111
#[cfg(test)]
1212
use std::cell::RefCell;
@@ -134,11 +134,13 @@ fn crate_to_path_fragment(
134134
path.push("local");
135135
path.push(name);
136136
}
137+
Crate::Path(ref krate_path) => {
138+
path.push("path");
139+
path.push(dest.sanitize(&krate_path).into_owned());
140+
}
137141
Crate::Git(ref repo) => {
138142
path.push("git");
139-
140-
let name = utf8_percent_encode(&repo.url, &NON_ALPHANUMERIC).to_string();
141-
path.push(dest.sanitize(&name).into_owned());
143+
path.push(dest.sanitize(&repo.url).into_owned());
142144
}
143145
}
144146

@@ -297,7 +299,7 @@ fn gen_retry_list(res: &TestResults) -> String {
297299
match krate {
298300
Crate::Registry(details) => writeln!(out, "{}", details.name).unwrap(),
299301
Crate::GitHub(repo) => writeln!(out, "{}/{}", repo.org, repo.name).unwrap(),
300-
Crate::Local(_) | Crate::Git(_) => {}
302+
Crate::Local(_) | Crate::Git(_) | Crate::Path(_) => {}
301303
}
302304
}
303305

@@ -315,6 +317,7 @@ fn crate_to_name(c: &Crate) -> Fallible<String> {
315317
}
316318
}
317319
Crate::Local(ref name) => format!("{} (local)", name),
320+
Crate::Path(ref path) => utf8_percent_encode(path, &REPORT_ENCODE_SET).to_string(),
318321
Crate::Git(ref repo) => {
319322
if let Some(ref sha) = repo.sha {
320323
format!(
@@ -347,6 +350,7 @@ fn crate_to_url(c: &Crate) -> Fallible<String> {
347350
crate::CRATER_REPO_URL,
348351
name
349352
),
353+
Crate::Path(ref path) => utf8_percent_encode(path, &REPORT_ENCODE_SET).to_string(),
350354
Crate::Git(ref repo) => repo.url.clone(),
351355
})
352356
}

0 commit comments

Comments
 (0)