rustpkg: Tests for well-formed and ill-formed package IDs...
...and cleanup, making how we handle version numbers more rational (specifically, not passing in a versioned name to rustc with the -o flag), and removing unused code.
This commit is contained in:
parent
c3875e8c70
commit
80a7e2644c
@ -28,3 +28,7 @@ condition! {
|
||||
condition! {
|
||||
missing_pkg_files: (super::PkgId) -> ();
|
||||
}
|
||||
|
||||
condition! {
|
||||
bad_pkg_id: (super::Path, ~str) -> ::util::PkgId;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, u_rwx) }
|
||||
|
||||
/// True if there's a directory in <workspace> with
|
||||
/// pkgid's short name
|
||||
pub fn workspace_contains_package_id(pkgid: PkgId, workspace: &Path) -> bool {
|
||||
pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
|
||||
let pkgpath = workspace.push("src").push(pkgid.local_path.to_str());
|
||||
os::path_is_dir(&pkgpath)
|
||||
}
|
||||
@ -67,17 +67,17 @@ pub fn built_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<
|
||||
|
||||
/// Figure out what the test name for <pkgid> in <workspace>'s build
|
||||
/// directory is, and if the file exists, return it.
|
||||
pub fn built_test_in_workspace(pkgid: PkgId, workspace: &Path) -> Option<Path> {
|
||||
pub fn built_test_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
|
||||
output_in_workspace(pkgid, workspace, Test)
|
||||
}
|
||||
|
||||
/// Figure out what the test name for <pkgid> in <workspace>'s build
|
||||
/// directory is, and if the file exists, return it.
|
||||
pub fn built_bench_in_workspace(pkgid: PkgId, workspace: &Path) -> Option<Path> {
|
||||
pub fn built_bench_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
|
||||
output_in_workspace(pkgid, workspace, Bench)
|
||||
}
|
||||
|
||||
fn output_in_workspace(pkgid: PkgId, workspace: &Path, what: OutputType) -> Option<Path> {
|
||||
fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Option<Path> {
|
||||
let mut result = workspace.push("build");
|
||||
// should use a target-specific subdirectory
|
||||
result = mk_output_path(what, pkgid, &result);
|
||||
@ -94,7 +94,7 @@ fn output_in_workspace(pkgid: PkgId, workspace: &Path, what: OutputType) -> Opti
|
||||
|
||||
/// Figure out what the library name for <pkgid> in <workspace>'s build
|
||||
/// directory is, and if the file exists, return it.
|
||||
pub fn built_library_in_workspace(pkgid: PkgId, workspace: &Path) -> Option<Path> {
|
||||
pub fn built_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
|
||||
let result = mk_output_path(Lib, pkgid, &workspace.push("build"));
|
||||
debug!("built_library_in_workspace: checking whether %s exists",
|
||||
result.to_str());
|
||||
@ -177,14 +177,14 @@ pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
||||
/// Returns the test executable that would be installed for <pkgid>
|
||||
/// in <workspace>
|
||||
/// note that we *don't* install test executables, so this is just for unit testing
|
||||
pub fn target_test_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
|
||||
pub fn target_test_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
||||
target_file_in_workspace(pkgid, workspace, Test)
|
||||
}
|
||||
|
||||
/// Returns the bench executable that would be installed for <pkgid>
|
||||
/// in <workspace>
|
||||
/// note that we *don't* install bench executables, so this is just for unit testing
|
||||
pub fn target_bench_in_workspace(pkgid: PkgId, workspace: &Path) -> Path {
|
||||
pub fn target_bench_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
||||
target_file_in_workspace(pkgid, workspace, Bench)
|
||||
}
|
||||
|
||||
@ -192,13 +192,12 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
|
||||
what: OutputType) -> Path {
|
||||
use conditions::bad_path::cond;
|
||||
|
||||
let (subdir, create_dir) = match what {
|
||||
let subdir = match what {
|
||||
Lib => "lib", Main | Test | Bench => "bin"
|
||||
};
|
||||
let result = workspace.push(subdir);
|
||||
debug!("target_file_in_workspace: %s %?", result.to_str(), create_dir);
|
||||
if !os::path_exists(&result) && !mkdir_recursive(&result, u_rwx) {
|
||||
cond.raise((result, fmt!("I couldn't create the %s dir", subdir)));
|
||||
cond.raise((copy result, fmt!("I couldn't create the %s dir", subdir)));
|
||||
}
|
||||
mk_output_path(what, pkgid, &result)
|
||||
}
|
||||
@ -222,17 +221,19 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
||||
|
||||
/// Return the output file for a given directory name,
|
||||
/// given whether we're building a library and whether we're building tests
|
||||
pub fn mk_output_path(what: OutputType, pkg_id: PkgId, workspace: &Path) -> Path {
|
||||
let short_name = pkg_id.short_name_with_version();
|
||||
pub fn mk_output_path(what: OutputType, pkg_id: &PkgId, workspace: &Path) -> Path {
|
||||
let short_name_with_version = pkg_id.short_name_with_version();
|
||||
// Not local_path.dir_path()! For package foo/bar/blat/, we want
|
||||
// the executable blat-0.5 to live under blat/
|
||||
let dir = workspace.push_rel(&*pkg_id.local_path);
|
||||
debug!("mk_output_path: short_name = %s, path = %s",
|
||||
short_name, dir.to_str());
|
||||
if what == Lib { copy short_name_with_version } else { copy pkg_id.short_name },
|
||||
dir.to_str());
|
||||
let output_path = match what {
|
||||
// this code is duplicated from elsewhere; fix this
|
||||
Lib => dir.push(os::dll_filename(short_name)),
|
||||
_ => dir.push(fmt!("%s%s%s", short_name,
|
||||
Lib => dir.push(os::dll_filename(short_name_with_version)),
|
||||
// executable names *aren't* versioned
|
||||
_ => dir.push(fmt!("%s%s%s", copy pkg_id.short_name,
|
||||
match what {
|
||||
Test => "test",
|
||||
Bench => "bench",
|
||||
|
@ -157,27 +157,6 @@ impl<'self> PkgScript<'self> {
|
||||
impl Ctx {
|
||||
|
||||
fn run(&self, cmd: ~str, args: ~[~str]) {
|
||||
let root = util::root();
|
||||
|
||||
util::need_dir(&root);
|
||||
util::need_dir(&root.push(~"work"));
|
||||
util::need_dir(&root.push(~"lib"));
|
||||
util::need_dir(&root.push(~"bin"));
|
||||
util::need_dir(&root.push(~"tmp"));
|
||||
|
||||
fn sep_name_vers(in: ~str) -> (Option<~str>, Option<~str>) {
|
||||
let mut name = None;
|
||||
let mut vers = None;
|
||||
|
||||
for str::each_split_char(in, '@') |s| {
|
||||
if name.is_none() { name = Some(s.to_owned()); }
|
||||
else if vers.is_none() { vers = Some(s.to_owned()); }
|
||||
else { break; }
|
||||
}
|
||||
|
||||
(name, vers)
|
||||
}
|
||||
|
||||
match cmd {
|
||||
~"build" => {
|
||||
if args.len() < 1 {
|
||||
@ -227,9 +206,7 @@ impl Ctx {
|
||||
return usage::uninstall();
|
||||
}
|
||||
|
||||
let (name, vers) = sep_name_vers(copy args[0]);
|
||||
|
||||
self.prefer(name.get(), vers);
|
||||
self.prefer(args[0], None);
|
||||
}
|
||||
~"test" => {
|
||||
self.test();
|
||||
@ -239,20 +216,16 @@ impl Ctx {
|
||||
return usage::uninstall();
|
||||
}
|
||||
|
||||
let (name, vers) = sep_name_vers(copy args[0]);
|
||||
|
||||
self.uninstall(name.get(), vers);
|
||||
self.uninstall(args[0], None);
|
||||
}
|
||||
~"unprefer" => {
|
||||
if args.len() < 1 {
|
||||
return usage::uninstall();
|
||||
}
|
||||
|
||||
let (name, vers) = sep_name_vers(copy args[0]);
|
||||
|
||||
self.unprefer(name.get(), vers);
|
||||
self.unprefer(args[0], None);
|
||||
}
|
||||
_ => fail!("reached an unhandled command")
|
||||
_ => fail!(fmt!("I don't know the command `%s`", cmd))
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +240,7 @@ impl Ctx {
|
||||
debug!("Destination dir = %s", build_dir.to_str());
|
||||
|
||||
// Create the package source
|
||||
let mut src = PkgSrc::new(workspace, &build_dir, &pkgid);
|
||||
let mut src = PkgSrc::new(workspace, &build_dir, pkgid);
|
||||
debug!("Package src = %?", src);
|
||||
|
||||
// Is there custom build logic? If so, use it
|
||||
@ -305,7 +278,6 @@ impl Ctx {
|
||||
// Build it!
|
||||
src.build(&build_dir, cfgs, self.sysroot_opt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn clean(&self, workspace: &Path, id: &PkgId) {
|
||||
@ -317,7 +289,7 @@ impl Ctx {
|
||||
util::note(fmt!("Cleaning package %s (removing directory %s)",
|
||||
id.to_str(), dir.to_str()));
|
||||
if os::path_exists(&dir) {
|
||||
util::remove_dir_r(&dir);
|
||||
os::remove_dir_recursive(&dir);
|
||||
util::note(fmt!("Removed directory %s", dir.to_str()));
|
||||
}
|
||||
|
||||
@ -353,19 +325,19 @@ impl Ctx {
|
||||
debug!("Copying: %s -> %s", exec.to_str(), target_exec.to_str());
|
||||
if !(os::mkdir_recursive(&target_exec.dir_path(), u_rwx) &&
|
||||
os::copy_file(exec, &target_exec)) {
|
||||
cond.raise((*exec, target_exec));
|
||||
cond.raise((copy *exec, copy target_exec));
|
||||
}
|
||||
}
|
||||
for maybe_library.each |lib| {
|
||||
debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str());
|
||||
if !(os::mkdir_recursive(&target_lib.dir_path(), u_rwx) &&
|
||||
os::copy_file(lib, &target_lib)) {
|
||||
cond.raise((*lib, target_lib));
|
||||
cond.raise((copy *lib, copy target_lib));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prefer(&self, _id: ~str, _vers: Option<~str>) {
|
||||
fn prefer(&self, _id: &str, _vers: Option<~str>) {
|
||||
fail!(~"prefer not yet implemented");
|
||||
}
|
||||
|
||||
@ -374,15 +346,16 @@ impl Ctx {
|
||||
fail!("test not yet implemented");
|
||||
}
|
||||
|
||||
fn uninstall(&self, _id: ~str, _vers: Option<~str>) {
|
||||
fn uninstall(&self, _id: &str, _vers: Option<~str>) {
|
||||
fail!("uninstall not yet implemented");
|
||||
}
|
||||
|
||||
fn unprefer(&self, _id: ~str, _vers: Option<~str>) {
|
||||
fn unprefer(&self, _id: &str, _vers: Option<~str>) {
|
||||
fail!("unprefer not yet implemented");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn main() {
|
||||
io::println("WARNING: The Rust package manager is experimental and may be unstable");
|
||||
|
||||
@ -443,32 +416,6 @@ pub struct Crate {
|
||||
cfgs: ~[~str]
|
||||
}
|
||||
|
||||
pub struct Listener {
|
||||
cmds: ~[~str],
|
||||
cb: ~fn()
|
||||
}
|
||||
|
||||
pub fn run(listeners: ~[Listener]) {
|
||||
let rcmd = copy os::args()[2];
|
||||
let mut found = false;
|
||||
|
||||
for listeners.each |listener| {
|
||||
for listener.cmds.each |&cmd| {
|
||||
if cmd == rcmd {
|
||||
(listener.cb)();
|
||||
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
os::set_exit_status(42);
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Crate {
|
||||
|
||||
fn new(p: &Path) -> Crate {
|
||||
@ -527,10 +474,6 @@ pub fn src_dir() -> Path {
|
||||
os::getcwd()
|
||||
}
|
||||
|
||||
condition! {
|
||||
bad_pkg_id: (super::Path, ~str) -> ::util::PkgId;
|
||||
}
|
||||
|
||||
// An enumeration of the unpacked source of a package workspace.
|
||||
// This contains a list of files found in the source workspace.
|
||||
pub struct PkgSrc {
|
||||
@ -576,7 +519,7 @@ impl PkgSrc {
|
||||
|
||||
if !os::path_exists(&dir) {
|
||||
if !self.fetch_git() {
|
||||
cond.raise((self.id, ~"supplied path for package dir does not \
|
||||
cond.raise((copy self.id, ~"supplied path for package dir does not \
|
||||
exist, and couldn't interpret it as a URL fragment"));
|
||||
}
|
||||
}
|
||||
@ -598,12 +541,12 @@ impl PkgSrc {
|
||||
let mut local = self.root.push("src");
|
||||
local = local.push(self.id.to_str());
|
||||
// Git can't clone into a non-empty directory
|
||||
util::remove_dir_r(&local);
|
||||
os::remove_dir_recursive(&local);
|
||||
|
||||
let url = fmt!("https://%s", self.id.remote_path.to_str());
|
||||
util::note(fmt!("git clone %s %s", url, local.to_str()));
|
||||
|
||||
if run::program_output(~"git", ~[~"clone", url, local.to_str()]).status != 0 {
|
||||
if run::program_output(~"git", ~[~"clone", copy url, local.to_str()]).status != 0 {
|
||||
util::note(fmt!("fetching %s failed: can't clone repository", url));
|
||||
return false;
|
||||
}
|
||||
@ -733,3 +676,4 @@ impl PkgSrc {
|
||||
self.build_crates(maybe_sysroot, dst_dir, &dir, self.benchs, cfgs, Bench);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ use path_util::{target_executable_in_workspace, target_library_in_workspace,
|
||||
target_test_in_workspace, target_bench_in_workspace,
|
||||
make_dir_rwx, u_rwx, RemotePath, LocalPath, normalize,
|
||||
built_bench_in_workspace, built_test_in_workspace};
|
||||
use core::os::mkdir_recursive;
|
||||
|
||||
fn fake_ctxt(sysroot_opt: Option<@Path>) -> Ctx {
|
||||
Ctx {
|
||||
@ -33,7 +32,7 @@ fn fake_pkg() -> PkgId {
|
||||
let sn = ~"bogus";
|
||||
let remote = RemotePath(Path(sn));
|
||||
PkgId {
|
||||
local_path: normalize(remote),
|
||||
local_path: normalize(copy remote),
|
||||
remote_path: remote,
|
||||
short_name: sn,
|
||||
version: default_version()
|
||||
@ -43,7 +42,7 @@ fn fake_pkg() -> PkgId {
|
||||
fn remote_pkg() -> PkgId {
|
||||
let remote = RemotePath(Path(~"github.com/catamorphism/test-pkg"));
|
||||
PkgId {
|
||||
local_path: normalize(remote),
|
||||
local_path: normalize(copy remote),
|
||||
remote_path: remote,
|
||||
short_name: ~"test_pkg",
|
||||
version: default_version()
|
||||
@ -59,9 +58,9 @@ fn writeFile(file_path: &Path, contents: ~str) {
|
||||
|
||||
fn mk_temp_workspace(short_name: &LocalPath) -> Path {
|
||||
let workspace = mkdtemp(&os::tmpdir(), "test").expect("couldn't create temp dir");
|
||||
// Ugh, including version number
|
||||
let package_dir = workspace.push(~"src").push(fmt!("%s-0-1", short_name.to_str()));
|
||||
assert!(mkdir_recursive(&package_dir, u_rwx));
|
||||
// include version number in directory name
|
||||
let package_dir = workspace.push(~"src").push(fmt!("%s-0.1", short_name.to_str()));
|
||||
assert!(os::mkdir_recursive(&package_dir, u_rwx));
|
||||
// Create main, lib, test, and bench files
|
||||
writeFile(&package_dir.push(~"main.rs"),
|
||||
~"fn main() { let _x = (); }");
|
||||
@ -162,25 +161,72 @@ fn test_install_url() {
|
||||
let ctxt = fake_ctxt(Some(@sysroot));
|
||||
let temp_pkg_id = remote_pkg();
|
||||
// should have test, bench, lib, and main
|
||||
ctxt.install(&workspace, temp_pkg_id);
|
||||
ctxt.install(&workspace, &temp_pkg_id);
|
||||
// Check that all files exist
|
||||
let exec = target_executable_in_workspace(temp_pkg_id, &workspace);
|
||||
let exec = target_executable_in_workspace(&temp_pkg_id, &workspace);
|
||||
debug!("exec = %s", exec.to_str());
|
||||
assert!(os::path_exists(&exec));
|
||||
assert!(is_rwx(&exec));
|
||||
let lib = target_library_in_workspace(temp_pkg_id, &workspace);
|
||||
let lib = target_library_in_workspace(&temp_pkg_id, &workspace);
|
||||
debug!("lib = %s", lib.to_str());
|
||||
assert!(os::path_exists(&lib));
|
||||
assert!(is_rwx(&lib));
|
||||
let built_test = built_test_in_workspace(temp_pkg_id, &workspace).expect(~"test_install_url");
|
||||
let built_test = built_test_in_workspace(&temp_pkg_id, &workspace).expect(~"test_install_url");
|
||||
assert!(os::path_exists(&built_test));
|
||||
let built_bench = built_bench_in_workspace(temp_pkg_id, &workspace).expect(~"test_install_url");
|
||||
let built_bench = built_bench_in_workspace(&temp_pkg_id,
|
||||
&workspace).expect(~"test_install_url");
|
||||
assert!(os::path_exists(&built_bench));
|
||||
// And that the test and bench executables aren't installed
|
||||
let test = target_test_in_workspace(temp_pkg_id, &workspace);
|
||||
let test = target_test_in_workspace(&temp_pkg_id, &workspace);
|
||||
assert!(!os::path_exists(&test));
|
||||
debug!("test = %s", test.to_str());
|
||||
let bench = target_bench_in_workspace(temp_pkg_id, &workspace);
|
||||
let bench = target_bench_in_workspace(&temp_pkg_id, &workspace);
|
||||
debug!("bench = %s", bench.to_str());
|
||||
assert!(!os::path_exists(&bench));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_package_ids_must_be_relative_path_like() {
|
||||
use conditions::bad_pkg_id::cond;
|
||||
|
||||
/*
|
||||
Okay:
|
||||
- One identifier, with no slashes
|
||||
- Several slash-delimited things, with no / at the root
|
||||
|
||||
Not okay:
|
||||
- Empty string
|
||||
- Absolute path (as per os::is_absolute)
|
||||
|
||||
*/
|
||||
|
||||
let default_version_str = "0.1";
|
||||
let addversion = |s| {
|
||||
fmt!("%s-%s", s, default_version_str)
|
||||
};
|
||||
|
||||
let whatever = PkgId::new("foo");
|
||||
|
||||
assert!(addversion("foo") == whatever.to_str());
|
||||
assert!(addversion("github.com/mozilla/rust") ==
|
||||
PkgId::new("github.com/mozilla/rust").to_str());
|
||||
|
||||
do cond.trap(|(p, e)| {
|
||||
assert!("" == p.to_str());
|
||||
assert!("0-length pkgid" == e);
|
||||
copy whatever
|
||||
}).in {
|
||||
let x = PkgId::new("");
|
||||
assert!(addversion("foo") == x.to_str());
|
||||
}
|
||||
|
||||
do cond.trap(|(p, e)| {
|
||||
assert!(p.to_str() == os::make_absolute(&Path("foo/bar/quux")).to_str());
|
||||
assert!("absolute pkgid" == e);
|
||||
copy whatever
|
||||
}).in {
|
||||
let z = PkgId::new(os::make_absolute(&Path("foo/bar/quux")).to_str());
|
||||
assert!(addversion("foo") == z.to_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,13 +16,12 @@ use rustc::driver::{driver, session};
|
||||
use rustc::metadata::filesearch;
|
||||
use std::getopts::groups::getopts;
|
||||
use std::semver;
|
||||
use std::{json, term, getopts};
|
||||
use std::{term, getopts};
|
||||
use syntax::ast_util::*;
|
||||
use syntax::codemap::{dummy_sp, spanned, dummy_spanned};
|
||||
use syntax::ext::base::{mk_ctxt, ext_ctxt};
|
||||
use syntax::ext::build;
|
||||
use syntax::{ast, attr, codemap, diagnostic, fold};
|
||||
use syntax::ast::{meta_name_value, meta_list, attribute};
|
||||
use syntax::ast::{meta_name_value, meta_list};
|
||||
use syntax::attr::{mk_attr};
|
||||
use rustc::back::link::output_type_exe;
|
||||
use rustc::driver::session::{lib_crate, bin_crate};
|
||||
@ -109,7 +108,7 @@ pub struct PkgId {
|
||||
|
||||
pub impl PkgId {
|
||||
fn new(s: &str) -> PkgId {
|
||||
use bad_pkg_id::cond;
|
||||
use conditions::bad_pkg_id::cond;
|
||||
|
||||
let p = Path(s);
|
||||
if p.is_absolute {
|
||||
@ -119,11 +118,12 @@ pub impl PkgId {
|
||||
return cond.raise((p, ~"0-length pkgid"));
|
||||
}
|
||||
let remote_path = RemotePath(p);
|
||||
let local_path = normalize(remote_path);
|
||||
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: local_path.filestem().expect(fmt!("Strange path! %s", s)),
|
||||
short_name: short_name,
|
||||
version: default_version()
|
||||
}
|
||||
}
|
||||
@ -142,14 +142,7 @@ pub impl PkgId {
|
||||
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(),
|
||||
// Replace dots with -s in the version
|
||||
// this is because otherwise rustc will think
|
||||
// that foo-0.1 has .1 as its extension
|
||||
// (Temporary hack until I figure out how to
|
||||
// get rustc to not name the object file
|
||||
// foo-0.o if I pass in foo-0.1 to build_output_filenames)
|
||||
str::replace(self.version.to_str(), ".", "-"))
|
||||
fmt!("%s-%s", self.local_path.to_str(), self.version.to_str())
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,26 +169,6 @@ pub fn is_cmd(cmd: &str) -> bool {
|
||||
Commands.any(|&c| c == cmd)
|
||||
}
|
||||
|
||||
pub fn parse_name(id: ~str) -> result::Result<~str, ~str> {
|
||||
let mut last_part = None;
|
||||
|
||||
for str::each_split_char(id, '.') |part| {
|
||||
for str::each_char(part) |char| {
|
||||
if char::is_whitespace(char) {
|
||||
return result::Err(
|
||||
~"could not parse id: contains whitespace");
|
||||
} else if char::is_uppercase(char) {
|
||||
return result::Err(
|
||||
~"could not parse id: should be all lowercase");
|
||||
}
|
||||
}
|
||||
last_part = Some(part.to_owned());
|
||||
}
|
||||
if last_part.is_none() { return result::Err(~"could not parse id: is empty"); }
|
||||
|
||||
result::Ok(last_part.unwrap())
|
||||
}
|
||||
|
||||
struct ListenerFn {
|
||||
cmds: ~[~str],
|
||||
span: codemap::span,
|
||||
@ -268,52 +241,6 @@ fn fold_item(ctx: @mut ReadyCtx,
|
||||
res
|
||||
}
|
||||
|
||||
fn add_pkg_module(ctx: @mut ReadyCtx, m: ast::_mod) -> ast::_mod {
|
||||
let listeners = mk_listener_vec(ctx);
|
||||
let ext_cx = ctx.ext_cx;
|
||||
let item = quote_item! (
|
||||
mod __pkg {
|
||||
extern mod rustpkg (vers="0.7-pre");
|
||||
static listeners : &[rustpkg::Listener] = $listeners;
|
||||
#[main]
|
||||
fn main() {
|
||||
rustpkg::run(listeners);
|
||||
}
|
||||
}
|
||||
);
|
||||
ast::_mod {
|
||||
items: vec::append_one(/*bad*/copy m.items, item.get()),
|
||||
.. m
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_listener_vec(ctx: @mut ReadyCtx) -> @ast::expr {
|
||||
let descs = do ctx.fns.map |listener| {
|
||||
mk_listener_rec(ctx, listener)
|
||||
};
|
||||
let ext_cx = ctx.ext_cx;
|
||||
build::mk_slice_vec_e(ext_cx, dummy_sp(), descs)
|
||||
}
|
||||
|
||||
fn mk_listener_rec(ctx: @mut ReadyCtx, listener: &ListenerFn) -> @ast::expr {
|
||||
let span = listener.span;
|
||||
let cmds = do listener.cmds.map |&cmd| {
|
||||
let ext_cx = ctx.ext_cx;
|
||||
build::mk_base_str(ext_cx, span, cmd)
|
||||
};
|
||||
|
||||
let ext_cx = ctx.ext_cx;
|
||||
let cmds_expr = build::mk_slice_vec_e(ext_cx, span, cmds);
|
||||
let cb_expr = build::mk_path(ext_cx, span, copy listener.path);
|
||||
|
||||
quote_expr!(
|
||||
Listener {
|
||||
cmds: $cmds_expr,
|
||||
cb: $cb_expr
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Generate/filter main function, add the list of commands, etc.
|
||||
pub fn ready_crate(sess: session::Session,
|
||||
crate: @ast::crate) -> @ast::crate {
|
||||
@ -395,67 +322,6 @@ pub fn hash(data: ~str) -> ~str {
|
||||
hasher.result_str()
|
||||
}
|
||||
|
||||
pub fn temp_change_dir<T>(dir: &Path, cb: &fn() -> T) {
|
||||
let cwd = os::getcwd();
|
||||
|
||||
os::change_dir(dir);
|
||||
cb();
|
||||
os::change_dir(&cwd);
|
||||
}
|
||||
|
||||
pub fn touch(path: &Path) {
|
||||
match io::mk_file_writer(path, ~[io::Create]) {
|
||||
result::Ok(writer) => writer.write_line(~""),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_dir_r(path: &Path) {
|
||||
for os::walk_dir(path) |&file| {
|
||||
let mut cdir = file;
|
||||
|
||||
loop {
|
||||
if os::path_is_dir(&cdir) {
|
||||
os::remove_dir(&cdir);
|
||||
} else {
|
||||
os::remove_file(&cdir);
|
||||
}
|
||||
|
||||
cdir = cdir.dir_path();
|
||||
|
||||
if cdir == *path { break; }
|
||||
}
|
||||
}
|
||||
|
||||
os::remove_dir(path);
|
||||
}
|
||||
|
||||
pub fn wait_for_lock(path: &Path) {
|
||||
if os::path_exists(path) {
|
||||
warn(fmt!("the database appears locked, please wait (or rm %s)",
|
||||
path.to_str()));
|
||||
|
||||
loop {
|
||||
if !os::path_exists(path) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_pkgs() -> result::Result<~[json::Json], ~str> {
|
||||
fail!("load_pkg not implemented");
|
||||
}
|
||||
|
||||
pub fn get_pkg(_id: ~str,
|
||||
_vers: Option<~str>) -> result::Result<Pkg, ~str> {
|
||||
fail!("get_pkg not implemented");
|
||||
}
|
||||
|
||||
pub fn add_pkg(pkg: &Pkg) -> bool {
|
||||
note(fmt!("Would be adding package, but add_pkg is not yet implemented %s",
|
||||
pkg.to_str()));
|
||||
false
|
||||
}
|
||||
|
||||
// FIXME (#4432): Use workcache to only compile when needed
|
||||
pub fn compile_input(sysroot: Option<@Path>,
|
||||
pkg_id: &PkgId,
|
||||
@ -466,22 +332,20 @@ pub fn compile_input(sysroot: Option<@Path>,
|
||||
opt: bool,
|
||||
what: OutputType) -> bool {
|
||||
|
||||
let short_name = pkg_id.short_name_with_version();
|
||||
|
||||
assert!(in_file.components.len() > 1);
|
||||
let input = driver::file_input(copy *in_file);
|
||||
debug!("compile_input: %s / %?", in_file.to_str(), what);
|
||||
// tjc: by default, use the package ID name as the link name
|
||||
// not sure if we should support anything else
|
||||
|
||||
let binary = os::args()[0];
|
||||
let binary = @(copy os::args()[0]);
|
||||
let building_library = what == Lib;
|
||||
|
||||
let out_file = if building_library {
|
||||
out_dir.push(os::dll_filename(short_name))
|
||||
out_dir.push(os::dll_filename(pkg_id.short_name))
|
||||
}
|
||||
else {
|
||||
out_dir.push(short_name + match what {
|
||||
out_dir.push(pkg_id.short_name + match what {
|
||||
Test => ~"test", Bench => ~"bench", Main | Lib => ~""
|
||||
} + os::EXE_SUFFIX)
|
||||
};
|
||||
@ -561,24 +425,27 @@ pub fn compile_crate_from_input(input: &driver::input,
|
||||
debug!("Calling compile_upto, outputs = %?", outputs);
|
||||
let (crate, _) = driver::compile_upto(sess, copy cfg, input,
|
||||
driver::cu_parse, Some(outputs));
|
||||
let mut crate = crate;
|
||||
|
||||
debug!("About to inject link_meta info...");
|
||||
// Inject the inferred link_meta info if it's not already there
|
||||
// (assumes that name and vers are the only linkage metas)
|
||||
let mut crate_to_use = crate;
|
||||
|
||||
debug!("How many attrs? %?", attr::find_linkage_metas(crate.node.attrs).len());
|
||||
|
||||
if attr::find_linkage_metas(crate.node.attrs).is_empty() {
|
||||
crate_to_use = add_attrs(*crate, ~[mk_attr(@dummy_spanned(meta_list(@~"link",
|
||||
~[@dummy_spanned(meta_name_value(@~"name",
|
||||
mk_string_lit(@pkg_id.short_name))),
|
||||
@dummy_spanned(meta_name_value(@~"vers",
|
||||
mk_string_lit(@pkg_id.version.to_str())))])))]);
|
||||
crate = @codemap::respan(crate.span, ast::crate_ {
|
||||
attrs: ~[mk_attr(@dummy_spanned(
|
||||
meta_list(@~"link",
|
||||
~[@dummy_spanned(meta_name_value(@~"name",
|
||||
mk_string_lit(@(copy pkg_id.short_name)))),
|
||||
@dummy_spanned(meta_name_value(@~"vers",
|
||||
mk_string_lit(@(copy pkg_id.version.to_str()))))])))],
|
||||
..copy crate.node});
|
||||
}
|
||||
|
||||
driver::compile_rest(sess, cfg, what, Some(outputs), Some(crate_to_use));
|
||||
crate_to_use
|
||||
driver::compile_rest(sess, cfg, what, Some(outputs), Some(crate));
|
||||
crate
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -592,14 +459,6 @@ pub fn exe_suffix() -> ~str { ~".exe" }
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn exe_suffix() -> ~str { ~"" }
|
||||
|
||||
|
||||
/// Returns a copy of crate `c` with attributes `attrs` added to its
|
||||
/// attributes
|
||||
fn add_attrs(mut c: ast::crate, new_attrs: ~[attribute]) -> @ast::crate {
|
||||
c.node.attrs += new_attrs;
|
||||
@c
|
||||
}
|
||||
|
||||
// Called by build_crates
|
||||
// FIXME (#4432): Use workcache to only compile when needed
|
||||
pub fn compile_crate(sysroot: Option<@Path>, pkg_id: &PkgId,
|
||||
@ -619,16 +478,17 @@ pub fn compile_crate(sysroot: Option<@Path>, pkg_id: &PkgId,
|
||||
/// 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 {
|
||||
pub fn normalize(p_: RemotePath) -> LocalPath {
|
||||
let RemotePath(p) = p_;
|
||||
match p.filestem() {
|
||||
None => LocalPath(*p),
|
||||
None => LocalPath(p),
|
||||
Some(st) => {
|
||||
let replaced = str::replace(st, "-", "_");
|
||||
if replaced != st {
|
||||
LocalPath(p.with_filestem(replaced))
|
||||
}
|
||||
else {
|
||||
LocalPath(*p)
|
||||
LocalPath(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -671,7 +531,7 @@ pub struct LocalPath (Path);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{is_cmd, parse_name};
|
||||
use super::is_cmd;
|
||||
|
||||
#[test]
|
||||
fn test_is_cmd() {
|
||||
@ -686,9 +546,4 @@ mod test {
|
||||
assert!(is_cmd(~"unprefer"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_name() {
|
||||
assert!(parse_name(~"org.mozilla.servo").get() == ~"servo");
|
||||
assert!(parse_name(~"org. mozilla.servo 2131").is_err());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user