Skip to content

Commit fa84593

Browse files
committed
rustpkg: Do not guess version if not given
rustpkg accessed git repo to read tags and guess package version, but it's not quite useful: version can be given explicitly by user, and implicit guess may cause confusions.
1 parent 750d48b commit fa84593

File tree

3 files changed

+7
-149
lines changed

3 files changed

+7
-149
lines changed

src/librustpkg/crate_id.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use version::{try_getting_version, try_getting_local_version,
12-
Version, NoVersion, ExactRevision};
11+
use version::{Version, NoVersion, ExactRevision};
1312
use std::hash::Streaming;
1413
use std::hash;
1514
use syntax::crateid;
@@ -53,17 +52,9 @@ impl CrateId {
5352
let raw_crateid = raw_crateid.unwrap();
5453
let crateid::CrateId { path, name, version } = raw_crateid;
5554
let path = Path::new(path);
56-
let given_version = version.map(|v| ExactRevision(v));
57-
58-
let version = match given_version {
59-
Some(v) => v,
60-
None => match try_getting_local_version(&path) {
61-
Some(v) => v,
62-
None => match try_getting_version(&path) {
63-
Some(v) => v,
64-
None => NoVersion
65-
}
66-
}
55+
let version = match version {
56+
Some(v) => ExactRevision(v),
57+
None => NoVersion,
6758
};
6859

6960
CrateId {

src/librustpkg/tests.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -752,46 +752,6 @@ fn test_crate_ids_must_be_relative_path_like() {
752752
})
753753
}
754754
755-
#[test]
756-
fn test_package_version() {
757-
let local_path = "mockgithub.com/catamorphism/test_pkg_version";
758-
let repo = init_git_repo(&Path::new(local_path));
759-
let repo = repo.path();
760-
let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]);
761-
debug!("Writing files in: {}", repo_subdir.display());
762-
fs::mkdir_recursive(&repo_subdir, io::UserRWX);
763-
writeFile(&repo_subdir.join("main.rs"),
764-
"fn main() { let _x = (); }");
765-
writeFile(&repo_subdir.join("lib.rs"),
766-
"pub fn f() { let _x = (); }");
767-
writeFile(&repo_subdir.join("test.rs"),
768-
"#[test] pub fn f() { (); }");
769-
writeFile(&repo_subdir.join("bench.rs"),
770-
"#[bench] pub fn f() { (); }");
771-
add_git_tag(&repo_subdir, ~"0.4");
772-
773-
// It won't pick up the 0.4 version because the dir isn't in the RUST_PATH, but...
774-
let temp_pkg_id = CrateId::new("mockgithub.com/catamorphism/test_pkg_version");
775-
// This should look at the prefix, clone into a workspace, then build.
776-
command_line_test([~"install", ~"mockgithub.com/catamorphism/test_pkg_version"],
777-
repo);
778-
let ws = repo.join(".rust");
779-
// we can still match on the filename to make sure it contains the 0.4 version
780-
assert!(match built_library_in_workspace(&temp_pkg_id,
781-
&ws) {
782-
Some(p) => {
783-
let suffix = format!("0.4{}", os::consts::DLL_SUFFIX);
784-
p.as_vec().ends_with(suffix.as_bytes())
785-
}
786-
None => false
787-
});
788-
assert!(built_executable_in_workspace(&temp_pkg_id, &ws)
789-
== Some(target_build_dir(&ws).join_many(["mockgithub.com",
790-
"catamorphism",
791-
"test_pkg_version",
792-
"test_pkg_version"])));
793-
}
794-
795755
#[test]
796756
fn test_package_request_version() {
797757
let local_path = "mockgithub.com/catamorphism/test_pkg_version";
@@ -2183,9 +2143,9 @@ fn test_installed_read_only() {
21832143
"fn main() { let _x = (); }");
21842144
writeFile(&repo_subdir.join("lib.rs"),
21852145
"pub fn f() { let _x = (); }");
2186-
add_git_tag(&repo_subdir, ~"0.1"); // this has the effect of committing the files
2146+
add_git_tag(&repo_subdir, ~"0.0"); // this has the effect of committing the files
21872147
// update crateid to what will be auto-detected
2188-
temp_pkg_id.version = ExactRevision(~"0.1");
2148+
temp_pkg_id.version = ExactRevision(~"0.0");
21892149
21902150
// FIXME (#9639): This needs to handle non-utf8 paths
21912151
command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo);

src/librustpkg/version.rs

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
extern mod std;
1515

