2013-01-22 19:19:13 -06:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2013-06-30 21:36:55 -05:00
|
|
|
use std::{os, result};
|
2013-01-22 19:19:13 -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::groups::getopts;
|
2013-03-01 12:44:43 -06:00
|
|
|
use syntax::ast_util::*;
|
2013-05-27 19:45:16 -05:00
|
|
|
use syntax::codemap::{dummy_sp, spanned};
|
|
|
|
use syntax::codemap::dummy_spanned;
|
2013-05-17 06:27:17 -05:00
|
|
|
use syntax::ext::base::ExtCtxt;
|
2013-03-26 15:38:07 -05:00
|
|
|
use syntax::{ast, attr, codemap, diagnostic, fold};
|
2013-05-14 19:46:52 -05:00
|
|
|
use syntax::ast::{meta_name_value, meta_list};
|
2013-04-17 15:53:34 -05:00
|
|
|
use syntax::attr::{mk_attr};
|
2013-04-11 19:43:02 -05:00
|
|
|
use rustc::back::link::output_type_exe;
|
2013-05-27 19:45:16 -05:00
|
|
|
use rustc::driver::driver::compile_upto;
|
2013-05-10 21:00:51 -05:00
|
|
|
use rustc::driver::session::{lib_crate, bin_crate};
|
2013-05-27 19:45:16 -05:00
|
|
|
use context::Ctx;
|
|
|
|
use package_id::PkgId;
|
|
|
|
use search::find_library_in_search_path;
|
2013-06-14 20:16:24 -05:00
|
|
|
use path_util::target_library_in_workspace;
|
2013-05-27 19:45:16 -05:00
|
|
|
pub use target::{OutputType, Main, Lib, Bench, Test};
|
2013-02-04 19:12:31 -06:00
|
|
|
|
2013-06-30 22:51:13 -05:00
|
|
|
static COMMANDS: &'static [&'static str] =
|
2013-05-11 21:45:13 -05:00
|
|
|
&["build", "clean", "do", "info", "install", "prefer", "test", "uninstall",
|
|
|
|
"unprefer"];
|
|
|
|
|
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
pub type ExitCode = int; // For now
|
|
|
|
|
|
|
|
pub struct Pkg {
|
|
|
|
id: PkgId,
|
2013-01-19 03:59:19 -06:00
|
|
|
bins: ~[~str],
|
|
|
|
libs: ~[~str],
|
|
|
|
}
|
2013-01-16 05:59:37 -06:00
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
impl ToStr for Pkg {
|
|
|
|
fn to_str(&self) -> ~str {
|
|
|
|
self.id.to_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-16 05:59:37 -06:00
|
|
|
pub fn root() -> Path {
|
|
|
|
match filesearch::get_rustpkg_root() {
|
|
|
|
result::Ok(path) => path,
|
2013-02-04 19:12:31 -06:00
|
|
|
result::Err(err) => fail!(err)
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:13 -05:00
|
|
|
pub fn is_cmd(cmd: &str) -> bool {
|
2013-07-04 21:13:26 -05:00
|
|
|
COMMANDS.iter().any(|&c| c == cmd)
|
2013-01-15 07:57:03 -06:00
|
|
|
}
|
2013-01-16 05:59:37 -06:00
|
|
|
|
2013-01-22 19:19:13 -06:00
|
|
|
struct ListenerFn {
|
2013-01-22 20:41:11 -06:00
|
|
|
cmds: ~[~str],
|
2013-01-22 19:19:13 -06:00
|
|
|
span: codemap::span,
|
|
|
|
path: ~[ast::ident]
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ReadyCtx {
|
|
|
|
sess: session::Session,
|
|
|
|
crate: @ast::crate,
|
2013-05-17 06:27:17 -05:00
|
|
|
ext_cx: @ExtCtxt,
|
2013-02-21 20:41:33 -06:00
|
|
|
path: ~[ast::ident],
|
|
|
|
fns: ~[ListenerFn]
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn fold_mod(_ctx: @mut ReadyCtx,
|
|
|
|
m: &ast::_mod,
|
|
|
|
fold: @fold::ast_fold) -> ast::_mod {
|
2013-01-22 19:19:13 -06:00
|
|
|
fn strip_main(item: @ast::item) -> @ast::item {
|
|
|
|
@ast::item {
|
2013-07-01 21:38:19 -05:00
|
|
|
attrs: do item.attrs.iter().filter_map |attr| {
|
|
|
|
if "main" != attr::get_attr_name(attr) {Some(*attr)} else {None}
|
|
|
|
}.collect(),
|
2013-01-22 19:19:13 -06:00
|
|
|
.. copy *item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
fold::noop_fold_mod(&ast::_mod {
|
|
|
|
items: do m.items.map |item| {
|
2013-01-22 19:19:13 -06:00
|
|
|
strip_main(*item)
|
2013-02-04 19:12:31 -06:00
|
|
|
},
|
2013-02-18 00:20:36 -06:00
|
|
|
.. copy *m
|
2013-01-22 19:19:13 -06:00
|
|
|
}, fold)
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn fold_item(ctx: @mut ReadyCtx,
|
|
|
|
item: @ast::item,
|
|
|
|
fold: @fold::ast_fold) -> Option<@ast::item> {
|
2013-01-22 19:19:13 -06:00
|
|
|
ctx.path.push(item.ident);
|
|
|
|
|
2013-05-21 09:00:34 -05:00
|
|
|
let attrs = attr::find_attrs_by_name(item.attrs, "pkg_do");
|
2013-01-22 20:41:11 -06:00
|
|
|
|
|
|
|
if attrs.len() > 0 {
|
|
|
|
let mut cmds = ~[];
|
|
|
|
|
2013-06-21 07:29:53 -05:00
|
|
|
for attrs.iter().advance |attr| {
|
2013-01-22 20:41:11 -06:00
|
|
|
match attr.node.value.node {
|
2013-05-11 21:45:13 -05:00
|
|
|
ast::meta_list(_, ref mis) => {
|
2013-06-21 07:29:53 -05:00
|
|
|
for mis.iter().advance |mi| {
|
2013-01-22 20:41:11 -06:00
|
|
|
match mi.node {
|
2013-06-12 12:02:55 -05:00
|
|
|
ast::meta_word(cmd) => cmds.push(cmd.to_owned()),
|
2013-01-22 20:41:11 -06:00
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => cmds.push(~"build")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:19:13 -06:00
|
|
|
ctx.fns.push(ListenerFn {
|
2013-01-22 20:41:11 -06:00
|
|
|
cmds: cmds,
|
2013-01-22 19:19:13 -06:00
|
|
|
span: item.span,
|
|
|
|
path: /*bad*/copy ctx.path
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let res = fold::noop_fold_item(item, fold);
|
|
|
|
|
|
|
|
ctx.path.pop();
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate/filter main function, add the list of commands, etc.
|
|
|
|
pub fn ready_crate(sess: session::Session,
|
|
|
|
crate: @ast::crate) -> @ast::crate {
|
2013-02-21 20:41:33 -06:00
|
|
|
let ctx = @mut ReadyCtx {
|
2013-01-22 19:19:13 -06:00
|
|
|
sess: sess,
|
|
|
|
crate: crate,
|
2013-05-17 06:27:17 -05:00
|
|
|
ext_cx: ExtCtxt::new(sess.parse_sess, copy sess.opts.cfg),
|
2013-02-21 20:41:33 -06:00
|
|
|
path: ~[],
|
|
|
|
fns: ~[]
|
2013-01-22 19:19:13 -06:00
|
|
|
};
|
|
|
|
let precursor = @fold::AstFoldFns {
|
2013-02-04 19:12:31 -06:00
|
|
|
// fold_crate: fold::wrap(|a, b| fold_crate(ctx, a, b)),
|
2013-01-22 19:19:13 -06:00
|
|
|
fold_item: |a, b| fold_item(ctx, a, b),
|
|
|
|
fold_mod: |a, b| fold_mod(ctx, a, b),
|
|
|
|
.. *fold::default_ast_fold()
|
|
|
|
};
|
|
|
|
|
|
|
|
let fold = fold::make_fold(precursor);
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
@fold.fold_crate(crate)
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
|
|
|
|
2013-01-17 03:05:19 -06:00
|
|
|
pub fn need_dir(s: &Path) {
|
|
|
|
if !os::path_is_dir(s) && !os::make_dir(s, 493_i32) {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("can't create dir: %s", s.to_str());
|
2013-01-17 03:05:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
// FIXME (#4432): Use workcache to only compile when needed
|
2013-05-27 19:45:16 -05:00
|
|
|
pub fn compile_input(ctxt: &Ctx,
|
2013-05-11 21:45:13 -05:00
|
|
|
pkg_id: &PkgId,
|
2013-03-07 16:54:23 -06:00
|
|
|
in_file: &Path,
|
|
|
|
out_dir: &Path,
|
2013-05-11 21:45:13 -05:00
|
|
|
flags: &[~str],
|
|
|
|
cfgs: &[~str],
|
2013-03-07 16:54:23 -06:00
|
|
|
opt: bool,
|
2013-05-10 21:00:51 -05:00
|
|
|
what: OutputType) -> bool {
|
2013-04-17 15:53:34 -05:00
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
let workspace = out_dir.pop().pop();
|
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
assert!(in_file.components.len() > 1);
|
2013-03-07 16:54:23 -06:00
|
|
|
let input = driver::file_input(copy *in_file);
|
2013-05-10 21:00:51 -05:00
|
|
|
debug!("compile_input: %s / %?", in_file.to_str(), what);
|
2013-04-11 19:43:02 -05:00
|
|
|
// tjc: by default, use the package ID name as the link name
|
|
|
|
// not sure if we should support anything else
|
2013-01-19 03:59:19 -06:00
|
|
|
|
2013-06-12 12:02:55 -05:00
|
|
|
let binary = os::args()[0].to_managed();
|
2013-01-19 03:59:19 -06:00
|
|
|
|
2013-06-10 08:25:25 -05:00
|
|
|
debug!("flags: %s", flags.connect(" "));
|
|
|
|
debug!("cfgs: %s", cfgs.connect(" "));
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("compile_input's sysroot = %?", ctxt.sysroot_opt);
|
2013-04-17 15:53:34 -05:00
|
|
|
|
2013-05-10 21:00:51 -05:00
|
|
|
let crate_type = match what {
|
|
|
|
Lib => lib_crate,
|
|
|
|
Test | Bench | Main => bin_crate
|
|
|
|
};
|
2013-06-27 18:27:13 -05:00
|
|
|
let matches = getopts(debug_flags()
|
2013-05-10 21:00:51 -05:00
|
|
|
+ match what {
|
|
|
|
Lib => ~[~"--lib"],
|
|
|
|
// --test compiles both #[test] and #[bench] fns
|
|
|
|
Test | Bench => ~[~"--test"],
|
|
|
|
Main => ~[]
|
|
|
|
}
|
2013-04-11 19:43:02 -05:00
|
|
|
+ flags
|
2013-06-21 05:31:11 -05:00
|
|
|
+ cfgs.flat_map(|c| { ~[~"--cfg", copy *c] }),
|
2013-04-11 19:43:02 -05:00
|
|
|
driver::optgroups()).get();
|
2013-05-27 19:45:16 -05:00
|
|
|
let options = @session::options {
|
2013-04-17 15:53:34 -05:00
|
|
|
crate_type: crate_type,
|
2013-01-23 00:38:05 -06:00
|
|
|
optimize: if opt { session::Aggressive } else { session::No },
|
2013-05-10 21:00:51 -05:00
|
|
|
test: what == Test || what == Bench,
|
2013-05-27 19:45:16 -05:00
|
|
|
maybe_sysroot: ctxt.sysroot_opt,
|
2013-06-14 20:16:24 -05:00
|
|
|
addl_lib_search_paths: @mut (~[copy *out_dir]),
|
2013-05-11 21:45:13 -05:00
|
|
|
// output_type should be conditional
|
|
|
|
output_type: output_type_exe, // Use this to get a library? That's weird
|
|
|
|
.. copy *driver::build_session_options(binary, &matches, diagnostic::emit)
|
2013-01-23 00:38:05 -06:00
|
|
|
};
|
2013-01-22 21:29:47 -06:00
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
let addl_lib_search_paths = @mut options.addl_lib_search_paths;
|
2013-06-14 20:16:24 -05:00
|
|
|
// Make sure all the library directories actually exist, since the linker will complain
|
|
|
|
// otherwise
|
2013-06-21 07:29:53 -05:00
|
|
|
for addl_lib_search_paths.iter().advance |p| {
|
2013-06-14 20:16:24 -05:00
|
|
|
assert!(os::path_is_dir(p));
|
|
|
|
}
|
2013-01-22 21:29:47 -06:00
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
let sess = driver::build_session(options, diagnostic::emit);
|
|
|
|
|
|
|
|
// Infer dependencies that rustpkg needs to build, by scanning for
|
|
|
|
// `extern mod` directives.
|
|
|
|
let cfg = driver::build_configuration(sess, binary, &input);
|
|
|
|
let (crate_opt, _) = driver::compile_upto(sess, copy cfg, &input, driver::cu_expand, None);
|
|
|
|
|
|
|
|
let mut crate = match crate_opt {
|
|
|
|
Some(c) => c,
|
|
|
|
None => fail!("compile_input expected...")
|
|
|
|
};
|
|
|
|
|
|
|
|
// Not really right. Should search other workspaces too, and the installed
|
|
|
|
// database (which doesn't exist yet)
|
|
|
|
find_and_install_dependencies(ctxt, sess, &workspace, crate,
|
|
|
|
|p| {
|
|
|
|
debug!("a dependency: %s", p.to_str());
|
|
|
|
// Pass the directory containing a dependency
|
|
|
|
// as an additional lib search path
|
|
|
|
addl_lib_search_paths.push(p);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Inject the link attributes so we get the right package name and version
|
|
|
|
if attr::find_linkage_metas(crate.node.attrs).is_empty() {
|
|
|
|
let short_name_to_use = match what {
|
|
|
|
Test => fmt!("%stest", pkg_id.short_name),
|
|
|
|
Bench => fmt!("%sbench", pkg_id.short_name),
|
|
|
|
_ => copy pkg_id.short_name
|
|
|
|
};
|
|
|
|
debug!("Injecting link name: %s", short_name_to_use);
|
|
|
|
crate = @codemap::respan(crate.span, ast::crate_ {
|
|
|
|
attrs: ~[mk_attr(@dummy_spanned(
|
2013-06-12 12:02:55 -05:00
|
|
|
meta_list(@"link",
|
|
|
|
~[@dummy_spanned(meta_name_value(@"name",
|
|
|
|
mk_string_lit(short_name_to_use.to_managed()))),
|
|
|
|
@dummy_spanned(meta_name_value(@"vers",
|
2013-06-14 20:16:24 -05:00
|
|
|
mk_string_lit(pkg_id.version.to_str().to_managed())))])))],
|
2013-05-27 19:45:16 -05:00
|
|
|
..copy crate.node});
|
|
|
|
}
|
2013-01-22 19:19:13 -06:00
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
debug!("calling compile_crate_from_input, out_dir = %s,
|
|
|
|
building_library = %?", out_dir.to_str(), sess.building_library);
|
2013-06-26 00:26:22 -05:00
|
|
|
compile_crate_from_input(&input, out_dir, sess, crate, copy cfg, driver::cu_expand);
|
2013-04-11 19:43:02 -05:00
|
|
|
true
|
|
|
|
}
|
2013-01-22 19:19:13 -06:00
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
// Should use workcache to avoid recompiling when not necessary
|
|
|
|
// Should also rename this to something better
|
|
|
|
// If crate_opt is present, then finish compilation. If it's None, then
|
|
|
|
// call compile_upto and return the crate
|
2013-04-17 15:53:34 -05:00
|
|
|
// also, too many arguments
|
2013-05-11 21:45:13 -05:00
|
|
|
pub fn compile_crate_from_input(input: &driver::input,
|
2013-05-27 19:45:16 -05:00
|
|
|
build_dir: &Path,
|
2013-04-17 15:53:34 -05:00
|
|
|
sess: session::Session,
|
2013-05-27 19:45:16 -05:00
|
|
|
crate: @ast::crate,
|
2013-06-26 00:26:22 -05:00
|
|
|
cfg: ast::crate_cfg,
|
|
|
|
compile_from: driver::compile_phase) {
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("Calling build_output_filenames with %s, building library? %?",
|
|
|
|
build_dir.to_str(), sess.building_library);
|
2013-04-17 15:53:34 -05:00
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
// bad copy
|
|
|
|
let outputs = driver::build_output_filenames(input, &Some(copy *build_dir), &None,
|
|
|
|
crate.node.attrs, sess);
|
|
|
|
|
|
|
|
debug!("Outputs are %? and output type = %?", outputs, sess.opts.output_type);
|
|
|
|
debug!("additional libraries:");
|
2013-06-21 07:29:53 -05:00
|
|
|
for sess.opts.addl_lib_search_paths.iter().advance |lib| {
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("an additional library: %s", lib.to_str());
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
|
|
|
|
driver::compile_rest(sess,
|
|
|
|
cfg,
|
|
|
|
compile_upto {
|
2013-06-26 00:26:22 -05:00
|
|
|
from: compile_from,
|
2013-05-27 19:45:16 -05:00
|
|
|
to: driver::cu_everything
|
|
|
|
},
|
|
|
|
Some(outputs),
|
|
|
|
Some(crate));
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
pub fn exe_suffix() -> ~str { ~".exe" }
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[cfg(target_os = "android")]
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
pub fn exe_suffix() -> ~str { ~"" }
|
|
|
|
|
2013-04-11 19:43:02 -05:00
|
|
|
// Called by build_crates
|
2013-01-23 03:25:03 -06:00
|
|
|
// FIXME (#4432): Use workcache to only compile when needed
|
2013-05-27 19:45:16 -05:00
|
|
|
pub fn compile_crate(ctxt: &Ctx, pkg_id: &PkgId,
|
2013-04-17 15:53:34 -05:00
|
|
|
crate: &Path, dir: &Path,
|
2013-05-11 21:45:13 -05:00
|
|
|
flags: &[~str], cfgs: &[~str], opt: bool,
|
2013-05-10 21:00:51 -05:00
|
|
|
what: OutputType) -> bool {
|
2013-04-11 19:43:02 -05:00
|
|
|
debug!("compile_crate: crate=%s, dir=%s", crate.to_str(), dir.to_str());
|
2013-04-17 15:53:34 -05:00
|
|
|
debug!("compile_crate: short_name = %s, flags =...", pkg_id.to_str());
|
2013-06-21 05:31:11 -05:00
|
|
|
for flags.iter().advance |fl| {
|
|
|
|
debug!("+++ %s", *fl);
|
2013-04-11 19:43:02 -05:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
compile_input(ctxt, pkg_id, crate, dir, flags, cfgs, opt, what)
|
2013-05-10 21:00:51 -05:00
|
|
|
}
|
|
|
|
|
2013-06-14 20:16:24 -05:00
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
/// Collect all `extern mod` directives in `c`, then
|
|
|
|
/// try to install their targets, failing if any target
|
|
|
|
/// can't be found.
|
2013-06-14 20:16:24 -05:00
|
|
|
pub fn find_and_install_dependencies(ctxt: &Ctx,
|
2013-05-27 19:45:16 -05:00
|
|
|
sess: session::Session,
|
|
|
|
workspace: &Path,
|
|
|
|
c: &ast::crate,
|
|
|
|
save: @fn(Path)
|
|
|
|
) {
|
|
|
|
// :-(
|
|
|
|
debug!("In find_and_install_dependencies...");
|
|
|
|
let my_workspace = copy *workspace;
|
|
|
|
let my_ctxt = copy *ctxt;
|
2013-06-27 08:04:22 -05:00
|
|
|
for c.each_view_item() |vi: &ast::view_item| {
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("A view item!");
|
|
|
|
match vi.node {
|
|
|
|
// ignore metadata, I guess
|
|
|
|
ast::view_item_extern_mod(lib_ident, _, _) => {
|
|
|
|
match my_ctxt.sysroot_opt {
|
|
|
|
Some(ref x) => debug!("sysroot: %s", x.to_str()),
|
2013-06-14 20:16:24 -05:00
|
|
|
None => debug!("No sysroot given")
|
2013-05-27 19:45:16 -05:00
|
|
|
};
|
|
|
|
let lib_name = sess.str_of(lib_ident);
|
2013-06-12 12:02:55 -05:00
|
|
|
match find_library_in_search_path(my_ctxt.sysroot_opt, lib_name) {
|
2013-05-27 19:45:16 -05:00
|
|
|
Some(installed_path) => {
|
|
|
|
debug!("It exists: %s", installed_path.to_str());
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
// Try to install it
|
2013-06-12 12:02:55 -05:00
|
|
|
let pkg_id = PkgId::new(lib_name);
|
2013-05-27 19:45:16 -05:00
|
|
|
my_ctxt.install(&my_workspace, &pkg_id);
|
|
|
|
// Also, add an additional search path
|
2013-06-14 20:16:24 -05:00
|
|
|
debug!("let installed_path...")
|
|
|
|
let installed_path = target_library_in_workspace(&pkg_id,
|
|
|
|
&my_workspace).pop();
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("Great, I installed %s, and it's in %s",
|
2013-06-12 12:02:55 -05:00
|
|
|
lib_name, installed_path.to_str());
|
2013-05-27 19:45:16 -05:00
|
|
|
save(installed_path);
|
|
|
|
}
|
|
|
|
}
|
2013-05-10 21:00:51 -05:00
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
// Ignore `use`s
|
|
|
|
_ => ()
|
2013-05-10 21:00:51 -05:00
|
|
|
}
|
|
|
|
}
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
|
|
|
|
2013-01-19 03:59:19 -06:00
|
|
|
#[cfg(windows)]
|
2013-01-23 00:38:05 -06:00
|
|
|
pub fn link_exe(_src: &Path, _dest: &Path) -> bool {
|
2013-01-23 03:25:03 -06:00
|
|
|
/* FIXME (#1768): Investigate how to do this on win32
|
2013-01-19 03:59:19 -06:00
|
|
|
Node wraps symlinks by having a .bat,
|
|
|
|
but that won't work with minGW. */
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[cfg(target_os = "android")]
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
#[cfg(target_os = "macos")]
|
2013-02-04 19:12:31 -06:00
|
|
|
pub fn link_exe(src: &Path, dest: &Path) -> bool {
|
2013-06-30 21:36:55 -05:00
|
|
|
use std::{libc, str};
|
2013-02-04 19:12:31 -06:00
|
|
|
unsafe {
|
|
|
|
do str::as_c_str(src.to_str()) |src_buf| {
|
|
|
|
do str::as_c_str(dest.to_str()) |dest_buf| {
|
|
|
|
libc::link(src_buf, dest_buf) == 0 as libc::c_int &&
|
|
|
|
libc::chmod(dest_buf, 755) == 0 as libc::c_int
|
|
|
|
}
|
2013-01-19 03:59:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 12:02:55 -05:00
|
|
|
pub fn mk_string_lit(s: @str) -> ast::lit {
|
2013-04-17 15:53:34 -05:00
|
|
|
spanned {
|
|
|
|
node: ast::lit_str(s),
|
|
|
|
span: dummy_sp()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 18:15:40 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2013-05-14 19:46:52 -05:00
|
|
|
use super::is_cmd;
|
2013-04-12 18:15:40 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_is_cmd() {
|
2013-05-27 18:04:00 -05:00
|
|
|
assert!(is_cmd("build"));
|
|
|
|
assert!(is_cmd("clean"));
|
|
|
|
assert!(is_cmd("do"));
|
|
|
|
assert!(is_cmd("info"));
|
|
|
|
assert!(is_cmd("install"));
|
|
|
|
assert!(is_cmd("prefer"));
|
|
|
|
assert!(is_cmd("test"));
|
|
|
|
assert!(is_cmd("uninstall"));
|
|
|
|
assert!(is_cmd("unprefer"));
|
2013-04-12 18:15:40 -05:00
|
|
|
}
|
2013-04-15 13:52:10 -05:00
|
|
|
|
2013-01-16 05:59:37 -06:00
|
|
|
}
|
2013-06-27 18:27:13 -05:00
|
|
|
|
|
|
|
// tjc: cheesy
|
|
|
|
fn debug_flags() -> ~[~str] { ~[] }
|
2013-06-30 22:51:13 -05:00
|
|
|
// static DEBUG_FLAGS: ~[~str] = ~[~"-Z", ~"time-passes"];
|