forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rustc/rusti/rustpkg: Infer packages from
extern mod
directives
This commit won't be quite as useful until I implement RUST_PATH and until we change `extern mod` to take a general string instead of an identifier (rust-lang#5682 and rust-lang#6407). With that said, now if you're using rustpkg and a program contains: extern mod foo; rustpkg will attempt to search for `foo`, so that you don't have to provide a -L directory explicitly. In addition, rustpkg will actually try to build and install `foo`, unless it's already installed (specifically, I tested that `extern mod extra;` would not cause it to try to find source for `extra` and compile it again). This is as per rust-lang#5681. Incidentally, I changed some driver code to infer the link name from the crate link_meta attributes. If that change isn't ok, say something. Also, I changed the addl_lib_search_paths field in the session options to be an @mut ~[Path] so that it can be modified after expansion but before later phases.
- Loading branch information
1 parent
37388fb
commit ed3e7a1
Showing
17 changed files
with
745 additions
and
492 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright 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. | ||
|
||
extern mod std; | ||
|
||
pub use package_path::{RemotePath, LocalPath, normalize, hash}; | ||
use std::semver; | ||
use core::prelude::*; | ||
|
||
/// Placeholder | ||
pub fn default_version() -> Version { ExactRevision(0.1) } | ||
|
||
/// Path-fragment identifier of a package such as | ||
/// 'github.com/graydon/test'; path must be a relative | ||
/// path with >=1 component. | ||
pub struct PkgId { | ||
/// Remote path: for example, github.com/mozilla/quux-whatever | ||
remote_path: RemotePath, | ||
/// Local path: for example, /home/quux/github.com/mozilla/quux_whatever | ||
/// Note that '-' normalizes to '_' when mapping a remote path | ||
/// onto a local path | ||
/// Also, this will change when we implement #6407, though we'll still | ||
/// need to keep track of separate local and remote paths | ||
local_path: LocalPath, | ||
/// Short name. This is the local path's filestem, but we store it | ||
/// redundantly so as to not call get() everywhere (filestem() returns an | ||
/// option) | ||
short_name: ~str, | ||
version: Version | ||
} | ||
|
||
pub impl PkgId { | ||
fn new(s: &str) -> PkgId { | ||
use conditions::bad_pkg_id::cond; | ||
|
||
let p = Path(s); | ||
if p.is_absolute { | ||
return cond.raise((p, ~"absolute pkgid")); | ||
} | ||
if p.components.len() < 1 { | ||
return cond.raise((p, ~"0-length 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)); | ||
PkgId { | ||
local_path: local_path, | ||
remote_path: remote_path, | ||
short_name: short_name, | ||
version: default_version() | ||
} | ||
} | ||
|
||
fn hash(&self) -> ~str { | ||
fmt!("%s-%s-%s", self.remote_path.to_str(), | ||
hash(self.remote_path.to_str() + self.version.to_str()), | ||
self.version.to_str()) | ||
} | ||
|
||
fn short_name_with_version(&self) -> ~str { | ||
fmt!("%s-%s", self.short_name, self.version.to_str()) | ||
} | ||
} | ||
|
||
impl ToStr for PkgId { | ||
fn to_str(&self) -> ~str { | ||
// 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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 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. | ||
|
||
// rustpkg utilities having to do with local and remote paths | ||
|
||
use core::path::Path; | ||
use core::option::Some; | ||
use core::{hash, str}; | ||
use core::rt::io::Writer; | ||
use core::hash::Streaming; | ||
|
||
/// Wrappers to prevent local and remote paths from getting confused | ||
/// (These will go away after #6407) | ||
pub struct RemotePath (Path); | ||
pub struct LocalPath (Path); | ||
|
||
|
||
// normalize should be the only way to construct a LocalPath | ||
// (though this isn't enforced) | ||
/// Replace all occurrences of '-' in the stem part of path with '_' | ||
/// This is because we treat rust-foo-bar-quux and rust_foo_bar_quux | ||
/// as the same name | ||
pub fn normalize(p_: RemotePath) -> LocalPath { | ||
let RemotePath(p) = p_; | ||
match p.filestem() { | ||
None => LocalPath(p), | ||
Some(st) => { | ||
let replaced = str::replace(st, "-", "_"); | ||
if replaced != st { | ||
LocalPath(p.with_filestem(replaced)) | ||
} | ||
else { | ||
LocalPath(p) | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn write<W: Writer>(writer: &mut W, string: &str) { | ||
let buffer = str::as_bytes_slice(string); | ||
writer.write(buffer); | ||
} | ||
|
||
pub fn hash(data: ~str) -> ~str { | ||
let hasher = &mut hash::default_state(); | ||
write(hasher, data); | ||
hasher.result_str() | ||
} |
Oops, something went wrong.