Skip to content

Teaching rustpkg to get versions from a git repository #6904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/librustpkg/crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use core::path::Path;
use core::vec;

/// A crate is a unit of Rust code to be compiled into a binary or library
pub struct Crate {
file: Path,
flags: ~[~str],
cfgs: ~[~str]
}

impl Crate {

pub fn new(p: &Path) -> Crate {
Crate {
file: copy *p,
flags: ~[],
cfgs: ~[]
}
}

fn flag(&self, flag: ~str) -> Crate {
Crate {
flags: vec::append(copy self.flags, [flag]),
.. copy *self
}
}

fn flags(&self, flags: ~[~str]) -> Crate {
Crate {
flags: vec::append(copy self.flags, flags),
.. copy *self
}
}

fn cfg(&self, cfg: ~str) -> Crate {
Crate {
cfgs: vec::append(copy self.cfgs, [cfg]),
.. copy *self
}
}

fn cfgs(&self, cfgs: ~[~str]) -> Crate {
Crate {
cfgs: vec::append(copy self.cfgs, cfgs),
.. copy *self
}
}
}
96 changes: 32 additions & 64 deletions src/librustpkg/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
// except according to those terms.

pub use package_path::{RemotePath, LocalPath, normalize, hash};
use extra::semver;
use core::prelude::*;
use core::result;

/// Placeholder
pub fn default_version() -> Version { ExactRevision(0.1) }
use version::{try_getting_version, Version, NoVersion, split_version};

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

let mut given_version = None;

// Did the user request a specific version?
let s = match split_version(s) {
Some((path, v)) => {
debug!("s = %s, path = %s, v = %s", s, path, v.to_str());
given_version = Some(v);
path
}
None => {
debug!("%s has no explicit version", s);
s
}
};

let p = Path(s);
if p.is_absolute {
return cond.raise((p, ~"absolute pkgid"));
Expand All @@ -49,11 +60,20 @@ impl PkgId {
let remote_path = RemotePath(p);
let local_path = normalize(copy remote_path);
let short_name = (copy local_path).filestem().expect(fmt!("Strange path! %s", s));

let version = match given_version {
Some(v) => v,
None => match try_getting_version(&remote_path) {
Some(v) => v,
None => NoVersion
}
};

PkgId {
local_path: local_path,
remote_path: remote_path,
short_name: short_name,
version: default_version()
version: version
}
}

Expand All @@ -64,69 +84,17 @@ impl PkgId {
}

pub fn short_name_with_version(&self) -> ~str {
fmt!("%s-%s", self.short_name, self.version.to_str())
fmt!("%s%s", self.short_name, self.version.to_str())
}
}

impl ToStr for PkgId {
fn to_str(&self) -> ~str {
let maybe_dash = match self.version {
NoVersion => "",
_ => "-"
};
// should probably use the filestem and not the whole path
fmt!("%s-%s", self.local_path.to_str(), self.version.to_str())
}
}

/// A version is either an exact revision,
/// or a semantic version
pub enum Version {
ExactRevision(float),
SemVersion(semver::Version)
}


impl Ord for Version {
fn lt(&self, other: &Version) -> bool {
match (self, other) {
(&ExactRevision(f1), &ExactRevision(f2)) => f1 < f2,
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 < v2,
_ => false // incomparable, really
}
}
fn le(&self, other: &Version) -> bool {
match (self, other) {
(&ExactRevision(f1), &ExactRevision(f2)) => f1 <= f2,
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 <= v2,
_ => false // incomparable, really
}
}
fn ge(&self, other: &Version) -> bool {
match (self, other) {
(&ExactRevision(f1), &ExactRevision(f2)) => f1 > f2,
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 > v2,
_ => false // incomparable, really
}
}
fn gt(&self, other: &Version) -> bool {
match (self, other) {
(&ExactRevision(f1), &ExactRevision(f2)) => f1 >= f2,
(&SemVersion(ref v1), &SemVersion(ref v2)) => v1 >= v2,
_ => false // incomparable, really
}
}

}

impl ToStr for Version {
fn to_str(&self) -> ~str {
match *self {
ExactRevision(ref n) => n.to_str(),
SemVersion(ref v) => v.to_str()
}
}
}

pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> {
match semver::parse(vers) {
Some(vers) => result::Ok(vers),
None => result::Err(~"could not parse version: invalid")
fmt!("%s%s%s", self.local_path.to_str(), maybe_dash, self.version.to_str())
}
}
Loading