use extra::arc::{Arc,RWArc};
use extra::workcache;
-use extra::workcache::*;
-use std::os;
+use extra::workcache::{Database, Logger, FreshnessMap};
use extra::treemap::TreeMap;
/// Convenience functions intended for calling from pkg.rs
/// p is where to put the cache file for dependencies
-pub fn default_ctxt(p: Path) -> BuildCtx {
- new_default_ctx(new_workcache_cx(&p), p)
+pub fn default_context(p: Path) -> BuildContext {
+ new_default_context(new_workcache_context(&p), p)
}
-pub fn new_default_ctx(c: Context, p: Path) -> BuildCtx {
- BuildCtx {
- cx: Ctx { use_rust_path_hack: false,
- sysroot_opt: p },
- workcache_cx: c
+pub fn new_default_context(c: workcache::Context, p: Path) -> BuildContext {
+ BuildContext {
+ context: Context {
+ use_rust_path_hack: false,
+ sysroot: p
+ },
+ workcache_context: c
}
}
}
-pub fn new_workcache_cx(p: &Path) -> Context {
+pub fn new_workcache_context(p: &Path) -> workcache::Context {
let db_file = p.push("rustpkg_db.json"); // ??? probably wrong
debug!("Workcache database file: %s", db_file.to_str());
let db = RWArc::new(Database::new(db_file));
let lg = RWArc::new(Logger::new());
let cfg = Arc::new(TreeMap::new());
- let mut rslt: FreshnessMap = TreeMap::new();
+ let mut freshness: FreshnessMap = TreeMap::new();
// Set up freshness functions for every type of dependency rustpkg
// knows about
- rslt.insert(~"file", file_is_fresh);
- rslt.insert(~"binary", binary_is_fresh);
- workcache::Context::new_with_freshness(db, lg, cfg, Arc::new(rslt))
+ freshness.insert(~"file", file_is_fresh);
+ freshness.insert(~"binary", binary_is_fresh);
+ workcache::Context::new_with_freshness(db, lg, cfg, Arc::new(freshness))
}
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
lib: Path) {
- let cx = default_ctxt(sysroot);
+ let cx = default_context(sysroot);
let subroot = root.clone();
let subversion = version.clone();
let sublib = lib.clone();
- do cx.workcache_cx.with_prep(name) |prep| {
+ do cx.workcache_context.with_prep(name) |prep| {
let pkg_src = PkgSrc {
workspace: subroot.clone(),
start_dir: subroot.push("src").push(name),
let subcx = cx.clone();
let subsrc = pkg_src.clone();
do prep.exec |exec| {
- subsrc.clone().build(exec, &subcx.clone(), ~[]);
+ subsrc.build(exec, &subcx.clone(), ~[]);
}
};
}
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
main: Path) {
- let cx = default_ctxt(sysroot);
+ let cx = default_context(sysroot);
let subroot = root.clone();
let submain = main.clone();
- do cx.workcache_cx.with_prep(name) |prep| {
+ do cx.workcache_context.with_prep(name) |prep| {
let pkg_src = PkgSrc {
workspace: subroot.clone(),
start_dir: subroot.push("src").push(name),
}
}
-pub fn install_lib(sysroot: Path,
- workspace: Path,
- name: ~str,
- lib_path: Path,
- version: Version) {
- debug!("self_exe: %?", os::self_exe_path());
- debug!("sysroot = %s", sysroot.to_str());
- debug!("workspace = %s", workspace.to_str());
- // make a PkgSrc
- let pkg_id = PkgId{ version: version, ..PkgId::new(name)};
- let cx = default_ctxt(sysroot);
- let subpath = lib_path.clone();
- do cx.workcache_cx.with_prep(pkg_id.to_str()) |prep| {
- let pkg_src = PkgSrc {
- workspace: workspace.clone(),
- start_dir: subpath.push("src").push(name),
- id: pkg_id.clone(),
- libs: ~[mk_crate(subpath.clone())],
- mains: ~[],
- tests: ~[],
- benchs: ~[]
- };
- pkg_src.declare_inputs(prep);
- let subcx = cx.clone();
- let subpkg_src = pkg_src.clone();
- do prep.exec |exec| {
- subpkg_src.clone().build(exec, &subcx.clone(), ~[]);
- }
- }
- cx.install_no_build(&workspace, &pkg_id);
-}
-
-pub fn install_exe(sysroot: Path, workspace: Path, name: ~str, version: Version) {
- let cx = default_ctxt(sysroot);
- debug!("install_exe calling with_prep");
+pub fn install_pkg(sysroot: Path, workspace: Path, name: ~str, version: Version) {
+ let cx = default_context(sysroot);
let pkgid = PkgId{ version: version, ..PkgId::new(name)};
cx.install(PkgSrc::new(workspace, false, pkgid));
}
use extra::workcache;
#[deriving(Clone)]
-pub struct Ctx {
+pub struct Context {
// If use_rust_path_hack is true, rustpkg searches for sources
// in *package* directories that are in the RUST_PATH (for example,
// FOO/src/bar-0.1 instead of FOO). The flag doesn't affect where
// rustpkg stores build artifacts.
use_rust_path_hack: bool,
// The root directory containing the Rust standard libraries
- sysroot_opt: Path
+ sysroot: Path
}
#[deriving(Clone)]
-pub struct BuildCtx {
+pub struct BuildContext {
// Context for workcache
- workcache_cx: workcache::Context,
+ workcache_context: workcache::Context,
// Everything else
- cx: Ctx
+ context: Context
}
-impl BuildCtx {
- pub fn sysroot_opt(&self) -> Path {
- self.cx.sysroot_opt.clone()
+impl BuildContext {
+ pub fn sysroot(&self) -> Path {
+ self.context.sysroot.clone()
}
pub fn sysroot_to_use(&self) -> Path {
- self.cx.sysroot_to_use()
+ self.context.sysroot_to_use()
}
}
-impl Ctx {
- pub fn sysroot_opt(&self) -> Path {
- self.sysroot_opt.clone()
+impl Context {
+ pub fn sysroot(&self) -> Path {
+ self.sysroot.clone()
}
}
-impl Ctx {
+impl Context {
/// Debugging
- pub fn sysroot_opt_str(&self) -> ~str {
- self.sysroot_opt.to_str()
+ pub fn sysroot_str(&self) -> ~str {
+ self.sysroot.to_str()
}
// Hack so that rustpkg can run either out of a rustc target dir,
// or the host dir
pub fn sysroot_to_use(&self) -> Path {
- if !in_target(&self.sysroot_opt) {
- self.sysroot_opt.clone()
+ if !in_target(&self.sysroot) {
+ self.sysroot.clone()
+ } else {
+ self.sysroot.pop().pop().pop()
}
- else {
- self.sysroot_opt.pop().pop().pop()
- }
- }
+ }
}
/// We assume that if ../../rustc exists, then we're running
/// rustpkg from a Rust target directory. This is part of a
/// kludgy hack used to adjust the sysroot.
-pub fn in_target(sysroot_opt: &Path) -> bool {
- debug!("Checking whether %s is in target", sysroot_opt.to_str());
- os::path_is_dir(&sysroot_opt.pop().pop().push("rustc"))
+pub fn in_target(sysroot: &Path) -> bool {
+ debug!("Checking whether %s is in target", sysroot.to_str());
+ os::path_is_dir(&sysroot.pop().pop().push("rustc"))
}
// This contains a list of files found in the source workspace.
#[deriving(Clone)]
pub struct PkgSrc {
- workspace: Path, // root of where the package source code lives
- start_dir: Path, // dir to start looking in for packages -- normally
- // this is workspace/src/id but it may be just workspace
+ /// Root of where the package source code lives
+ workspace: Path,
+ // Directory to start looking in for packages -- normally
+ // this is workspace/src/id but it may be just workspace
+ start_dir: Path,
id: PkgId,
libs: ~[Crate],
mains: ~[Crate],
let mut to_try = ~[];
if use_rust_path_hack {
to_try.push(workspace.clone());
- }
- else {
+ } else {
let result = workspace.push("src").push_rel(&id.path.pop()).push(fmt!("%s-%s",
id.short_name, id.version.to_str()));
to_try.push(result);
}
fn build_crates(&self,
- ctx: &BuildCtx,
+ ctx: &BuildContext,
exec: &mut workcache::Exec,
destination_dir: &Path,
crates: &[Crate],
let path_str = path.to_str();
let cfgs = crate.cfgs + cfgs;
- let result = {
+ let result =
// compile_crate should return the path of the output artifact
- match compile_crate(ctx,
- exec,
- &self.id,
- &path,
- destination_dir,
- crate.flags,
- cfgs,
- false,
- what).map(|p| p.to_str()) {
- Some(p) => p,
- None => build_err::cond.raise(fmt!("build failure on %s",
- path_str))
-
- }
- };
+ compile_crate(ctx,
+ exec,
+ &self.id,
+ &path,
+ destination_dir,
+ crate.flags,
+ cfgs,
+ false,
+ what).to_str();
debug!("Result of compiling %s was %s", path_str, result);
}
}
// It would be better if build returned a Path, but then Path would have to derive
// Encodable.
- pub fn build(&self, exec: &mut workcache::Exec, ctx: &BuildCtx, cfgs: ~[~str]) -> ~str {
+ pub fn build(&self,
+ exec: &mut workcache::Exec,
+ build_context: &BuildContext,
+ cfgs: ~[~str]) -> ~str {
use conditions::not_a_workspace::cond;
// Determine the destination workspace (which depends on whether
let destination_workspace = if is_workspace(&self.workspace) {
debug!("%s is indeed a workspace", self.workspace.to_str());
self.workspace.clone()
- }
- else {
+ } else {
// It would be nice to have only one place in the code that checks
// for the use_rust_path_hack flag...
- if ctx.cx.use_rust_path_hack {
+ if build_context.context.use_rust_path_hack {
let rs = default_workspace();
debug!("Using hack: %s", rs.to_str());
rs
- }
- else {
+ } else {
cond.raise(fmt!("Package root %s is not a workspace; pass in --rust_path_hack \
if you want to treat it as a package source",
self.workspace.to_str()))
let benchs = self.benchs.clone();
debug!("Building libs in %s, destination = %s",
destination_workspace.to_str(), destination_workspace.to_str());
- self.build_crates(ctx, exec, &destination_workspace, libs, cfgs, Lib);
+ self.build_crates(build_context, exec, &destination_workspace, libs, cfgs, Lib);
debug!("Building mains");
- self.build_crates(ctx, exec, &destination_workspace, mains, cfgs, Main);
+ self.build_crates(build_context, exec, &destination_workspace, mains, cfgs, Main);
debug!("Building tests");
- self.build_crates(ctx, exec, &destination_workspace, tests, cfgs, Test);
+ self.build_crates(build_context, exec, &destination_workspace, tests, cfgs, Test);
debug!("Building benches");
- self.build_crates(ctx, exec, &destination_workspace, benchs, cfgs, Bench);
+ self.build_crates(build_context, exec, &destination_workspace, benchs, cfgs, Bench);
destination_workspace.to_str()
}
}
if found.is_some() {
debug!("Found %s in %s", pkgid.to_str(), workspace.to_str());
- }
- else {
+ } else {
debug!("Didn't find %s in %s", pkgid.to_str(), workspace.to_str());
}
found
use path_util::{target_executable_in_workspace, target_library_in_workspace};
use source_control::is_git_dir;
use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces, cwd_to_workspace};
-use context::{BuildCtx, Ctx};
+use context::{BuildContext, Context};
use package_id::PkgId;
use package_source::PkgSrc;
use workcache_support::{discover_outputs, digest_only_date};
fn build(&self, exec: &mut workcache::Exec, pkg_src: PkgSrc) -> Path;
fn clean(&self, workspace: &Path, id: &PkgId);
fn info(&self);
+ /// Returns a pair. First component is a list of installed paths,
+ /// second is a list of declared and discovered inputs
fn install(&self, src: PkgSrc) -> (~[Path], ~[(~str, ~str)]);
/// Returns a list of installed files
fn install_no_build(&self, workspace: &Path, id: &PkgId) -> ~[Path];
fn unprefer(&self, _id: &str, _vers: Option<~str>);
}
-impl CtxMethods for BuildCtx {
+impl CtxMethods for BuildContext {
fn build_from_src(&self, pkg_src: PkgSrc) {
let tag = pkg_src.id.to_str();
debug!("package source = %s", pkg_src.to_str());
- do self.workcache_cx.with_prep(tag) |prep| {
+ do self.workcache_context.with_prep(tag) |prep| {
let subsrc = pkg_src.clone();
let subself = self.clone();
declare_package_script_dependency(prep, &subsrc);
"build" => {
if args.len() < 1 {
match cwd_to_workspace() {
- None if self.cx.use_rust_path_hack => {
+ None if self.context.use_rust_path_hack => {
let cwd = os::getcwd();
let pkgid = PkgId::new(cwd.components[cwd.components.len() - 1]);
self.build_from_src(PkgSrc::new(cwd, true, pkgid));
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(args[0].clone());
- do each_pkg_parent_workspace(&self.cx, &pkgid) |workspace| {
+ do each_pkg_parent_workspace(&self.context, &pkgid) |workspace| {
debug!("found pkg %s in workspace %s, trying to build",
pkgid.to_str(), workspace.to_str());
let pkg_src = PkgSrc::new(workspace.clone(), false, pkgid.clone());
"install" => {
if args.len() < 1 {
match cwd_to_workspace() {
- None if self.cx.use_rust_path_hack => {
+ None if self.context.use_rust_path_hack => {
let cwd = os::getcwd();
let inferred_pkgid =
PkgId::new(cwd.components[cwd.components.len() - 1]);
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(args[0]);
- let workspaces = pkg_parent_workspaces(&self.cx, &pkgid);
+ let workspaces = pkg_parent_workspaces(&self.context, &pkgid);
debug!("package ID = %s, found it in %? workspaces",
pkgid.to_str(), workspaces.len());
if workspaces.is_empty() {
else {
for workspace in workspaces.iter() {
let src = PkgSrc::new(workspace.clone(),
- self.cx.use_rust_path_hack,
+ self.context.use_rust_path_hack,
pkgid.clone());
self.install(src);
};
else {
let rp = rust_path();
assert!(!rp.is_empty());
- do each_pkg_parent_workspace(&self.cx, &pkgid) |workspace| {
+ do each_pkg_parent_workspace(&self.context, &pkgid) |workspace| {
path_util::uninstall_package_from(workspace, &pkgid);
note(fmt!("Uninstalled package %s (was installed in %s)",
pkgid.to_str(), workspace.to_str()));
/// Returns the destination workspace
/// In the case of a custom build, we don't know, so we just return the source workspace
- fn build(&self, exec: &mut workcache::Exec, pkg_src: PkgSrc) -> Path {
-
- let pkg_src = &mut pkg_src.clone(); // :-o
+ fn build(&self, exec: &mut workcache::Exec, mut pkg_src: PkgSrc) -> Path {
let workspace = pkg_src.workspace.clone();
let pkgid = pkg_src.id.clone();
fail!("info not yet implemented");
}
- /// Returns a pair. First component is a list of installed paths,
- /// second is a list of declared and discovered inputs
fn install(&self, pkg_src: PkgSrc) -> (~[Path], ~[(~str, ~str)]) {
let id = &pkg_src.id;
let installed_files = RWArc::new(~[]);
let inputs = RWArc::new(~[]);
// FIXME #7402: Use RUST_PATH to determine target dir
- let f: &fn(&mut workcache::Prep) = |prep| {
+ self.workcache_context.with_prep(id.to_str(), |p| pkg_src.declare_inputs(p));
+ do self.workcache_context.with_prep(id.to_str()) |prep| {
let sub_inputs = inputs.clone();
let sub_files = installed_files.clone();
let subsrc = pkg_src.clone();
sub_inputs.write(|r| { *r = *r + exec.lookup_discovered_inputs() });
}
};
- self.workcache_cx.with_prep(id.to_str(), |p| pkg_src.declare_inputs(p));
- self.workcache_cx.with_prep(id.to_str(), f);
(installed_files.unwrap(), inputs.unwrap())
}
let sroot = filesearch::get_or_default_sysroot();
debug!("Using sysroot: %s", sroot.to_str());
debug!("Will store workcache in %s", default_workspace().to_str());
- BuildCtx {
- cx: Ctx {
- use_rust_path_hack: use_rust_path_hack,
- sysroot_opt: sroot, // Currently, only tests override this
+ BuildContext {
+ context: Context {
+ use_rust_path_hack: use_rust_path_hack,
+ sysroot: sroot, // Currently, only tests override this
},
- workcache_cx: api::default_ctxt(default_workspace()).workcache_cx // ???
+ workcache_context: api::default_context(default_workspace()).workcache_context
}.run(*cmd, remaining_args)
}
// rustpkg unit tests
-use context::{BuildCtx, Ctx};
+use context::{BuildContext, Context};
use std::{io, libc, os, run, str, task};
use extra::arc::Arc;
use extra::arc::RWArc;
use extra::tempfile::mkdtemp;
-use extra::workcache::{Context, Database, Logger};
+use extra::workcache;
+use extra::workcache::{Database, Logger};
use extra::treemap::TreeMap;
use std::run::ProcessOutput;
use installed_packages::list_installed_packages;
p.stat().map(|stat| stat.st_mtime)
}
-fn fake_ctxt(sysroot_opt: Path, workspace: &Path) -> BuildCtx {
- let bcx = Context::new(RWArc::new(Database::new(workspace.push("rustpkg_db.json"))),
- RWArc::new(Logger::new()),
- Arc::new(TreeMap::new()));
- BuildCtx {
- workcache_cx: bcx,
- cx: Ctx {
+fn fake_ctxt(sysroot: Path, workspace: &Path) -> BuildContext {
+ let context = workcache::Context::new(
+ RWArc::new(Database::new(workspace.push("rustpkg_db.json"))),
+ RWArc::new(Logger::new()),
+ Arc::new(TreeMap::new()));
+ BuildContext {
+ workcache_context: context,
+ context: Context {
use_rust_path_hack: false,
- sysroot_opt: sysroot_opt
+ sysroot: sysroot
}
}
}
use syntax::attr::AttrMetaMethods;
use rustc::back::link::output_type_exe;
use rustc::driver::session::{lib_crate, bin_crate};
-use context::{in_target, BuildCtx};
+use context::{in_target, BuildContext};
use package_id::PkgId;
use package_source::PkgSrc;
use path_util::{installed_library_in_workspace, U_RWX};
@fold.fold_crate(crate)
}
-pub fn compile_input(ctxt: &BuildCtx,
+pub fn compile_input(ctxt: &BuildContext,
exec: &mut workcache::Exec,
pkg_id: &PkgId,
in_file: &Path,
flags: &[~str],
cfgs: &[~str],
opt: bool,
- what: OutputType) -> Option<Path> {
-
+ what: OutputType) -> Path {
assert!(in_file.components.len() > 1);
let input = driver::file_input((*in_file).clone());
debug!("compile_input: %s / %?", in_file.to_str(), what);
debug!("flags: %s", flags.connect(" "));
debug!("cfgs: %s", cfgs.connect(" "));
- debug!("compile_input's sysroot = %s", ctxt.sysroot_opt().to_str());
+ debug!("compile_input's sysroot = %s", ctxt.sysroot().to_str());
let crate_type = match what {
Lib => lib_crate,
driver::optgroups()).unwrap();
// Hack so that rustpkg can run either out of a rustc target dir,
// or the host dir
- let sysroot_to_use = @if !in_target(&ctxt.sysroot_opt()) {
- ctxt.sysroot_opt()
+ let sysroot_to_use = @if !in_target(&ctxt.sysroot()) {
+ ctxt.sysroot()
}
else {
- ctxt.sysroot_opt().pop().pop().pop()
+ ctxt.sysroot().pop().pop().pop()
};
- debug!("compile_input's sysroot = %s", ctxt.sysroot_opt().to_str());
+ debug!("compile_input's sysroot = %s", ctxt.sysroot().to_str());
debug!("sysroot_to_use = %s", sysroot_to_use.to_str());
let options = @session::options {
crate_type: crate_type,
// should be of the form <workspace>/build/<pkg id's path>
out_dir: &Path,
sess: session::Session,
- crate: @ast::Crate) -> Option<Path> {
+ crate: @ast::Crate) -> Path {
debug!("Calling build_output_filenames with %s, building library? %?",
out_dir.to_str(), sess.building_library);
&analysis,
outputs);
driver::phase_5_run_llvm_passes(sess, &translation, outputs);
- if driver::stop_after_phase_5(sess) { return Some(outputs.out_filename); }
+ if driver::stop_after_phase_5(sess) { return outputs.out_filename; }
driver::phase_6_link_output(sess, &translation, outputs);
// Register dependency on the source file
exec.discover_input("file", input.to_str(), digest_file_with_date(input));
- Some(outputs.out_filename)
+ outputs.out_filename
}
#[cfg(windows)]
pub fn exe_suffix() -> ~str { ~"" }
// Called by build_crates
-pub fn compile_crate(ctxt: &BuildCtx,
+pub fn compile_crate(ctxt: &BuildContext,
exec: &mut workcache::Exec,
pkg_id: &PkgId,
crate: &Path, workspace: &Path,
flags: &[~str], cfgs: &[~str], opt: bool,
- what: OutputType) -> Option<Path> {
+ what: OutputType) -> Path {
debug!("compile_crate: crate=%s, workspace=%s", crate.to_str(), workspace.to_str());
debug!("compile_crate: short_name = %s, flags =...", pkg_id.to_str());
for fl in flags.iter() {
/// Collect all `extern mod` directives in `c`, then
/// try to install their targets, failing if any target
/// can't be found.
-pub fn find_and_install_dependencies(ctxt: &BuildCtx,
+pub fn find_and_install_dependencies(ctxt: &BuildContext,
sess: session::Session,
exec: &mut workcache::Exec,
workspace: &Path,
// ignore metadata, I guess
ast::view_item_extern_mod(lib_ident, path_opt, _, _) => {
let lib_name = match path_opt {
- Some(p) => p, None => sess.str_of(lib_ident) };
- match installed_library_in_workspace(lib_name, &ctxt.sysroot_opt()) {
+ Some(p) => p,
+ None => sess.str_of(lib_ident)
+ };
+ match installed_library_in_workspace(lib_name, &ctxt.sysroot()) {
Some(ref installed_path) => {
debug!("It exists: %s", installed_path.to_str());
// Say that [path for c] has a discovered dependency on
use std::{os,util};
use std::path::Path;
-use context::Ctx;
+use context::Context;
use path_util::{workspace_contains_package_id, find_dir_using_rust_path_hack};
use util::option_to_vec;
use package_id::PkgId;
use path_util::rust_path;
-pub fn each_pkg_parent_workspace(cx: &Ctx, pkgid: &PkgId, action: &fn(&Path) -> bool) -> bool {
+pub fn each_pkg_parent_workspace(cx: &Context, pkgid: &PkgId, action: &fn(&Path) -> bool) -> bool {
// Using the RUST_PATH, find workspaces that contain
// this package ID
let workspaces = pkg_parent_workspaces(cx, pkgid);
return true;
}
-pub fn pkg_parent_workspaces(cx: &Ctx, pkgid: &PkgId) -> ~[Path] {
+pub fn pkg_parent_workspaces(cx: &Context, pkgid: &PkgId) -> ~[Path] {
let rs: ~[Path] = rust_path().move_iter()
.filter(|ws| workspace_contains_package_id(pkgid, ws))
.collect();