1616
use extra::semver;
17-
use std::{char, result, run, str};
18-
use extra::tempfile::TempDir;
19-
use path_util::rust_path;
17+
use std::{char, result};
2018

2119
#[deriving(Clone)]
2220
pub enum Version {
@@ -93,91 +91,6 @@ pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> {
9391
}
9492
}
9593

96-
/// If `local_path` is a git repo in the RUST_PATH, and the most recent tag
97-
/// in that repo denotes a version, return it; otherwise, `None`
98-
pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
99-
let rustpath = rust_path();
100-
for rp in rustpath.iter() {
101-
let local_path = rp.join(local_path);
102-
let git_dir = local_path.join(".git");
103-
if !git_dir.is_dir() {
104-
continue;
105-
}
106-
// FIXME (#9639): This needs to handle non-utf8 paths
107-
let opt_outp = run::process_output("git",
108-
["--git-dir=" + git_dir.as_str().unwrap(), ~"tag", ~"-l"]);
109-
let outp = opt_outp.expect("Failed to exec `git`");
110-
111-
debug!("git --git-dir={} tag -l ~~~> {:?}", git_dir.display(), outp.status);
112-
113-
if !outp.status.success() {
114-
continue;
115-
}
116-
117-
let mut output = None;
118-
let output_text = str::from_utf8(outp.output).unwrap();
119-
for l in output_text.lines() {
120-
if !l.is_whitespace() {
121-
output = Some(l);
122-
}
123-
match output.and_then(try_parsing_version) {
124-
Some(v) => return Some(v),
125-
None => ()
126-
}
127-
}
128-
}
129-
None
130-
}
131-
132-
/// If `remote_path` refers to a git repo that can be downloaded,
133-
/// and the most recent tag in that repo denotes a version, return it;
134-
/// otherwise, `None`
135-
pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
136-
if is_url_like(remote_path) {
137-
let tmp_dir = TempDir::new("test");
138-
let tmp_dir = tmp_dir.expect("try_getting_version: couldn't create temp dir");
139-
let tmp_dir = tmp_dir.path();
140-
debug!("(to get version) executing \\{git clone https://{} {}\\}",
141-
remote_path.display(),
142-
tmp_dir.display());
143-
// FIXME (#9639): This needs to handle non-utf8 paths
144-
let opt_outp = run::process_output("git", [~"clone", format!("https://{}",
145-
remote_path.as_str().unwrap()),
146-
tmp_dir.as_str().unwrap().to_owned()]);
147-
let outp = opt_outp.expect("Failed to exec `git`");
148-
if outp.status.success() {
149-
debug!("Cloned it... ( {}, {} )",
150-
str::from_utf8(outp.output).unwrap(),
151-
str::from_utf8(outp.error).unwrap());
152-
let mut output = None;
153-
let git_dir = tmp_dir.join(".git");
154-
debug!("(getting version, now getting tags) executing \\{git --git-dir={} tag -l\\}",
155-
git_dir.display());
156-
// FIXME (#9639): This needs to handle non-utf8 paths
157-
let opt_outp = run::process_output("git",
158-
["--git-dir=" + git_dir.as_str().unwrap(),
159-
~"tag", ~"-l"]);
160-
let outp = opt_outp.expect("Failed to exec `git`");
161-
let output_text = str::from_utf8(outp.output).unwrap();
162-
debug!("Full output: ( {} ) [{:?}]", output_text, outp.status);
163-
for l in output_text.lines() {
164-
debug!("A line of output: {}", l);
165-
if !l.is_whitespace() {
166-
output = Some(l);
167-
}
168-
}
169-
170-
output.and_then(try_parsing_version)
171-
}
172-
else {
173-
None
174-
}
175-
}
176-
else {
177-
None
178-
}
179-
}
180-
18194
// Being lazy since we don't have a regexp library now
18295
#[deriving(Eq)]
18396
enum ParseState {
@@ -207,12 +120,6 @@ pub fn try_parsing_version(s: &str) -> Option<Version> {
207120
}
208121
}
209122

210-
/// Just an approximation
211-
fn is_url_like(p: &Path) -> bool {
212-
// check if there are more than 2 /-separated components
213-
p.as_vec().split(|b| *b == '/' as u8).nth(2).is_some()
214-
}
215-
216123
/// If s is of the form foo#bar, where bar is a valid version
217124
/// number, return the prefix before the # and the version.
218125
/// Otherwise, return None.

0 commit comments

Comments
 (0)