Skip to content

Commit 655433e

Browse files
committed
rustpkg::version: Remove enum Version
Currently rustpkg doesn't use SemanticVersion or Tagged, so they are removed. Remaining variants are replaced by `Option<~str>`.
1 parent fa84593 commit 655433e

File tree

11 files changed

+100
-180
lines changed

11 files changed

+100
-180
lines changed

src/librustpkg/api.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate_id::*;
1515
use package_source::*;
1616
use path_util::{platform_library_name, target_build_dir};
1717
use target::*;
18-
use version::Version;
1918
use workspace::pkg_parent_workspaces;
2019
use workcache_support::*;
2120
pub use path_util::default_workspace;
@@ -79,13 +78,13 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context {
7978
workcache::Context::new_with_freshness(db, cfg, Arc::new(freshness))
8079
}
8180

82-
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
81+
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Option<~str>,
8382
lib: Path) {
8483
build_lib_with_cfgs(sysroot, root, name, version, lib, ~[])
8584
}
8685

8786
pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
88-
version: Version, lib: Path, cfgs: ~[~str]) {
87+
version: Option<~str>, lib: Path, cfgs: ~[~str]) {
8988
let cx = default_context(sysroot, root.clone());
9089
let pkg_src = PkgSrc {
9190
source_workspace: root.clone(),
@@ -102,13 +101,13 @@ pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
102101
pkg_src.build(&cx, cfgs, []);
103102
}
104103

105-
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
104+
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Option<~str>,
106105
main: Path) {
107106
build_exe_with_cfgs(sysroot, root, name, version, main, ~[])
108107
}
109108

