Skip to content

Commit

Permalink
rustpkg::version: Remove enum Version
Browse files Browse the repository at this point in the history
Currently rustpkg doesn't use SemanticVersion or Tagged, so they are
removed. Remaining variants are replaced by `Option<~str>`.
  • Loading branch information
klutzy committed Jan 22, 2014
1 parent fa84593 commit 655433e
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 180 deletions.
11 changes: 5 additions & 6 deletions src/librustpkg/api.rs
Expand Up @@ -15,7 +15,6 @@ use crate_id::*;
use package_source::*;
use path_util::{platform_library_name, target_build_dir};
use target::*;
use version::Version;
use workspace::pkg_parent_workspaces;
use workcache_support::*;
pub use path_util::default_workspace;
Expand Down Expand Up @@ -79,13 +78,13 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context {
workcache::Context::new_with_freshness(db, cfg, Arc::new(freshness))
}

pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Option<~str>,
lib: Path) {
build_lib_with_cfgs(sysroot, root, name, version, lib, ~[])
}

pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
version: Version, lib: Path, cfgs: ~[~str]) {
version: Option<~str>, lib: Path, cfgs: ~[~str]) {
let cx = default_context(sysroot, root.clone());
let pkg_src = PkgSrc {
source_workspace: root.clone(),
Expand All @@ -102,13 +101,13 @@ pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
pkg_src.build(&cx, cfgs, []);
}

pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Option<~str>,
main: Path) {
build_exe_with_cfgs(sysroot, root, name, version, main, ~[])
}

pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
version: Version, main: Path, cfgs: ~[~str]) {
version: Option<~str>, main: Path, cfgs: ~[~str]) {
let cx = default_context(sysroot, root.clone());
let pkg_src = PkgSrc {
source_workspace: root.clone(),
Expand All @@ -129,7 +128,7 @@ pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
pub fn install_pkg(cx: &BuildContext,
workspace: Path,
name: ~str,
version: Version,
version: Option<~str>,
// For now, these inputs are assumed to be inputs to each of the crates
more_inputs: ~[(~str, Path)]) { // pairs of Kind and Path
let crateid = CrateId{ version: version, ..CrateId::new(name)};
Expand Down
20 changes: 11 additions & 9 deletions src/librustpkg/crate_id.rs
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use version::{Version, NoVersion, ExactRevision};
use std::hash::Streaming;
use std::hash;
use syntax::crateid;
Expand All @@ -32,7 +31,7 @@ pub struct CrateId {
/// of package IDs whose short names aren't valid Rust identifiers.
short_name: ~str,
/// The requested package version.
version: Version
version: Option<~str>
}

impl Eq for CrateId {
Expand All @@ -42,6 +41,13 @@ impl Eq for CrateId {
}

impl CrateId {
pub fn get_version<'a>(&'a self) -> &'a str {
match self.version {
Some(ref ver) => ver.as_slice(),
None => "0.0"
}
}

pub fn new(s: &str) -> CrateId {
use conditions::bad_pkg_id::cond;

Expand All @@ -52,10 +58,6 @@ impl CrateId {
let raw_crateid = raw_crateid.unwrap();
let crateid::CrateId { path, name, version } = raw_crateid;
let path = Path::new(path);
let version = match version {
Some(v) => ExactRevision(v),
None => NoVersion,
};

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/librustpkg/lib.rs
Expand Up @@ -163,7 +163,6 @@ impl<'a> PkgScript<'a> {
exe.as_str().unwrap().to_owned()
}


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

if args.len() < 1 {
match cwd_to_workspace() {
None if dir_has_crate_file(&cwd) => {
None if dir_has_crate_file(&cwd) => {
// FIXME (#9639): This needs to handle non-utf8 paths
let crateid = CrateId::new(cwd.filename_str().unwrap());
let mut pkg_src = PkgSrc::new(cwd, default_workspace(), true, crateid);
Expand Down Expand Up @@ -289,6 +288,7 @@ impl CtxMethods for BuildContext {
Some((crateid, dest_ws))
}
}

fn run(&self, cmd: Command, args: ~[~str]) {
let cwd = os::getcwd();
match cmd {
Expand Down
6 changes: 3 additions & 3 deletions src/librustpkg/package_source.rs
Expand Up @@ -100,15 +100,15 @@ impl PkgSrc {
// automatically-checked-out sources go.
let mut result = source_workspace.join("src");
result.push(&id.path.dir_path());
result.push(format!("{}-{}", id.short_name, id.version.to_str()));
result.push(id.short_name_with_version());
to_try.push(result);
let mut result = source_workspace.join("src");
result.push(&id.path);
to_try.push(result);

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

let mut failed = false;

Expand Down
23 changes: 11 additions & 12 deletions src/librustpkg/path_util.rs
Expand Up @@ -14,7 +14,7 @@

pub use crate_id::CrateId;
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
pub use version::{Version, ExactRevision, NoVersion, split_version, split_version_general,
pub use version::{Version, split_version, split_version_general,
try_parsing_version};
pub use rustc::metadata::filesearch::rust_path;
use rustc::metadata::filesearch::{libdir, relative_target_lib_path};
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn workspace_contains_crate_id_(crateid: &CrateId, workspace: &Path,
None => false,
Some((ref might_match, ref vers)) => {
*might_match == crateid.short_name
&& (crateid.version == *vers || crateid.version == NoVersion)
&& (crateid.version == *vers || crateid.version == None)
}
}
})
Expand Down Expand Up @@ -188,7 +188,7 @@ pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Opti
Install,
workspace,
libdir(),
&NoVersion)
&None)
}
}

Expand Down Expand Up @@ -261,7 +261,8 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
Some(i) => {
debug!("Maybe {} is a version", f_name.slice(i + 1, f_name.len()));
match try_parsing_version(f_name.slice(i + 1, f_name.len())) {
Some(ref found_vers) if version == found_vers => {
Some(ref found_vers) if version == &Some(found_vers.to_owned()) ||
version == &None => {
match f_name.slice(0, i).rfind('-') {
Some(j) => {
let lib_prefix = match p_path.extension_str() {
Expand All @@ -276,7 +277,6 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
}
None => break
}

}
_ => { f_name = f_name.slice(0, i); }
}
Expand Down Expand Up @@ -306,13 +306,13 @@ fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) {
match split_version(crate_id) {
Some((name, vers)) =>
match vers {
ExactRevision(ref v) => match v.find('-') {
Some(pos) => (name, ExactRevision(v.slice(0, pos).to_owned())),
None => (name, ExactRevision(v.to_owned()))
Some(ref v) => match v.find('-') {
Some(pos) => (name, Some(v.slice(0, pos).to_owned())),
None => (name, Some(v.to_owned()))
},
_ => (name, vers)
},
None => (crate_id, NoVersion)
None => (crate_id, None)
}
}

Expand Down Expand Up @@ -393,8 +393,7 @@ pub fn build_pkg_id_in_workspace(crateid: &CrateId, workspace: &Path) -> Path {
/// given whether we're building a library and whether we're building tests
pub fn mk_output_path(what: OutputType, where: Target,
pkg_id: &CrateId, workspace: Path) -> Path {
let short_name_with_version = format!("{}-{}", pkg_id.short_name,
pkg_id.version.to_str());
let short_name_with_version = pkg_id.short_name_with_version();
// Not local_path.dir_path()! For package foo/bar/blat/, we want
// the executable blat-0.5 to live under blat/
let dir = match where {
Expand Down Expand Up @@ -487,7 +486,7 @@ pub fn versionize(p: &Path, v: &Version) -> Path {
let q = p.filename().expect("path is a directory");
let mut q = q.to_owned();
q.push('-' as u8);
let vs = v.to_str();
let vs = match v { &Some(ref s) => s.to_owned(), &None => ~"0.0" };
q.push_all(vs.as_bytes());
p.with_filename(q)
}
Expand Down
11 changes: 5 additions & 6 deletions src/librustpkg/source_control.rs
Expand Up @@ -14,15 +14,14 @@ use std::{run, str};
use std::run::{ProcessOutput, ProcessOptions, Process};
use std::io::fs;
use extra::tempfile::TempDir;
use version::*;
use path_util::chmod_read_only;

/// Attempts to clone `source`, a local git repository, into `target`, a local
/// directory that doesn't exist.
/// Returns `DirToUse(p)` if the clone fails, where `p` is a newly created temporary
/// directory (that the callee may use, for example, to check out remote sources into).
/// Returns `CheckedOutSources` if the clone succeeded.
pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult {
pub fn safe_git_clone(source: &Path, v: &Option<~str>, target: &Path) -> CloneResult {
if source.exists() {
debug!("{} exists locally! Cloning it into {}",
source.display(), target.display());
Expand All @@ -44,7 +43,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
}
else {
match v {
&ExactRevision(ref s) => {
&Some(ref s) => {
let git_dir = target.join(".git");
debug!("`Running: git --work-tree={} --git-dir={} checkout {}",
*s, target.display(), git_dir.display());
Expand All @@ -65,7 +64,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
} else {
// Check that no version was specified. There's no reason to not handle the
// case where a version was requested, but I haven't implemented it.
assert!(*v == NoVersion);
assert!(*v == None);
let git_dir = target.join(".git");
debug!("Running: git --work-tree={} --git-dir={} pull --no-edit {}",
target.display(), git_dir.display(), source.display());
Expand Down Expand Up @@ -106,7 +105,7 @@ pub fn make_read_only(target: &Path) {
}

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

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

0 comments on commit 655433e

Please sign in to comment.