2013-02-28 07:15:32 -06:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2013-01-14 04:55:47 -06:00
|
|
|
// 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.
|
|
|
|
|
2013-04-12 18:15:40 -05:00
|
|
|
// rustpkg - a package manager and build system for Rust
|
2013-01-14 04:55:47 -06:00
|
|
|
|
|
|
|
#[link(name = "rustpkg",
|
2013-04-04 23:46:37 -05:00
|
|
|
vers = "0.7-pre",
|
2013-01-14 04:55:47 -06:00
|
|
|
uuid = "25de5e6e-279e-4a20-845c-4cabae92daaf",
|
|
|
|
url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")];
|
|
|
|
|
2013-03-01 10:41:31 -06:00
|
|
|
#[license = "MIT/ASL2"];
|
2013-01-14 04:55:47 -06:00
|
|
|
#[crate_type = "lib"];
|
|
|
|
|
2013-05-30 14:03:21 -05:00
|
|
|
#[no_core];
|
2013-05-17 17:28:44 -05:00
|
|
|
#[no_std];
|
|
|
|
|
|
|
|
extern mod core(name = "std");
|
2013-05-24 21:35:29 -05:00
|
|
|
extern mod extra(name = "extra");
|
2013-05-17 17:28:44 -05:00
|
|
|
|
2013-05-18 23:21:41 -05:00
|
|
|
extern mod rustc;
|
|
|
|
extern mod syntax;
|
2013-01-14 04:55:47 -06:00
|
|
|
|
2013-05-17 17:28:44 -05:00
|
|
|
use core::prelude::*;
|
2013-01-15 07:57:03 -06:00
|
|
|
use core::*;
|
2013-04-11 19:43:02 -05:00
|
|
|
pub use core::path::Path;
|
2013-04-03 08:28:36 -05:00
|
|
|
use core::hashmap::HashMap;
|
2013-01-18 02:31:43 -06:00
|
|
|
use rustc::driver::{driver, session};
|
2013-03-01 12:44:43 -06:00
|
|
|
use rustc::metadata::filesearch;
|
2013-05-24 21:35:29 -05:00
|
|
|
use extra::{getopts};
|
2013-03-26 15:38:07 -05:00
|
|
|
use syntax::{ast, diagnostic};
|
2013-04-17 15:53:34 -05:00
|
|
|
use util::*;
|
2013-06-01 17:59:12 -05:00
|
|
|
use path_util::{build_pkg_id_in_workspace, first_pkgid_src_in_workspace};
|
2013-05-27 19:45:16 -05:00
|
|
|
use path_util::u_rwx;
|
2013-05-02 15:09:28 -05:00
|
|
|
use path_util::{built_executable_in_workspace, built_library_in_workspace};
|
|
|
|
use path_util::{target_executable_in_workspace, target_library_in_workspace};
|
2013-04-24 19:37:59 -05:00
|
|
|
use workspace::pkg_parent_workspaces;
|
|
|
|
use context::Ctx;
|
2013-05-27 19:45:16 -05:00
|
|
|
use package_id::PkgId;
|
2013-06-01 17:59:12 -05:00
|
|
|
use package_source::PkgSrc;
|
2013-01-14 04:55:47 -06:00
|
|
|
|
2013-04-12 18:15:40 -05:00
|
|
|
mod conditions;
|
2013-04-24 19:37:59 -05:00
|
|
|
mod context;
|
2013-06-01 17:59:12 -05:00
|
|
|
mod crate;
|
2013-05-27 19:45:16 -05:00
|
|
|
mod package_id;
|
|
|
|
mod package_path;
|
2013-06-01 17:59:12 -05:00
|
|
|
mod package_source;
|
2013-04-12 18:15:40 -05:00
|
|
|
mod path_util;
|
2013-05-27 19:45:16 -05:00
|
|
|
mod search;
|
|
|
|
mod target;
|
2013-05-12 15:50:57 -05:00
|
|
|
#[cfg(test)]
|
2013-04-24 19:37:59 -05:00
|
|
|
mod tests;
|
2013-01-15 07:57:03 -06:00
|
|
|
mod util;
|
2013-05-30 14:03:21 -05:00
|
|
|
mod version;
|
2013-04-24 19:37:59 -05:00
|
|
|
mod workspace;
|
2013-01-15 07:57:03 -06:00
|
|
|
|
2013-05-12 16:48:01 -05:00
|
|
|
pub mod usage;
|
|
|
|
|
2013-05-24 21:35:29 -05:00
|
|
|
mod std {
|
|
|
|
pub use core::cmp;
|
|
|
|
pub use core::condition;
|
|
|
|
pub use core::os;
|
|
|
|
pub use core::str;
|
|
|
|
pub use core::sys;
|
|
|
|
pub use core::unstable;
|
|
|
|
}
|
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
/// A PkgScript represents user-supplied custom logic for
|
|
|
|
/// special build hooks. This only exists for packages with
|
|
|
|
/// an explicit package script.
|
2013-05-11 21:45:13 -05:00
|
|
|
struct PkgScript<'self> {
|
2013-04-11 19:43:02 -05:00
|
|
|
/// Uniquely identifies this package
|
2013-05-11 21:45:13 -05:00
|
|
|
id: &'self PkgId,
|
2013-04-11 19:43:02 -05:00
|
|
|
// Used to have this field: deps: ~[(~str, Option<~str>)]
|
|
|
|
// but I think it shouldn't be stored here
|
|
|
|
/// The contents of the package script: either a file path,
|
|
|
|
/// or a string containing the text of the input
|
2013-01-22 19:19:13 -06:00
|
|
|
input: driver::input,
|
2013-04-11 19:43:02 -05:00
|
|
|
/// The session to use *only* for compiling the custom
|
|
|
|
/// build script
|
2013-01-22 19:19:13 -06:00
|
|
|
sess: session::Session,
|
2013-04-11 19:43:02 -05:00
|
|
|
/// The config for compiling the custom build script
|
2013-01-22 19:19:13 -06:00
|
|
|
cfg: ast::crate_cfg,
|
2013-04-11 19:43:02 -05:00
|
|
|
/// The crate for the custom build script
|
2013-01-22 19:19:13 -06:00
|
|
|
crate: @ast::crate,
|
2013-04-11 19:43:02 -05:00
|
|
|
/// Directory in which to store build output
|
|
|
|
build_dir: Path
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:13 -05:00
|
|
|
impl<'self> PkgScript<'self> {
|
2013-04-11 19:43:02 -05:00
|
|
|
/// Given the path name for a package script
|
|
|
|
/// and a package ID, parse the package script into
|
|
|
|
/// a PkgScript that we can then execute
|
2013-05-11 21:45:13 -05:00
|
|
|
fn parse<'a>(script: Path, workspace: &Path, id: &'a PkgId) -> PkgScript<'a> {
|
2013-04-11 19:43:02 -05:00
|
|
|
// Get the executable name that was invoked
|
2013-05-11 21:45:13 -05:00
|
|
|
let binary = @copy os::args()[0];
|
2013-04-11 19:43:02 -05:00
|
|
|
// Build the rustc session data structures to pass
|
|
|
|
// to the compiler
|
2013-02-19 02:01:03 -06:00
|
|
|
let options = @session::options {
|
2013-05-11 21:45:13 -05:00
|
|
|
binary: binary,
|
2013-01-22 19:19:13 -06:00
|
|
|
crate_type: session::bin_crate,
|
2013-05-11 21:45:13 -05:00
|
|
|
.. copy *session::basic_options()
|
2013-01-22 19:19:13 -06:00
|
|
|
};
|
|
|
|
let input = driver::file_input(script);
|
|
|
|
let sess = driver::build_session(options, diagnostic::emit);
|
2013-05-11 21:45:13 -05:00
|
|
|
let cfg = driver::build_configuration(sess, binary, &input);
|
2013-05-27 19:45:16 -05:00
|
|
|
let (crate, _) = driver::compile_upto(sess, copy cfg, &input, driver::cu_parse, None);
|
2013-04-22 19:54:54 -05:00
|
|
|
let work_dir = build_pkg_id_in_workspace(id, workspace);
|
2013-01-16 05:59:37 -06:00
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
debug!("Returning package script with id %?", id);
|
2013-01-16 05:59:37 -06:00
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
PkgScript {
|
2013-01-16 05:59:37 -06:00
|
|
|
id: id,
|
2013-01-22 19:19:13 -06:00
|
|
|
input: input,
|
|
|
|
sess: sess,
|
|
|
|
cfg: cfg,
|
2013-05-28 17:31:32 -05:00
|
|
|
crate: crate.unwrap(),
|
2013-04-11 19:43:02 -05:00
|
|
|
build_dir: work_dir
|
|
|
|
}
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
/// 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
|
|
|
|
/// calling the package script's configs() function if it exists
|
2013-01-23 03:25:03 -06:00
|
|
|
// FIXME (#4432): Use workcache to only compile the script when changed
|
2013-04-11 19:43:02 -05:00
|
|
|
fn run_custom(&self, what: ~str) -> (~[~str], ExitCode) {
|
|
|
|
debug!("run_custom: %s", what);
|
2013-01-22 19:19:13 -06:00
|
|
|
let sess = self.sess;
|
2013-04-11 19:43:02 -05:00
|
|
|
|
|
|
|
debug!("Working directory = %s", self.build_dir.to_str());
|
|
|
|
// Collect together any user-defined commands in the package script
|
2013-01-22 19:19:13 -06:00
|
|
|
let crate = util::ready_crate(sess, self.crate);
|
2013-04-11 19:43:02 -05:00
|
|
|
debug!("Building output filenames with script name %s",
|
2013-04-18 16:56:41 -05:00
|
|
|
driver::source_name(&self.input));
|
2013-04-11 19:43:02 -05:00
|
|
|
match filesearch::get_rustpkg_sysroot() {
|
|
|
|
Ok(r) => {
|
|
|
|
let root = r.pop().pop().pop().pop(); // :-\
|
|
|
|
debug!("Root is %s, calling compile_rest", root.to_str());
|
|
|
|
let exe = self.build_dir.push(~"pkg" + util::exe_suffix());
|
2013-05-27 19:45:16 -05:00
|
|
|
let binary = @copy os::args()[0];
|
|
|
|
util::compile_crate_from_input(&self.input,
|
|
|
|
&self.build_dir,
|
|
|
|
sess,
|
|
|
|
crate,
|
|
|
|
driver::build_configuration(sess,
|
|
|
|
binary, &self.input));
|
2013-04-11 19:43:02 -05:00
|
|
|
debug!("Running program: %s %s %s", exe.to_str(), root.to_str(), what);
|
2013-05-12 07:58:00 -05:00
|
|
|
let status = run::process_status(exe.to_str(), [root.to_str(), what]);
|
2013-04-11 19:43:02 -05:00
|
|
|
if status != 0 {
|
|
|
|
return (~[], status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
debug!("Running program (configs): %s %s %s",
|
2013-05-21 09:00:34 -05:00
|
|
|
exe.to_str(), root.to_str(), "configs");
|
2013-05-12 07:58:00 -05:00
|
|
|
let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]);
|
2013-04-11 19:43:02 -05:00
|
|
|
// Run the configs() function to get the configs
|
|
|
|
let mut cfgs = ~[];
|
2013-05-12 07:58:00 -05:00
|
|
|
for str::each_word(str::from_bytes(output.output)) |w| {
|
2013-04-11 19:43:02 -05:00
|
|
|
cfgs.push(w.to_owned());
|
|
|
|
}
|
|
|
|
(cfgs, output.status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
2013-05-09 06:52:07 -05:00
|
|
|
fail!("Running package script, couldn't find rustpkg sysroot (%s)", e)
|
2013-04-11 19:43:02 -05:00
|
|
|
}
|
|
|
|
}
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 19:12:31 -06:00
|
|
|
fn hash(&self) -> ~str {
|
2013-04-11 19:43:02 -05:00
|
|
|
self.id.hash()
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ctx {
|
2013-04-11 19:43:02 -05:00
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
fn run(&self, cmd: &str, args: ~[~str]) {
|
2013-01-17 03:05:19 -06:00
|
|
|
match cmd {
|
2013-05-27 19:45:16 -05:00
|
|
|
"build" => {
|
2013-03-07 16:54:23 -06:00
|
|
|
if args.len() < 1 {
|
|
|
|
return usage::build();
|
|
|
|
}
|
2013-04-11 19:43:02 -05:00
|
|
|
// The package id is presumed to be the first command-line
|
|
|
|
// argument
|
2013-05-11 21:45:13 -05:00
|
|
|
let pkgid = PkgId::new(copy args[0]);
|
|
|
|
for pkg_parent_workspaces(&pkgid) |workspace| {
|
|
|
|
self.build(workspace, &pkgid);
|
2013-04-17 15:53:34 -05:00
|
|
|
}
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"clean" => {
|
2013-04-17 17:47:24 -05:00
|
|
|
if args.len() < 1 {
|
|
|
|
return usage::build();
|
|
|
|
}
|
|
|
|
// The package id is presumed to be the first command-line
|
|
|
|
// argument
|
2013-05-11 21:45:13 -05:00
|
|
|
let pkgid = PkgId::new(copy args[0]);
|
2013-04-22 19:54:54 -05:00
|
|
|
let cwd = os::getcwd();
|
2013-05-11 21:45:13 -05:00
|
|
|
self.clean(&cwd, &pkgid); // tjc: should use workspace, not cwd
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"do" => {
|
2013-04-11 19:43:02 -05:00
|
|
|
if args.len() < 2 {
|
2013-01-22 20:41:11 -06:00
|
|
|
return usage::do_cmd();
|
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:13 -05:00
|
|
|
self.do_cmd(copy args[0], copy args[1]);
|
2013-01-22 20:41:11 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"info" => {
|
2013-01-26 02:35:10 -06:00
|
|
|
self.info();
|
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"install" => {
|
2013-04-24 19:37:59 -05:00
|
|
|
if args.len() < 1 {
|
|
|
|
return usage::install();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The package id is presumed to be the first command-line
|
|
|
|
// argument
|
|
|
|
let pkgid = PkgId::new(args[0]);
|
2013-05-11 21:45:13 -05:00
|
|
|
for pkg_parent_workspaces(&pkgid) |workspace| {
|
|
|
|
self.install(workspace, &pkgid);
|
2013-04-24 19:37:59 -05:00
|
|
|
}
|
2013-01-18 02:31:43 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"prefer" => {
|
2013-01-18 02:31:43 -06:00
|
|
|
if args.len() < 1 {
|
|
|
|
return usage::uninstall();
|
|
|
|
}
|
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
self.prefer(args[0], None);
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"test" => {
|
2013-01-22 19:19:13 -06:00
|
|
|
self.test();
|
2013-01-18 02:31:43 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"uninstall" => {
|
2013-01-18 02:31:43 -06:00
|
|
|
if args.len() < 1 {
|
|
|
|
return usage::uninstall();
|
|
|
|
}
|
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
self.uninstall(args[0], None);
|
2013-01-18 02:31:43 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
"unprefer" => {
|
2013-01-18 02:31:43 -06:00
|
|
|
if args.len() < 1 {
|
|
|
|
return usage::uninstall();
|
|
|
|
}
|
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
self.unprefer(args[0], None);
|
2013-01-18 02:31:43 -06:00
|
|
|
}
|
2013-05-14 19:46:52 -05:00
|
|
|
_ => fail!(fmt!("I don't know the command `%s`", cmd))
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:13 -05:00
|
|
|
fn do_cmd(&self, _cmd: &str, _pkgname: &str) {
|
2013-04-22 19:54:54 -05:00
|
|
|
// stub
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("`do` not yet implemented");
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:13 -05:00
|
|
|
fn build(&self, workspace: &Path, pkgid: &PkgId) {
|
2013-05-27 19:45:16 -05:00
|
|
|
let src_dir = first_pkgid_src_in_workspace(pkgid, workspace);
|
2013-05-02 15:09:28 -05:00
|
|
|
let build_dir = build_pkg_id_in_workspace(pkgid, workspace);
|
|
|
|
debug!("Destination dir = %s", build_dir.to_str());
|
|
|
|
|
|
|
|
// Create the package source
|
2013-05-14 19:46:52 -05:00
|
|
|
let mut src = PkgSrc::new(workspace, &build_dir, pkgid);
|
2013-05-02 15:09:28 -05:00
|
|
|
debug!("Package src = %?", src);
|
|
|
|
|
|
|
|
// Is there custom build logic? If so, use it
|
|
|
|
let pkg_src_dir = src_dir;
|
|
|
|
let mut custom = false;
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("Package source directory = %?", pkg_src_dir);
|
|
|
|
let cfgs = match pkg_src_dir.chain_ref(|p| src.package_script_option(p)) {
|
2013-05-02 15:09:28 -05:00
|
|
|
Some(package_script_path) => {
|
|
|
|
let pscript = PkgScript::parse(package_script_path,
|
|
|
|
workspace,
|
|
|
|
pkgid);
|
|
|
|
// Limited right now -- we're only running the post_build
|
|
|
|
// hook and probably fail otherwise
|
|
|
|
// also post_build should be called pre_build
|
|
|
|
let (cfgs, hook_result) = pscript.run_custom(~"post_build");
|
|
|
|
debug!("Command return code = %?", hook_result);
|
|
|
|
if hook_result != 0 {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("Error running custom build command")
|
2013-05-02 15:09:28 -05:00
|
|
|
}
|
|
|
|
custom = true;
|
|
|
|
// otherwise, the package script succeeded
|
|
|
|
cfgs
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
debug!("No package script, continuing");
|
|
|
|
~[]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// If there was a package script, it should have finished
|
|
|
|
// the build already. Otherwise...
|
|
|
|
if !custom {
|
|
|
|
// Find crates inside the workspace
|
|
|
|
src.find_crates();
|
|
|
|
// Build it!
|
2013-05-27 19:45:16 -05:00
|
|
|
src.build(self, build_dir, cfgs);
|
2013-05-02 15:09:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:13 -05:00
|
|
|
fn clean(&self, workspace: &Path, id: &PkgId) {
|
2013-04-17 17:47:24 -05:00
|
|
|
// Could also support a custom build hook in the pkg
|
|
|
|
// script for cleaning files rustpkg doesn't know about.
|
|
|
|
// Do something reasonable for now
|
|
|
|
|
2013-04-22 19:54:54 -05:00
|
|
|
let dir = build_pkg_id_in_workspace(id, workspace);
|
2013-04-17 17:47:24 -05:00
|
|
|
util::note(fmt!("Cleaning package %s (removing directory %s)",
|
|
|
|
id.to_str(), dir.to_str()));
|
|
|
|
if os::path_exists(&dir) {
|
2013-05-14 19:46:52 -05:00
|
|
|
os::remove_dir_recursive(&dir);
|
2013-04-17 17:47:24 -05:00
|
|
|
util::note(fmt!("Removed directory %s", dir.to_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
util::note(fmt!("Cleaned package %s", id.to_str()));
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 19:12:31 -06:00
|
|
|
fn info(&self) {
|
2013-04-11 19:43:02 -05:00
|
|
|
// stub
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("info not yet implemented");
|
2013-01-26 02:35:10 -06:00
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:13 -05:00
|
|
|
fn install(&self, workspace: &Path, id: &PkgId) {
|
2013-05-02 15:09:28 -05:00
|
|
|
use conditions::copy_failed::cond;
|
|
|
|
|
|
|
|
// Should use RUST_PATH in the future.
|
|
|
|
// Also should use workcache to not build if not necessary.
|
|
|
|
self.build(workspace, id);
|
2013-05-10 21:00:51 -05:00
|
|
|
debug!("install: workspace = %s, id = %s", workspace.to_str(),
|
|
|
|
id.to_str());
|
2013-05-02 15:09:28 -05:00
|
|
|
|
|
|
|
// Now copy stuff into the install dirs
|
|
|
|
let maybe_executable = built_executable_in_workspace(id, workspace);
|
|
|
|
let maybe_library = built_library_in_workspace(id, workspace);
|
|
|
|
let target_exec = target_executable_in_workspace(id, workspace);
|
2013-06-01 17:59:12 -05:00
|
|
|
let target_lib = maybe_library.map(|p| target_library_in_workspace(workspace, p));
|
2013-05-02 15:09:28 -05:00
|
|
|
|
2013-06-01 17:59:12 -05:00
|
|
|
debug!("target_exec = %s target_lib = %? \
|
2013-05-10 21:00:51 -05:00
|
|
|
maybe_executable = %? maybe_library = %?",
|
2013-06-01 17:59:12 -05:00
|
|
|
target_exec.to_str(), target_lib,
|
2013-05-10 21:00:51 -05:00
|
|
|
maybe_executable, maybe_library);
|
|
|
|
|
2013-05-02 15:09:28 -05:00
|
|
|
for maybe_executable.each |exec| {
|
|
|
|
debug!("Copying: %s -> %s", exec.to_str(), target_exec.to_str());
|
2013-05-10 21:00:51 -05:00
|
|
|
if !(os::mkdir_recursive(&target_exec.dir_path(), u_rwx) &&
|
|
|
|
os::copy_file(exec, &target_exec)) {
|
2013-05-14 19:46:52 -05:00
|
|
|
cond.raise((copy *exec, copy target_exec));
|
2013-05-02 15:09:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for maybe_library.each |lib| {
|
2013-06-01 17:59:12 -05:00
|
|
|
let target_lib = (copy target_lib).expect(fmt!("I built %s but apparently \
|
|
|
|
didn't install it!", lib.to_str()));
|
2013-05-02 15:09:28 -05:00
|
|
|
debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str());
|
2013-05-10 21:00:51 -05:00
|
|
|
if !(os::mkdir_recursive(&target_lib.dir_path(), u_rwx) &&
|
|
|
|
os::copy_file(lib, &target_lib)) {
|
2013-05-14 19:46:52 -05:00
|
|
|
cond.raise((copy *lib, copy target_lib));
|
2013-01-18 02:31:43 -06:00
|
|
|
}
|
|
|
|
}
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
fn prefer(&self, _id: &str, _vers: Option<~str>) {
|
2013-05-27 19:45:16 -05:00
|
|
|
fail!("prefer not yet implemented");
|
2013-01-17 03:05:19 -06:00
|
|
|
}
|
2013-01-16 05:59:37 -06:00
|
|
|
|
2013-04-17 17:47:24 -05:00
|
|
|
fn test(&self) {
|
|
|
|
// stub
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("test not yet implemented");
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
fn uninstall(&self, _id: &str, _vers: Option<~str>) {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("uninstall not yet implemented");
|
2013-01-17 03:05:19 -06:00
|
|
|
}
|
2013-01-16 05:59:37 -06:00
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
fn unprefer(&self, _id: &str, _vers: Option<~str>) {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("unprefer not yet implemented");
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
}
|
2013-01-15 07:57:03 -06:00
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
|
2013-01-14 04:55:47 -06:00
|
|
|
pub fn main() {
|
2013-04-11 19:43:02 -05:00
|
|
|
io::println("WARNING: The Rust package manager is experimental and may be unstable");
|
2013-03-20 13:44:01 -05:00
|
|
|
|
2013-01-15 07:57:03 -06:00
|
|
|
let args = os::args();
|
2013-05-21 09:00:34 -05:00
|
|
|
let opts = ~[getopts::optflag("h"), getopts::optflag("help"),
|
|
|
|
getopts::optflag("j"), getopts::optflag("json"),
|
|
|
|
getopts::optmulti("c"), getopts::optmulti("cfg")];
|
2013-01-15 07:57:03 -06:00
|
|
|
let matches = &match getopts::getopts(args, opts) {
|
|
|
|
result::Ok(m) => m,
|
|
|
|
result::Err(f) => {
|
2013-01-19 03:59:19 -06:00
|
|
|
util::error(fmt!("%s", getopts::fail_str(f)));
|
|
|
|
|
|
|
|
return;
|
2013-01-15 07:57:03 -06:00
|
|
|
}
|
|
|
|
};
|
2013-05-21 09:00:34 -05:00
|
|
|
let help = getopts::opt_present(matches, "h") ||
|
|
|
|
getopts::opt_present(matches, "help");
|
|
|
|
let json = getopts::opt_present(matches, "j") ||
|
|
|
|
getopts::opt_present(matches, "json");
|
2013-01-15 07:57:03 -06:00
|
|
|
let mut args = copy matches.free;
|
|
|
|
|
|
|
|
args.shift();
|
2013-01-14 04:55:47 -06:00
|
|
|
|
2013-01-15 07:57:03 -06:00
|
|
|
if (args.len() < 1) {
|
|
|
|
return usage::general();
|
|
|
|
}
|
|
|
|
|
2013-01-16 05:59:37 -06:00
|
|
|
let cmd = args.shift();
|
2013-01-15 07:57:03 -06:00
|
|
|
|
2013-01-16 05:59:37 -06:00
|
|
|
if !util::is_cmd(cmd) {
|
2013-01-15 07:57:03 -06:00
|
|
|
return usage::general();
|
|
|
|
} else if help {
|
2013-01-16 05:59:37 -06:00
|
|
|
return match cmd {
|
2013-01-15 07:57:03 -06:00
|
|
|
~"build" => usage::build(),
|
|
|
|
~"clean" => usage::clean(),
|
2013-01-22 20:41:11 -06:00
|
|
|
~"do" => usage::do_cmd(),
|
2013-01-26 02:35:10 -06:00
|
|
|
~"info" => usage::info(),
|
2013-01-15 07:57:03 -06:00
|
|
|
~"install" => usage::install(),
|
|
|
|
~"prefer" => usage::prefer(),
|
|
|
|
~"test" => usage::test(),
|
|
|
|
~"uninstall" => usage::uninstall(),
|
|
|
|
~"unprefer" => usage::unprefer(),
|
|
|
|
_ => usage::general()
|
2013-01-16 05:59:37 -06:00
|
|
|
};
|
2013-01-15 07:57:03 -06:00
|
|
|
}
|
|
|
|
|
2013-01-16 05:59:37 -06:00
|
|
|
Ctx {
|
2013-05-03 18:47:53 -05:00
|
|
|
sysroot_opt: None, // Currently, only tests override this
|
2013-01-26 02:35:10 -06:00
|
|
|
json: json,
|
2013-04-03 08:28:36 -05:00
|
|
|
dep_cache: @mut HashMap::new()
|
2013-01-17 03:05:19 -06:00
|
|
|
}.run(cmd, args);
|
2013-01-14 04:55:47 -06:00
|
|
|
}
|
2013-01-15 07:57:03 -06:00
|
|
|
|
2013-01-23 00:38:05 -06:00
|
|
|
/**
|
|
|
|
* Get the working directory of the package script.
|
|
|
|
* Assumes that the package script has been compiled
|
|
|
|
* in is the working directory.
|
|
|
|
*/
|
2013-01-26 02:35:10 -06:00
|
|
|
pub fn work_dir() -> Path {
|
2013-01-23 00:38:05 -06:00
|
|
|
os::self_exe_path().get()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the source directory of the package (i.e.
|
|
|
|
* where the crates are located). Assumes
|
|
|
|
* that the cwd is changed to it before
|
|
|
|
* running this executable.
|
|
|
|
*/
|
2013-01-26 02:35:10 -06:00
|
|
|
pub fn src_dir() -> Path {
|
2013-01-23 00:38:05 -06:00
|
|
|
os::getcwd()
|
|
|
|
}
|