110109
pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
111-
version: Version, main: Path, cfgs: ~[~str]) {
110+
version: Option<~str>, main: Path, cfgs: ~[~str]) {
112111
let cx = default_context(sysroot, root.clone());
113112
let pkg_src = PkgSrc {
114113
source_workspace: root.clone(),
@@ -129,7 +128,7 @@ pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
129128
pub fn install_pkg(cx: &BuildContext,
130129
workspace: Path,
131130
name: ~str,
132-
version: Version,
131+
version: Option<~str>,
133132
// For now, these inputs are assumed to be inputs to each of the crates
134133
more_inputs: ~[(~str, Path)]) { // pairs of Kind and Path
135134
let crateid = CrateId{ version: version, ..CrateId::new(name)};

src/librustpkg/crate_id.rs

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

11-
use version::{Version, NoVersion, ExactRevision};
1211
use std::hash::Streaming;
1312
use std::hash;
1413
use syntax::crateid;
@@ -32,7 +31,7 @@ pub struct CrateId {
3231
/// of package IDs whose short names aren't valid Rust identifiers.
3332
short_name: ~str,
3433
/// The requested package version.
35-
version: Version
34+
version: Option<~str>
3635
}
3736

3837
impl Eq for CrateId {
@@ -42,6 +41,13 @@ impl Eq for CrateId {
4241
}
4342

4443
impl CrateId {
44+
pub fn get_version<'a>(&'a self) -> &'a str {
45+
match self.version {
46+
Some(ref ver) => ver.as_slice(),
47+
None => "0.0"
48+
}
49+
}
50+
4551
pub fn new(s: &str) -> CrateId {
4652
use conditions::bad_pkg_id::cond;
4753

@@ -52,10 +58,6 @@ impl CrateId {
5258
let raw_crateid = raw_crateid.unwrap();
5359
let crateid::CrateId { path, name, version } = raw_crateid;
5460
let path = Path::new(path);
55-
let version = match version {
56-
Some(v) => ExactRevision(v),
57-
None => NoVersion,
58-
};
5961

6062
CrateId {
6163
path: path,
@@ -67,13 +69,13 @@ impl CrateId {
6769
pub fn hash(&self) -> ~str {
6870
// FIXME (#9639): hash should take a &[u8] so we can hash the real path
6971
self.path.display().with_str(|s| {
70-
let vers = self.version.to_str();
72+
let vers = self.get_version();
7173
format!("{}-{}-{}", s, hash(s + vers), vers)
7274
})
7375
}
7476

7577
pub fn short_name_with_version(&self) -> ~str {
76-
format!("{}{}", self.short_name, self.version.to_str())
78+
format!("{}-{}", self.short_name, self.get_version())
7779
}
7880

7981
/// True if the ID has multiple components
@@ -124,7 +126,7 @@ impl Iterator<(Path, Path)> for Prefixes {
124126
impl ToStr for CrateId {
125127
fn to_str(&self) -> ~str {
126128
// should probably use the filestem and not the whole path
127-
format!("{}-{}", self.path.as_str().unwrap(), self.version.to_str())
129+
format!("{}-{}", self.path.as_str().unwrap(), self.get_version())
128130
}
129131
}
130132

src/librustpkg/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ impl<'a> PkgScript<'a> {
163163
exe.as_str().unwrap().to_owned()
164164
}
165165

166-
167166
/// Run the contents of this package script, where <what>
168167
/// is the command to pass to it (e.g., "build", "clean", "install")
169168
/// Returns a pair of an exit code and list of configs (obtained by
@@ -243,7 +242,7 @@ impl CtxMethods for BuildContext {
243242

244243
if args.len() < 1 {
245244
match cwd_to_workspace() {
246-
None if dir_has_crate_file(&cwd) => {
245+
None if dir_has_crate_file(&cwd) => {
247246
// FIXME (#9639): This needs to handle non-utf8 paths
248247
let crateid = CrateId::new(cwd.filename_str().unwrap());
249248
let mut pkg_src = PkgSrc::new(cwd, default_workspace(), true, crateid);
@@ -289,6 +288,7 @@ impl CtxMethods for BuildContext {
289288
Some((crateid, dest_ws))
290289
}
291290
}
291+
292292
fn run(&self, cmd: Command, args: ~[~str]) {
293293
let cwd = os::getcwd();
294294
match cmd {

src/librustpkg/package_source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ impl PkgSrc {
100100
// automatically-checked-out sources go.
101101
let mut result = source_workspace.join("src");
102102
result.push(&id.path.dir_path());
103-
result.push(format!("{}-{}", id.short_name, id.version.to_str()));
103+
result.push(id.short_name_with_version());
104104
to_try.push(result);
105105
let mut result = source_workspace.join("src");
106106
result.push(&id.path);
107107
to_try.push(result);
108108

109109
let mut result = build_dir.join("src");
110110
result.push(&id.path.dir_path());
111-
result.push(format!("{}-{}", id.short_name, id.version.to_str()));
111+
result.push(id.short_name_with_version());
112112
to_try.push(result.clone());
113113
output_names.push(result);
114114
let mut other_result = build_dir.join("src");
@@ -287,7 +287,7 @@ impl PkgSrc {
287287
// FIXME (#9639): This needs to handle non-utf8 paths
288288
let url = format!("https://{}", crateid.path.as_str().unwrap());
289289
debug!("Fetching package: git clone {} {} [version={}]",
290-
url, clone_target.display(), crateid.version.to_str());
290+
url, clone_target.display(), crateid.get_version());
291291

292292
let mut failed = false;
293293

src/librustpkg/path_util.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
pub use crate_id::CrateId;
1616
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
17-
pub use version::{Version, ExactRevision, NoVersion, split_version, split_version_general,
17+
pub use version::{Version, split_version, split_version_general,
1818
try_parsing_version};
1919
pub use rustc::metadata::filesearch::rust_path;
2020
use rustc::metadata::filesearch::{libdir, relative_target_lib_path};
@@ -85,7 +85,7 @@ pub fn workspace_contains_crate_id_(crateid: &CrateId, workspace: &Path,
8585
None => false,
8686
Some((ref might_match, ref vers)) => {
8787
*might_match == crateid.short_name
88-
&& (crateid.version == *vers || crateid.version == NoVersion)
88+
&& (crateid.version == *vers || crateid.version == None)
8989
}
9090
}
9191
})
@@ -188,7 +188,7 @@ pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Opti
188188
Install,
189189
workspace,
190190
libdir(),
191-
&NoVersion)
191+
&None)
192192
}
193193
}
194194

@@ -261,7 +261,8 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
261261
Some(i) => {
262262
debug!("Maybe {} is a version", f_name.slice(i + 1, f_name.len()));
263263
match try_parsing_version(f_name.slice(i + 1, f_name.len())) {
264-
Some(ref found_vers) if version == found_vers => {
264+
Some(ref found_vers) if version == &Some(found_vers.to_owned()) ||
265+
version == &None => {
265266
match f_name.slice(0, i).rfind('-') {
266267
Some(j) => {
267268
let lib_prefix = match p_path.extension_str() {
@@ -276,7 +277,6 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
276277
}
277278
None => break
278279
}
279-
280280
}
281281
_ => { f_name = f_name.slice(0, i); }
282282
}
@@ -306,13 +306,13 @@ fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) {
306306
match split_version(crate_id) {
307307
Some((name, vers)) =>
308308
match vers {
309-
ExactRevision(ref v) => match v.find('-') {
310-
Some(pos) => (name, ExactRevision(v.slice(0, pos).to_owned())),
311-
None => (name, ExactRevision(v.to_owned()))
309+
Some(ref v) => match v.find('-') {
310+
Some(pos) => (name, Some(v.slice(0, pos).to_owned())),
311+
None => (name, Some(v.to_owned()))
312312
},
313313
_ => (name, vers)
314314
},
315-
None => (crate_id, NoVersion)
315+
None => (crate_id, None)
316316
}
317317
}
318318

@@ -393,8 +393,7 @@ pub fn build_pkg_id_in_workspace(crateid: &CrateId, workspace: &Path) -> Path {
393393
/// given whether we're building a library and whether we're building tests
394394
pub fn mk_output_path(what: OutputType, where: Target,
395395
pkg_id: &CrateId, workspace: Path) -> Path {
396-
let short_name_with_version = format!("{}-{}", pkg_id.short_name,
397-
pkg_id.version.to_str());
396+
let short_name_with_version = pkg_id.short_name_with_version();
398397
// Not local_path.dir_path()! For package foo/bar/blat/, we want
399398
// the executable blat-0.5 to live under blat/
400399
let dir = match where {
@@ -487,7 +486,7 @@ pub fn versionize(p: &Path, v: &Version) -> Path {
487486
let q = p.filename().expect("path is a directory");
488487
let mut q = q.to_owned();
489488
q.push('-' as u8);
490-
let vs = v.to_str();
489+
let vs = match v { &Some(ref s) => s.to_owned(), &None => ~"0.0" };
491490
q.push_all(vs.as_bytes());
492491
p.with_filename(q)
493492
}

src/librustpkg/source_control.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ use std::{run, str};
1414
use std::run::{ProcessOutput, ProcessOptions, Process};
1515
use std::io::fs;
1616
use extra::tempfile::TempDir;
17-
use version::*;
1817
use path_util::chmod_read_only;
1918

2019
/// Attempts to clone `source`, a local git repository, into `target`, a local
2120
/// directory that doesn't exist.
2221
/// Returns `DirToUse(p)` if the clone fails, where `p` is a newly created temporary
2322
/// directory (that the callee may use, for example, to check out remote sources into).
2423
/// Returns `CheckedOutSources` if the clone succeeded.
25-
pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult {
24+
pub fn safe_git_clone(source: &Path, v: &Option<~str>, target: &Path) -> CloneResult {
2625
if source.exists() {
2726
debug!("{} exists locally! Cloning it into {}",
2827
source.display(), target.display());
@@ -44,7 +43,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
4443
}
4544
else {
4645
match v {
47-
&ExactRevision(ref s) => {
46+
&Some(ref s) => {
4847
let git_dir = target.join(".git");
4948
debug!("`Running: git --work-tree={} --git-dir={} checkout {}",
5049
*s, target.display(), git_dir.display());
@@ -65,7 +64,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
6564
} else {
6665
// Check that no version was specified. There's no reason to not handle the
6766
// case where a version was requested, but I haven't implemented it.
68-
assert!(*v == NoVersion);
67+
assert!(*v == None);
6968
let git_dir = target.join(".git");
7069
debug!("Running: git --work-tree={} --git-dir={} pull --no-edit {}",
7170
target.display(), git_dir.display(), source.display());
@@ -106,7 +105,7 @@ pub fn make_read_only(target: &Path) {
106105
}
107106

108107
/// Source can be either a URL or a local file path.
109-
pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
108+
pub fn git_clone_url(source: &str, target: &Path, v: &Option<~str>) {
110109
use conditions::git_checkout_failed::cond;
111110

112111
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -120,7 +119,7 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
120119
}
121120
else {
122121
match v {
123-
&ExactRevision(ref s) | &Tagged(ref s) => {
122+
&Some(ref s) => {
124123
let opt_outp = process_output_in_cwd("git", [~"checkout", s.to_owned()],
125124
target);
126125
let outp = opt_outp.expect("Failed to exec `git`");

0 commit comments

Comments
 (0)