Skip to content

Commit

Permalink
rustpkg: Massage for landing.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Feb 16, 2013
1 parent d4e71da commit 585d6f7
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 521 deletions.
30 changes: 29 additions & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let unwrapped_msg = match msg {
*/

use cmp::Eq;
use cmp::{Eq,Ord};
use kinds::Copy;
use option;
use ptr;
Expand All @@ -56,6 +56,34 @@ pub enum Option<T> {
Some(T),
}

pub impl<T:Ord> Ord for Option<T> {
pure fn lt(&self, other: &Option<T>) -> bool {
match (self, other) {
(&None, &None) => false,
(&None, &Some(_)) => true,
(&Some(_), &None) => false,
(&Some(ref a), &Some(ref b)) => *a < *b
}
}

pure fn le(&self, other: &Option<T>) -> bool {
match (self, other) {
(&None, &None) => true,
(&None, &Some(_)) => true,
(&Some(_), &None) => false,
(&Some(ref a), &Some(ref b)) => *a <= *b
}
}

pure fn ge(&self, other: &Option<T>) -> bool {
! (self < other)
}

pure fn gt(&self, other: &Option<T>) -> bool {
! (self <= other)
}
}

#[inline(always)]
pub pure fn get<T: Copy>(opt: Option<T>) -> T {
/*!
Expand Down
84 changes: 47 additions & 37 deletions src/librustpkg/rustpkg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#[allow(vecs_implicitly_copyable,
non_implicitly_copyable_typarams)];

#[legacy_records];

extern mod core(vers = "0.6");
extern mod std(vers = "0.6");
extern mod rustc(vers = "0.6");
Expand All @@ -29,10 +31,11 @@ use core::*;
use io::{ReaderUtil, WriterUtil};
use std::{json, semver, getopts};
use std::net::url;
use send_map::linear::LinearMap;
use hashmap::linear::LinearMap;
use rustc::metadata::filesearch;
use rustc::driver::{driver, session};
use syntax::{ast, attr, codemap, diagnostic, parse, visit};
use syntax::codemap::spanned;

mod usage;
mod util;
Expand Down Expand Up @@ -83,7 +86,7 @@ impl PackageScript {

for mis.each |a| {
match a.node {
ast::meta_name_value(v, ast::spanned {
ast::meta_name_value(v, spanned {
node: ast::lit_str(s),
span: _}) => {
match v {
Expand All @@ -106,7 +109,7 @@ impl PackageScript {

for mis.each |a| {
match a.node {
ast::meta_name_value(v, ast::spanned {
ast::meta_name_value(v, spanned {
node: ast::lit_str(s),
span: _}) => {
match v {
Expand All @@ -127,7 +130,7 @@ impl PackageScript {

for mis.each |a| {
match a.node {
ast::meta_name_value(v, ast::spanned {
ast::meta_name_value(v, spanned {
node: ast::lit_str(s),
span: _}) => {
match v {
Expand Down Expand Up @@ -156,7 +159,7 @@ impl PackageScript {
let (u, t) = load_pkg_dep_attr(mis);

if u.is_none() {
fail ~"pkg_dep attr without a url value";
fail!(~"pkg_dep attr without a url value");
}

deps.push((u.get(), t));
Expand All @@ -165,7 +168,7 @@ impl PackageScript {
let f = load_pkg_crate_attr(mis);

if f.is_none() {
fail ~"pkg_file attr without a file value";
fail!(~"pkg_file attr without a file value");
}

crates.push(f.get());
Expand Down Expand Up @@ -222,7 +225,7 @@ impl PackageScript {

// Build the bootstrap and run a command
// FIXME (#4432): Use workcache to only compile the script when changed
fn run(cmd: ~str, test: bool) -> int {
fn run(&self, cmd: ~str, test: bool) -> int {
let work_dir = self.work_dir();
let input = self.input;
let sess = self.sess;
Expand All @@ -238,12 +241,12 @@ impl PackageScript {
run::run_program(exe.to_str(), ~[root.to_str(), cmd, test.to_str()])
}

fn hash() -> ~str {
fn hash(&self) -> ~str {
fmt!("%s-%s-%s", self.name, util::hash(self.id + self.vers.to_str()),
self.vers.to_str())
}

fn work_dir() -> Path {
fn work_dir(&self) -> Path {
util::root().push(~"work").push(self.hash())
}
}
Expand All @@ -255,7 +258,7 @@ struct Ctx {
}

impl Ctx {
fn run(cmd: ~str, args: ~[~str]) {
fn run(&self, cmd: ~str, args: ~[~str]) {
let root = util::root();

util::need_dir(&root);
Expand Down Expand Up @@ -333,11 +336,11 @@ impl Ctx {

self.unprefer(name.get(), vers);
}
_ => fail ~"reached an unhandled command"
_ => fail!(~"reached an unhandled command")
}
}

fn do_cmd(cmd: ~str) -> bool {
fn do_cmd(&self, cmd: ~str) -> bool {
match cmd {
~"build" | ~"test" => {
util::error(~"that command cannot be manually called");
Expand Down Expand Up @@ -367,7 +370,7 @@ impl Ctx {
status == 0
}

fn build(dir: &Path, verbose: bool, opt: bool,
fn build(&self, dir: &Path, verbose: bool, opt: bool,
test: bool) -> Option<PackageScript> {
let cwd = &os::getcwd();
let script = match PackageScript::parse(dir) {
Expand Down Expand Up @@ -450,12 +453,12 @@ impl Ctx {
Some(script)
}

fn compile(crate: &Path, dir: &Path, flags: ~[~str],
fn compile(&self, crate: &Path, dir: &Path, flags: ~[~str],
cfgs: ~[~str], opt: bool, test: bool) -> bool {
util::compile_crate(None, crate, dir, flags, cfgs, opt, test)
}

fn clean() -> bool {
fn clean(&self) -> bool {
let script = match PackageScript::parse(&os::getcwd()) {
result::Ok(script) => script,
result::Err(err) => {
Expand All @@ -480,23 +483,24 @@ impl Ctx {
true
}

fn info() {
fn info(&self) {
if self.json {
match PackageScript::parse(&os::getcwd()) {
result::Ok(script) => {
let mut map = ~LinearMap();
let mut map = ~LinearMap::new();

map.insert(~"id", json::String(script.id));
map.insert(~"name", json::String(script.name));
map.insert(~"vers", json::String(script.vers.to_str()));
map.insert(~"deps", json::List(do script.deps.map |&dep| {
let (url, target) = dep;
let mut inner = ~LinearMap();
let mut inner = ~LinearMap::new();

inner.insert(~"url", json::String(url));

if !target.is_none() {
inner.insert(~"target", json::String(target.get()));
inner.insert(~"target",
json::String(target.get()));
}

json::Object(inner)
Expand All @@ -519,7 +523,12 @@ impl Ctx {
util::note(fmt!("id: %s", script.id));
util::note(fmt!("name: %s", script.name));
util::note(fmt!("vers: %s", script.vers.to_str()));
util::note(fmt!("deps: %s", if script.deps.len() > 0 { ~"" } else { ~"none" }));
util::note(fmt!("deps: %s",
if script.deps.len() > 0 {
~""
} else {
~"none"
}));

for script.deps.each |&dep| {
let (url, target) = dep;
Expand All @@ -532,7 +541,8 @@ impl Ctx {
}
}

fn install(url: Option<~str>, target: Option<~str>, cache: bool) -> bool {
fn install(&self, url: Option<~str>,
target: Option<~str>, cache: bool) -> bool {
let mut success;
let mut dir;

Expand Down Expand Up @@ -608,7 +618,7 @@ impl Ctx {
true
}

fn fetch(dir: &Path, url: ~str, target: Option<~str>) -> bool {
fn fetch(&self, dir: &Path, url: ~str, target: Option<~str>) -> bool {
let url = if str::find_str(url, "://").is_none() {
~"http://" + url }
else { url };
Expand Down Expand Up @@ -641,7 +651,7 @@ impl Ctx {
}
}

fn fetch_curl(dir: &Path, url: ~str) -> bool {
fn fetch_curl(&self, dir: &Path, url: ~str) -> bool {
util::note(fmt!("fetching from %s using curl", url));

let tar = dir.dir_path().push(&dir.file_path().to_str() + ~".tar");
Expand All @@ -666,7 +676,7 @@ impl Ctx {
true
}

fn fetch_git(dir: &Path, url: ~str, target: Option<~str>) -> bool {
fn fetch_git(&self, dir: &Path, url: ~str, target: Option<~str>) -> bool {
util::note(fmt!("fetching from %s using git", url));

// Git can't clone into a non-empty directory
Expand Down Expand Up @@ -698,7 +708,7 @@ impl Ctx {
true
}

fn prefer(id: ~str, vers: Option<~str>) -> bool {
fn prefer(&self, id: ~str, vers: Option<~str>) -> bool {
let package = match util::get_pkg(id, vers) {
result::Ok(package) => package,
result::Err(err) => {
Expand Down Expand Up @@ -735,7 +745,7 @@ impl Ctx {
true
}

fn test() -> bool {
fn test(&self) -> bool {
let script = match self.build(&os::getcwd(), false, false, true) {
Some(script) => script,
None => {
Expand Down Expand Up @@ -773,7 +783,7 @@ impl Ctx {
true
}

fn uninstall(id: ~str, vers: Option<~str>) -> bool {
fn uninstall(&self, id: ~str, vers: Option<~str>) -> bool {
let package = match util::get_pkg(id, vers) {
result::Ok(package) => package,
result::Err(err) => {
Expand Down Expand Up @@ -812,7 +822,7 @@ impl Ctx {
true
}

fn unprefer(id: ~str, vers: Option<~str>) -> bool {
fn unprefer(&self, id: ~str, vers: Option<~str>) -> bool {
let package = match util::get_pkg(id, vers) {
result::Ok(package) => package,
result::Err(err) => {
Expand Down Expand Up @@ -904,7 +914,7 @@ pub fn main() {
Ctx {
cfgs: cfgs,
json: json,
mut dep_cache: LinearMap()
mut dep_cache: LinearMap::new()
}.run(cmd, args);
}

Expand Down Expand Up @@ -942,31 +952,31 @@ pub fn run(listeners: ~[Listener]) {
}

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

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

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

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

5 comments on commit 585d6f7

@bors
Copy link
Contributor

@bors bors commented on 585d6f7 Feb 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from graydon
at graydon@585d6f7

@bors
Copy link
Contributor

@bors bors commented on 585d6f7 Feb 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging graydon/rust/rustpkg = 585d6f7 into auto

@bors
Copy link
Contributor

@bors bors commented on 585d6f7 Feb 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graydon/rust/rustpkg = 585d6f7 merged ok, testing candidate = 354da41

@bors
Copy link
Contributor

@bors bors commented on 585d6f7 Feb 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 585d6f7 Feb 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 354da41

Please sign in to comment.