]> git.lizzy.rs Git - rust.git/commitdiff
rustpkg::version: Remove enum Version
authorklutzy <klutzytheklutzy@gmail.com>
Wed, 8 Jan 2014 05:09:48 +0000 (14:09 +0900)
committerklutzy <klutzytheklutzy@gmail.com>
Wed, 22 Jan 2014 18:02:40 +0000 (03:02 +0900)
Currently rustpkg doesn't use SemanticVersion or Tagged, so they are
removed. Remaining variants are replaced by `Option<~str>`.

src/librustpkg/api.rs
src/librustpkg/crate_id.rs
src/librustpkg/lib.rs
src/librustpkg/package_source.rs
src/librustpkg/path_util.rs
src/librustpkg/source_control.rs
src/librustpkg/tests.rs
src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs
src/librustpkg/testsuite/pass/src/fancy-lib/pkg.rs
src/librustpkg/util.rs
src/librustpkg/version.rs

index 19586ac48b07807e7cdef25c26634ba039fc8584..27dfc3cae41c4772158e11d2a9272abace7fecd6 100644 (file)
@@ -15,7 +15,6 @@
 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;
@@ -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(),
@@ -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(),
@@ -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)};
index bd9a75bad6975232a71989fbfaf45a10d66e5e02..9415e850e98ed0e28dc711042e3140c894ac94c3 100644 (file)
@@ -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;
@@ -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 {
@@ -42,6 +41,13 @@ fn eq(&self, other: &CrateId) -> bool {
 }
 
 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;
 
@@ -52,10 +58,6 @@ pub fn new(s: &str) -> 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,
@@ -67,13 +69,13 @@ pub fn new(s: &str) -> 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
@@ -124,7 +126,7 @@ fn next(&mut self) -> Option<(Path, Path)> {
 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())
     }
 }
 
index c9db8af0b8a9ce17e9b5547a93e2a521515b0456..22871179a6e3bfe1b97b930d8a405cf8542331b8 100644 (file)
@@ -163,7 +163,6 @@ fn build_custom(&mut self, exec: &mut workcache::Exec) -> ~str {
         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
@@ -243,7 +242,7 @@ fn build_args(&self, args: ~[~str], what: &WhatToBuild) -> Option<(CrateId, Path
 
         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);
@@ -289,6 +288,7 @@ fn build_args(&self, args: ~[~str], what: &WhatToBuild) -> Option<(CrateId, Path
             Some((crateid, dest_ws))
         }
     }
+
     fn run(&self, cmd: Command, args: ~[~str]) {
         let cwd = os::getcwd();
         match cmd {
index 651d64aa9d32f50bd214912c4ad6c116077133be..fce2f9e4d0c6b135e368326114344da6c20c00fd 100644 (file)
@@ -100,7 +100,7 @@ pub fn new(mut source_workspace: Path,
             // 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);
@@ -108,7 +108,7 @@ pub fn new(mut source_workspace: Path,
 
             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");
@@ -287,7 +287,7 @@ pub fn fetch_git(local: &Path, crateid: &CrateId) -> Option<Path> {
                 // 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;
 
index 3c91e6607849acbc42dca55b0639686a47c5c567..d8dee82d09e8aa34f3f53caae28c73401efebfef 100644 (file)
@@ -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};
@@ -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)
                         }
                     }
                 })
@@ -188,7 +188,7 @@ pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Opti
                                                  Install,
                                                  workspace,
                                                  libdir(),
-                                                 &NoVersion)
+                                                 &None)
     }
 }
 
@@ -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() {
@@ -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); }
                  }
@@ -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)
     }
 }
 
@@ -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 {
@@ -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)
 }
index 4b7aaf7e340d94af8593dac8dfc07102d3c5b70a..2346749feb53a0da3a0516dc8f2bc2236a1f4fa5 100644 (file)
@@ -14,7 +14,6 @@
 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
@@ -22,7 +21,7 @@
 /// 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());
