Skip to content

Commit 94f72dd

Browse files
committed
auto merge of #6904 : catamorphism/rust/rustpkg_version_vcs, r=catamorphism
r? @brson
2 parents 88c318d + d92b435 commit 94f72dd

File tree

9 files changed

+670
-352
lines changed

9 files changed

+670
-352
lines changed

src/librustpkg/crate.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use core::path::Path;
12+
use core::vec;
13+
14+
/// A crate is a unit of Rust code to be compiled into a binary or library
15+
pub struct Crate {
16+
file: Path,
17+
flags: ~[~str],
18+
cfgs: ~[~str]
19+
}
20+
21+
impl Crate {
22+
23+
pub fn new(p: &Path) -> Crate {
24+
Crate {
25+
file: copy *p,
26+
flags: ~[],
27+
cfgs: ~[]
28+
}
29+
}
30+
31+
fn flag(&self, flag: ~str) -> Crate {
32+
Crate {
33+
flags: vec::append(copy self.flags, [flag]),
34+
.. copy *self
35+
}
36+
}
37+
38+
fn flags(&self, flags: ~[~str]) -> Crate {
39+
Crate {
40+
flags: vec::append(copy self.flags, flags),
41+
.. copy *self
42+
}
43+
}
44+
45+
fn cfg(&self, cfg: ~str) -> Crate {
46+
Crate {
47+
cfgs: vec::append(copy self.cfgs, [cfg]),
48+
.. copy *self
49+
}
50+
}
51+
52+
fn cfgs(&self, cfgs: ~[~str]) -> Crate {
53+
Crate {
54+
cfgs: vec::append(copy self.cfgs, cfgs),
55+
.. copy *self
56+
}
57+
}
58+
}

src/librustpkg/package_id.rs

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
// except according to those terms.
1010

1111
pub use package_path::{RemotePath, LocalPath, normalize, hash};
12-
use extra::semver;
1312
use core::prelude::*;
14-
use core::result;
15-
16-
/// Placeholder
17-
pub fn default_version() -> Version { ExactRevision(0.1) }
13+
use version::{try_getting_version, Version, NoVersion, split_version};
1814

1915
/// Path-fragment identifier of a package such as
2016
/// 'github.com/graydon/test'; path must be a relative
@@ -39,6 +35,21 @@ impl PkgId {
3935
pub fn new(s: &str) -> PkgId {
4036
use conditions::bad_pkg_id::cond;
4137

38+
let mut given_version = None;
39+
40+
// Did the user request a specific version?
41+
let s = match split_version(s) {
42+
Some((path, v)) => {
43+
debug!("s = %s, path = %s, v = %s", s, path, v.to_str());
44+
given_version = Some(v);
45+
path
46+
}
47+
None => {
48+
debug!("%s has no explicit version", s);
49+
s
50+
}
51+
};
52+
4253
let p = Path(s);
4354
if p.is_absolute {
4455
return cond.raise((p, ~"absolute pkgid"));
@@ -49,11 +60,20 @@ impl PkgId {
4960
let remote_path = RemotePath(p);
5061
let local_path = normalize(copy remote_path);
5162
let short_name = (copy local_path).filestem().expect(fmt!("Strange path! %s", s));
63+
64+
let version = match given_version {
65+
Some(v) => v,
66+
None => match try_getting_version(&remote_path) {
67+
Some(v) => v,
68+
None => NoVersion
69+
}
70+
};
71+
5272
PkgId {
5373
local_path: local_path,
5474
remote_path: remote_path,
5575
short_name: short_name,
56-
version: default_version()
76+
version: version
5777
}
5878
}
5979

@@ -64,69 +84,17 @@ impl PkgId {
6484
}
6585

6686
pub fn short_name_with_version(&self) -> ~str {
67-
fmt!("%s-%s", self.short_name, self.version.to_str())
87+
fmt!("%s%s", self.short_name, self.version.to_str())
6888
}
6989
}
7090

7191
impl ToStr for PkgId {
7292
fn to_str(&self) -> ~str {
93+
let maybe_dash = match self.version {
94+
NoVersion => "",
95+
_ => "-"
96+
};
7397
// should probably use the filestem and not the whole path
74-
fmt!("%s-%s", self.local_path.to_str(), self.version.to_str())
75-
}
76-
}
77-
78-
/// A version is either an exact revision,
79-
/// or a semantic version
80-
pub enum Version {
81-
ExactRevision(float),
82-
SemVersion(semver::Version)
83-
}
84-
85-
86-
impl Ord for Version {
87-
fn lt(&self, other: &Version) -> bool {
88-
match (self, other) {
89-
(&ExactRevision(f1), &ExactRevision(f2)) => f1 < f2,
90-
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 < v2,
91-
_ => false // incomparable, really
92-
}
93-
}
94-
fn le(&self, other: &Version) -> bool {
95-
match (self, other) {
96-
(&ExactRevision(f1), &ExactRevision(f2)) => f1 <= f2,
97-
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 <= v2,
98-
_ => false // incomparable, really
99-
}
100-
}
101-
fn ge(&self, other: &Version) -> bool {
102-
match (self, other) {
103-
(&ExactRevision(f1), &ExactRevision(f2)) => f1 > f2,
104-
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 > v2,
105-
_ => false // incomparable, really
106-
}
107-
}
108-
fn gt(&self, other: &Version) -> bool {
109-
match (self, other) {
110-
(&ExactRevision(f1), &ExactRevision(f2)) => f1 >= f2,
111-
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 >= v2,
112-
_ => false // incomparable, really
113-
}
114-
}
115-
116-
}
117-
118-
impl ToStr for Version {
119-
fn to_str(&self) -> ~str {
120-
match *self {
121-
ExactRevision(ref n) => n.to_str(),
122-
SemVersion(ref v) => v.to_str()
123-
}
124-
}
125-
}
126-
127-
pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> {
128-
match semver::parse(vers) {
129-
Some(vers) => result::Ok(vers),
130-
None => result::Err(~"could not parse version: invalid")
98+
fmt!("%s%s%s", self.local_path.to_str(), maybe_dash, self.version.to_str())
13199
}
132100
}

0 commit comments

Comments
 (0)