@@ -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());
@@ -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());
@@ -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
@@ -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`");
index f2efcadea78545636114f32d5015c447ef937105..be5b6859c74e438e610ffb43686ad06e11e75cea 100644 (file)
@@ -25,8 +25,7 @@
 use extra::getopts::groups::getopts;
 use std::run::ProcessOutput;
 use installed_packages::list_installed_packages;
-use crate_id::{CrateId};
-use version::{ExactRevision, NoVersion, Version};
+use crate_id::CrateId;
 use path_util::{target_executable_in_workspace, target_test_in_workspace,
                target_bench_in_workspace, make_dir_rwx,
                library_in_workspace, installed_library_in_workspace,
@@ -63,7 +62,7 @@ fn fake_pkg() -> CrateId {
     CrateId {
         path: Path::new(sn.as_slice()),
         short_name: sn,
-        version: NoVersion
+        version: None
     }
 }
 
@@ -71,7 +70,7 @@ fn git_repo_pkg() -> CrateId {
     CrateId {
         path: Path::new("mockgithub.com/catamorphism/test-pkg"),
         short_name: ~"test-pkg",
-        version: NoVersion
+        version: None
     }
 }
 
@@ -88,28 +87,24 @@ fn mk_emptier_workspace(tag: &str) -> TempDir {
     workspace
 }
 
-fn mk_empty_workspace(short_name: &Path, version: &Version, tag: &str) -> TempDir {
+fn mk_empty_workspace(crate_id: &CrateId, tag: &str) -> TempDir {
     let workspace_dir = TempDir::new(tag).expect("couldn't create temp dir");
-    mk_workspace(workspace_dir.path(), short_name, version);
+    mk_workspace(workspace_dir.path(), crate_id);
     workspace_dir
 }
 
-fn mk_workspace(workspace: &Path, short_name: &Path, version: &Version) -> Path {
+fn mk_workspace(workspace: &Path, crate_id: &CrateId) -> Path {
     // include version number in directory name
     // FIXME (#9639): This needs to handle non-utf8 paths
-    let package_dir = workspace.join_many([~"src", format!("{}-{}",
-                                           short_name.as_str().unwrap(), version.to_str())]);
+    let package_dir = workspace.join_many([~"src", crate_id.short_name_with_version()]);
     fs::mkdir_recursive(&package_dir, io::UserRWX);
     package_dir
 }
 
-fn mk_temp_workspace(short_name: &Path, version: &Version) -> (TempDir, Path) {
-    let workspace_dir = mk_empty_workspace(short_name, version, "temp_workspace");
+fn mk_temp_workspace(crate_id: &CrateId) -> (TempDir, Path) {
+    let workspace_dir = mk_empty_workspace(crate_id, "temp_workspace");
     // FIXME (#9639): This needs to handle non-utf8 paths
-    let package_dir = workspace_dir.path().join_many([~"src",
-                                                      format!("{}-{}",
-                                                              short_name.as_str().unwrap(),
-                                                              version.to_str())]);
+    let package_dir = workspace_dir.path().join_many([~"src", crate_id.short_name_with_version()]);
 
     debug!("Created {} and does it exist? {:?}", package_dir.display(),
            package_dir.is_dir());
@@ -294,7 +289,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
 }
 
 fn create_local_package(crateid: &CrateId) -> TempDir {
-    let (workspace, parent_dir) = mk_temp_workspace(&crateid.path, &crateid.version);
+    let (workspace, parent_dir) = mk_temp_workspace(crateid);
     debug!("Created empty package dir for {}, returning {}", crateid.to_str(),
            parent_dir.display());
     workspace
@@ -348,11 +343,11 @@ fn create_local_package_with_custom_build_hook(crateid: &CrateId,
 
 }
 
-fn assert_lib_exists(repo: &Path, pkg_path: &Path, v: Version) {
+fn assert_lib_exists(repo: &Path, pkg_path: &Path, v: Option<~str>) {
     assert!(lib_exists(repo, pkg_path, v));
 }
 
-fn lib_exists(repo: &Path, pkg_path: &Path, _v: Version) -> bool { // ??? version?
+fn lib_exists(repo: &Path, pkg_path: &Path, _v: Option<~str>) -> bool { // ??? version?
     debug!("assert_lib_exists: repo = {}, pkg_path = {}", repo.display(), pkg_path.display());
     let lib = installed_library_in_workspace(pkg_path, repo);
     debug!("assert_lib_exists: checking whether {:?} exists", lib);
@@ -475,7 +470,7 @@ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path {
                          Build,
                          workspace,
                          "build",
-                         &NoVersion).expect("lib_output_file_name")
+                         &None).expect("lib_output_file_name")
 }
 
 #[cfg(target_os = "linux")]
@@ -567,7 +562,7 @@ fn test_install_valid() {
     let sysroot = test_sysroot();
     debug!("sysroot = {}", sysroot.display());
     let temp_pkg_id = fake_pkg();
-    let (temp_workspace, _pkg_dir) = mk_temp_workspace(&temp_pkg_id.path, &NoVersion);
+    let (temp_workspace, _pkg_dir) = mk_temp_workspace(&temp_pkg_id);
     let temp_workspace = temp_workspace.path();
     let ctxt = fake_ctxt(sysroot, temp_workspace);
     debug!("temp_workspace = {}", temp_workspace.display());
@@ -624,8 +619,7 @@ fn test_install_invalid() {
 #[test]
 fn test_install_valid_external() {
     let temp_pkg_id = CrateId::new("foo");
-    let (tempdir, _) = mk_temp_workspace(&temp_pkg_id.path,
-                                         &temp_pkg_id.version);
+    let (tempdir, _) = mk_temp_workspace(&temp_pkg_id);
     let temp_workspace = tempdir.path();
     command_line_test([~"install", ~"foo"], temp_workspace);
 
@@ -821,7 +815,7 @@ fn rustpkg_library_target() {
 
     add_git_tag(&package_dir, ~"1.0");
     command_line_test([~"install", ~"foo"], foo_repo);
-    assert_lib_exists(&foo_repo.join(".rust"), &Path::new("foo"), ExactRevision(~"1.0"));
+    assert_lib_exists(&foo_repo.join(".rust"), &Path::new("foo"), Some(~"1.0"));
 }
 
 #[test]
@@ -844,7 +838,7 @@ fn package_script_with_default_build() {
     debug!("package_script_with_default_build: {}", source.display());
     fs::copy(&source, &dir.join_many(["src", "fancy-lib-0.0", "pkg.rs"]));
     command_line_test([~"install", ~"fancy-lib"], dir);
-    assert_lib_exists(dir, &Path::new("fancy-lib"), NoVersion);
+    assert_lib_exists(dir, &Path::new("fancy-lib"), None);
     assert!(target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]).exists());
     let generated_path = target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]);
     debug!("generated path = {}", generated_path.display());
@@ -875,7 +869,7 @@ fn rustpkg_install_no_arg() {
               "fn main() { let _x = (); }");
     debug!("install_no_arg: dir = {}", package_dir.display());
     command_line_test([~"install"], &package_dir);
-    assert_lib_exists(&tmp, &Path::new("foo"), NoVersion);
+    assert_lib_exists(&tmp, &Path::new("foo"), None);
 }
 
 #[test]
@@ -898,7 +892,7 @@ fn rustpkg_clean_no_arg() {
 #[test]
 fn rust_path_test() {
     let dir_for_path = TempDir::new("more_rust").expect("rust_path_test failed");
-    let dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion);
+    let dir = mk_workspace(dir_for_path.path(), &CrateId::new("foo"));
     debug!("dir = {}", dir.display());
     writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }");
 
@@ -1322,8 +1316,9 @@ fn multiple_workspaces() {
 // Copy the exact same package into directory B and install it
 // Set the RUST_PATH to A:B
 // Make a third package that uses foo, make sure we can build/install it
-    let (a_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion);
-    let (b_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion);
+    let p_id = CrateId::new("foo");
+    let (a_loc, _pkg_dir) = mk_temp_workspace(&p_id);
+    let (b_loc, _pkg_dir) = mk_temp_workspace(&p_id);
     let (a_loc, b_loc) = (a_loc.path(), b_loc.path());
     debug!("Trying to install foo in {}", a_loc.display());
     command_line_test([~"install", ~"foo"], a_loc);
@@ -1348,7 +1343,7 @@ fn rust_path_hack_test(hack_flag: bool) {
    let p_id = CrateId::new("foo");
    let workspace = create_local_package(&p_id);
    let workspace = workspace.path();
-   let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+   let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace");
    let dest_workspace = dest_workspace.path();
    let foo_path = workspace.join_many(["src", "foo-0.0"]);
    let rust_path = Some(~[(~"RUST_PATH",
@@ -1357,11 +1352,11 @@ fn rust_path_hack_test(hack_flag: bool) {
                foo_path.as_str().unwrap()))]);
    command_line_test_with_env(~[~"install"] + if hack_flag { ~[~"--rust-path-hack"] } else { ~[] } +
                                ~[~"foo"], dest_workspace, rust_path);
-   assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion);
+   assert_lib_exists(dest_workspace, &Path::new("foo"), None);
    assert_executable_exists(dest_workspace, "foo");
    assert_built_library_exists(dest_workspace, "foo");
    assert_built_executable_exists(dest_workspace, "foo");
-   assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion));
+   assert!(!lib_exists(workspace, &Path::new("foo"), None));
    assert!(!executable_exists(workspace, "foo"));
    assert!(!built_library_exists(workspace, "foo"));
    assert!(!built_executable_exists(workspace, "foo"));
@@ -1396,15 +1391,15 @@ fn rust_path_hack_cwd() {
    fs::mkdir_recursive(&cwd, io::UserRWX);
    writeFile(&cwd.join("lib.rs"), "pub fn f() { }");
 
-   let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+   let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace");
    let dest_workspace = dest_workspace.path();
    // FIXME (#9639): This needs to handle non-utf8 paths
    let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
    command_line_test_with_env([~"install", ~"--rust-path-hack", ~"foo"], &cwd, rust_path);
    debug!("Checking that foo exists in {}", dest_workspace.display());
-   assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion);
+   assert_lib_exists(dest_workspace, &Path::new("foo"), None);
    assert_built_library_exists(dest_workspace, "foo");
-   assert!(!lib_exists(&cwd, &Path::new("foo"), NoVersion));
+   assert!(!lib_exists(&cwd, &Path::new("foo"), None));
    assert!(!built_library_exists(&cwd, "foo"));
 }
 
@@ -1417,15 +1412,15 @@ fn rust_path_hack_multi_path() {
    writeFile(&subdir.join("lib.rs"), "pub fn f() { }");
    let name = ~"foo/bar/quux";
 
-   let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+   let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace");
    let dest_workspace = dest_workspace.path();
    // FIXME (#9639): This needs to handle non-utf8 paths
    let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
    command_line_test_with_env([~"install", ~"--rust-path-hack", name.clone()], &subdir, rust_path);
    debug!("Checking that {} exists in {}", name, dest_workspace.display());
-   assert_lib_exists(dest_workspace, &Path::new("quux"), NoVersion);
+   assert_lib_exists(dest_workspace, &Path::new("quux"), None);
    assert_built_library_exists(dest_workspace, name);
-   assert!(!lib_exists(&subdir, &Path::new("quux"), NoVersion));
+   assert!(!lib_exists(&subdir, &Path::new("quux"), None));
    assert!(!built_library_exists(&subdir, name));
 }
 
@@ -1438,15 +1433,15 @@ fn rust_path_hack_install_no_arg() {
    assert!(make_dir_rwx(&source_dir));
    writeFile(&source_dir.join("lib.rs"), "pub fn f() { }");
 
-   let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+   let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace");
    let dest_workspace = dest_workspace.path();
    // FIXME (#9639): This needs to handle non-utf8 paths
    let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
    command_line_test_with_env([~"install", ~"--rust-path-hack"], &source_dir, rust_path);
    debug!("Checking that foo exists in {}", dest_workspace.display());
-   assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion);
+   assert_lib_exists(dest_workspace, &Path::new("foo"), None);
    assert_built_library_exists(dest_workspace, "foo");
-   assert!(!lib_exists(&source_dir, &Path::new("foo"), NoVersion));
+   assert!(!lib_exists(&source_dir, &Path::new("foo"), None));
    assert!(!built_library_exists(cwd, "foo"));
 }
 
@@ -1458,7 +1453,7 @@ fn rust_path_hack_build_no_arg() {
    assert!(make_dir_rwx(&source_dir));
    writeFile(&source_dir.join("lib.rs"), "pub fn f() { }");
 
-   let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+   let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace");
    let dest_workspace = dest_workspace.path();
    // FIXME (#9639): This needs to handle non-utf8 paths
    let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
@@ -1496,7 +1491,7 @@ fn rust_path_hack_build_with_dependency() {
 fn rust_path_install_target() {
     let dir_for_path = TempDir::new(
         "source_workspace").expect("rust_path_install_target failed");
-    let mut dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion);
+    let mut dir = mk_workspace(dir_for_path.path(), &CrateId::new("foo"));
     debug!("dir = {}", dir.display());
     writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }");
     let dir_to_install_to = TempDir::new(
@@ -1608,7 +1603,7 @@ fn notrans_flag_fail() {
                           workspace, None, BAD_FLAG_CODE);
         assert!(!built_executable_exists(workspace, "foo"));
         assert!(!object_file_exists(workspace, "foo"));
-        assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion));
+        assert!(!lib_exists(workspace, &Path::new("foo"), None));
     }
 }
 
@@ -1880,9 +1875,9 @@ fn test_recursive_deps() {
     command_line_test_with_env([~"install", ~"a"],
                                a_workspace,
                                environment);
-    assert_lib_exists(a_workspace, &Path::new("a"), NoVersion);
-    assert_lib_exists(b_workspace, &Path::new("b"), NoVersion);
-    assert_lib_exists(b_workspace, &Path::new("c"), NoVersion);
+    assert_lib_exists(a_workspace, &Path::new("a"), None);
+    assert_lib_exists(b_workspace, &Path::new("b"), None);
+    assert_lib_exists(b_workspace, &Path::new("c"), None);
 }
 
 #[test]
@@ -1890,7 +1885,7 @@ fn test_install_to_rust_path() {
     let p_id = CrateId::new("foo");
     let second_workspace = create_local_package(&p_id);
     let second_workspace = second_workspace.path();
-    let first_workspace = mk_empty_workspace(&Path::new("p"), &NoVersion, "dest");
+    let first_workspace = mk_empty_workspace(&CrateId::new("p"), "dest");
     let first_workspace = first_workspace.path();
     // FIXME (#9639): This needs to handle non-utf8 paths
     let rust_path = Some(~[(~"RUST_PATH",
@@ -1937,7 +1932,7 @@ fn test_target_specific_install_dir() {
                        ~"foo"],
                       workspace);
     assert!(workspace.join_many([~"lib", host_triple()]).is_dir());
-    assert_lib_exists(workspace, &Path::new("foo"), NoVersion);
+    assert_lib_exists(workspace, &Path::new("foo"), None);
     assert!(fs::readdir(&workspace.join("lib")).len() == 1);
     assert!(workspace.join("bin").is_dir());
     assert_executable_exists(workspace, "foo");
@@ -1965,7 +1960,7 @@ fn install_after_build() {
     command_line_test([~"build", ~"b"], workspace);
     command_line_test([~"install", ~"b"], workspace);
     assert_executable_exists(workspace, b_id.short_name);
-    assert_lib_exists(workspace, &b_id.path, NoVersion);
+    assert_lib_exists(workspace, &b_id.path, None);
 }
 
 #[test]
@@ -1977,7 +1972,7 @@ fn reinstall() {
     // and make sure executable was re-installed
     command_line_test([~"install", ~"b"], workspace);
     assert_executable_exists(workspace, b.short_name);
-    assert_lib_exists(workspace, &b.path, NoVersion);
+    assert_lib_exists(workspace, &b.path, None);
     remove_executable_file(&b, workspace);
     command_line_test([~"install", ~"b"], workspace);
     assert_executable_exists(workspace, b.short_name);
@@ -2013,7 +2008,7 @@ fn correct_package_name_with_rust_path_hack() {
     let bar_id = CrateId::new("bar");
     let foo_workspace = create_local_package(&foo_id);
     let foo_workspace = foo_workspace.path();
-    let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+    let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace");
     let dest_workspace = dest_workspace.path();
 
     writeFile(&dest_workspace.join_many(["src", "bar-0.0", "main.rs"]),
@@ -2145,7 +2140,7 @@ fn test_installed_read_only() {
               "pub fn f() { let _x = (); }");
     add_git_tag(&repo_subdir, ~"0.0"); // this has the effect of committing the files
     // update crateid to what will be auto-detected
-    temp_pkg_id.version = ExactRevision(~"0.0");
+    temp_pkg_id.version = Some(~"0.0");
 
     // FIXME (#9639): This needs to handle non-utf8 paths
     command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo);
@@ -2202,7 +2197,7 @@ fn test_installed_local_changes() {
                                                   "test-pkg-0.0"]);
     debug!("---- git clone {} {}", repo_subdir.display(), target_dir.display());
 
-    let c_res = safe_git_clone(&repo_subdir, &NoVersion, &target_dir);
+    let c_res = safe_git_clone(&repo_subdir, &None, &target_dir);
 
     match c_res {
         DirToUse(_) => fail!("test_installed_local_changes failed"),
index b6c5e15c09a5f94ac0b81512d7c95b1cff7324dd..b6dba40ebd46aed7600e3d4b7053116c8ec355cb 100644 (file)
@@ -13,7 +13,7 @@
 
 use std::{os, task};
 use rustpkg::api;
-use rustpkg::version::NoVersion;
+use rustpkg::version::None;
 use rustpkg::workcache_support::digest_file_with_date;
 use rustpkg::exit_codes::COPY_FAILED_CODE;
 
@@ -73,7 +73,7 @@ pub fn main() {
         api::install_pkg(&mut cc,
                          os::getcwd(),
                          ~"cdep",
-                         NoVersion,
+                         None,
                          ~[(~"binary", out_lib_path.clone()), (~"file", foo_c_name.clone())]);
     };
 
index 4a107de55a59f590ef043807bd4a0b5791cc4797..7b1291025e40b222ae51f7195943b651a606586b 100644 (file)
@@ -14,7 +14,7 @@
 use std::os;
 use std::io::File;
 use rustpkg::api;
-use rustpkg::version::NoVersion;
+use rustpkg::version::None;
 
 pub fn main() {
     let args = os::args();
@@ -48,5 +48,5 @@ pub fn main() {
                 for _ in xs.iter() { assert!(true); } }".as_bytes());
 
     let context = api::default_context(sysroot, api::default_workspace());
-    api::install_pkg(&context, os::getcwd(), ~"fancy-lib", NoVersion, ~[]);
+    api::install_pkg(&context, os::getcwd(), ~"fancy-lib", None, ~[]);
 }
index 4d8f5c668b74fd5645a12a7020859dd6cb06b205..18e773d5f15a8ec02385a7d837ab1cf62d00bc06 100644 (file)
@@ -315,7 +315,7 @@ pub fn compile_input(context: &BuildContext,
             attr::mk_name_value_item_str(@"crate_id",
                                          format!("{}\\#{}",
                                                  pkg_id.path.as_str().unwrap(),
-                                                 pkg_id.version.to_str()).to_managed());
+                                                 pkg_id.get_version()).to_managed());
 
         debug!("crateid attr: {:?}", crateid_attr);
         crate.attrs.push(attr::mk_attr(crateid_attr));
index 5da5b4fece9748a67d21732e20f8711675682022..93e7a052efa06d9bf29917e18968f3d6fee7ab22 100644 (file)
 
 extern mod std;
 
-use extra::semver;
-use std::{char, result};
+use std::char;
 
-#[deriving(Clone)]
-pub enum Version {
-    ExactRevision(~str), // Should look like a m.n.(...).x
-    SemanticVersion(semver::Version),
-    Tagged(~str), // String that can't be parsed as a version.
-                  // Requirements get interpreted exactly
-    NoVersion // user didn't specify a version -- prints as 0.0
-}
-
-// Equality on versions is non-symmetric: if self is NoVersion, it's equal to
-// anything; but if self is a precise version, it's not equal to NoVersion.
-// We should probably make equality symmetric, and use less-than and greater-than
-// where we currently use eq
-impl Eq for Version {
-    fn eq(&self, other: &Version) -> bool {
-        match (self, other) {
-            (&ExactRevision(ref s1), &ExactRevision(ref s2)) => *s1 == *s2,
-            (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => *v1 == *v2,
-            (&NoVersion, _) => true,
-            _ => false
-        }
-    }
-}
-
-impl Ord for Version {
-    fn lt(&self, other: &Version) -> bool {
-        match (self, other) {
-            (&NoVersion, _) => true,
-            (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 < f2,
-            (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 < v2,
-            _ => false // incomparable, really
-        }
-    }
-    fn le(&self, other: &Version) -> bool {
-        match (self, other) {
-            (&NoVersion, _) => true,
-            (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 <= f2,
-            (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 <= v2,
-            _ => false // incomparable, really
-        }
-    }
-    fn ge(&self, other: &Version) -> bool {
-        match (self, other) {
-            (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 > f2,
-            (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 > v2,
-            _ => false // incomparable, really
-        }
-    }
-    fn gt(&self, other: &Version) -> bool {
-        match (self, other) {
-            (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 >= f2,
-            (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 >= v2,
-            _ => false // incomparable, really
-        }
-    }
-
-}
-
-impl ToStr for Version {
-    fn to_str(&self) -> ~str {
-        match *self {
-            ExactRevision(ref n) | Tagged(ref n) => format!("{}", n.to_str()),
-            SemanticVersion(ref v) => format!("{}", v.to_str()),
-            NoVersion => ~"0.0"
-        }
-    }
-}
-
-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")
-    }
-}
+pub type Version = Option<~str>;
 
 // Being lazy since we don't have a regexp library now
 #[deriving(Eq)]
@@ -99,7 +25,7 @@ enum ParseState {
     SawDot
 }
 
-pub fn try_parsing_version(s: &str) -> Option<Version> {
+pub fn try_parsing_version(s: &str) -> Option<~str> {
     let s = s.trim();
     debug!("Attempting to parse: {}", s);
     let mut parse_state = Start;
@@ -115,7 +41,7 @@ pub fn try_parsing_version(s: &str) -> Option<Version> {
         }
     }
     match parse_state {
-        SawDigit => Some(ExactRevision(s.to_owned())),
+        SawDigit => Some(s.to_owned()),
         _        => None
     }
 }
@@ -136,7 +62,7 @@ pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, Vers
         Some(i) => {
             let path = s.slice(0, i);
             // n.b. for now, assuming an exact revision is intended, not a SemVer
-            Some((path, ExactRevision(s.slice(i + 1, s.len()).to_owned())))
+            Some((path, Some(s.slice(i + 1, s.len()).to_owned())))
         }
         None => {
             None
@@ -146,11 +72,11 @@ pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, Vers
 
 #[test]
 fn test_parse_version() {
-    assert!(try_parsing_version("1.2") == Some(ExactRevision(~"1.2")));
-    assert!(try_parsing_version("1.0.17") == Some(ExactRevision(~"1.0.17")));
+    assert!(try_parsing_version("1.2") == Some(~"1.2"));
+    assert!(try_parsing_version("1.0.17") == Some(~"1.0.17"));
     assert!(try_parsing_version("you're_a_kitty") == None);
     assert!(try_parsing_version("42..1") == None);
-    assert!(try_parsing_version("17") == Some(ExactRevision(~"17")));
+    assert!(try_parsing_version("17") == Some(~"17"));
     assert!(try_parsing_version(".1.2.3") == None);
     assert!(try_parsing_version("2.3.") == None);
 }
@@ -159,9 +85,9 @@ fn test_parse_version() {
 fn test_split_version() {
     let s = "a/b/c#0.1";
     debug!("== {:?} ==", split_version(s));
-    assert!(split_version(s) == Some((s.slice(0, 5), ExactRevision(~"0.1"))));
+    assert!(split_version(s) == Some((s.slice(0, 5), Some(~"0.1"))));
     assert!(split_version("a/b/c") == None);
     let s = "a#1.2";
-    assert!(split_version(s) == Some((s.slice(0, 1), ExactRevision(~"1.2"))));
+    assert!(split_version(s) == Some((s.slice(0, 1), Some(~"1.2"))));
     assert!(split_version("a#a#3.4") == None);
 }