rustpkg::crate_id: Remove CrateId
There is no significant difference between `rustpkg::crate_id::CrateId` and `syntax::crateid::CrateId`. rustpkg's one is replaced by syntax's one.
This commit is contained in:
parent
df9067cd15
commit
a6a31ecb04
11 changed files with 409 additions and 495 deletions
|
@ -11,7 +11,6 @@
|
|||
use CtxMethods;
|
||||
use context::*;
|
||||
use crate::*;
|
||||
use crate_id::*;
|
||||
use package_source::*;
|
||||
use path_util::{platform_library_name, target_build_dir};
|
||||
use target::*;
|
||||
|
@ -26,6 +25,7 @@ use extra::arc::{Arc,RWArc};
|
|||
use extra::workcache;
|
||||
use extra::workcache::{Database, FreshnessMap};
|
||||
use extra::treemap::TreeMap;
|
||||
use syntax::crateid::CrateId;
|
||||
|
||||
// A little sad -- duplicated from rustc::back::*
|
||||
#[cfg(target_arch = "arm")]
|
||||
|
@ -78,20 +78,19 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context {
|
|||
workcache::Context::new_with_freshness(db, cfg, Arc::new(freshness))
|
||||
}
|
||||
|
||||
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Option<~str>,
|
||||
lib: Path) {
|
||||
build_lib_with_cfgs(sysroot, root, name, version, lib, ~[])
|
||||
pub fn build_lib(sysroot: Path, root: Path, name: ~str, lib: Path) {
|
||||
build_lib_with_cfgs(sysroot, root, name, lib, ~[])
|
||||
}
|
||||
|
||||
pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
|
||||
version: Option<~str>, lib: Path, cfgs: ~[~str]) {
|
||||
pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str, lib: Path, cfgs: ~[~str]) {
|
||||
let cx = default_context(sysroot, root.clone());
|
||||
let crate_id: CrateId = from_str(name).expect("valid crate id");
|
||||
let pkg_src = PkgSrc {
|
||||
source_workspace: root.clone(),
|
||||
build_in_destination: false,
|
||||
destination_workspace: root.clone(),
|
||||
start_dir: root.join_many(["src", name.as_slice()]),
|
||||
id: CrateId{ version: version, ..CrateId::new(name)},
|
||||
id: crate_id,
|
||||
// n.b. This assumes the package only has one crate
|
||||
libs: ~[mk_crate(lib)],
|
||||
mains: ~[],
|
||||
|
@ -101,20 +100,19 @@ pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
|
|||
pkg_src.build(&cx, cfgs, []);
|
||||
}
|
||||
|
||||
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Option<~str>,
|
||||
main: Path) {
|
||||
build_exe_with_cfgs(sysroot, root, name, version, main, ~[])
|
||||
pub fn build_exe(sysroot: Path, root: Path, name: ~str, main: Path) {
|
||||
build_exe_with_cfgs(sysroot, root, name, main, ~[])
|
||||
}
|
||||
|
||||
pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
|
||||
version: Option<~str>, main: Path, cfgs: ~[~str]) {
|
||||
pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str, main: Path, cfgs: ~[~str]) {
|
||||
let cx = default_context(sysroot, root.clone());
|
||||
let crate_id: CrateId = from_str(name).expect("valid crate id");
|
||||
let pkg_src = PkgSrc {
|
||||
source_workspace: root.clone(),
|
||||
build_in_destination: false,
|
||||
destination_workspace: root.clone(),
|
||||
start_dir: root.join_many(["src", name.as_slice()]),
|
||||
id: CrateId{ version: version, ..CrateId::new(name)},
|
||||
id: crate_id,
|
||||
libs: ~[],
|
||||
// n.b. This assumes the package only has one crate
|
||||
mains: ~[mk_crate(main)],
|
||||
|
@ -128,11 +126,10 @@ pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
|
|||
pub fn install_pkg(cx: &BuildContext,
|
||||
workspace: Path,
|
||||
name: ~str,
|
||||
version: Option<~str>,
|
||||
// For now, these inputs are assumed to be inputs to each of the crates
|
||||
more_inputs: ~[(~str, Path)]) { // pairs of Kind and Path
|
||||
let crateid = CrateId{ version: version, ..CrateId::new(name)};
|
||||
cx.install(PkgSrc::new(workspace.clone(), workspace, false, crateid),
|
||||
let crate_id: CrateId = from_str(name).expect("valid crate id");
|
||||
cx.install(PkgSrc::new(workspace.clone(), workspace, false, crate_id),
|
||||
&WhatToBuild{ build_type: Inferred,
|
||||
inputs_to_discover: more_inputs,
|
||||
sources: Everything });
|
||||
|
@ -156,10 +153,10 @@ pub fn build_library_in_workspace(exec: &mut workcache::Exec,
|
|||
let out_name = workspace_build_dir.join_many([package_name.to_str(),
|
||||
platform_library_name(output)]);
|
||||
// make paths absolute
|
||||
let crateid = CrateId::new(package_name);
|
||||
let crateid: CrateId = from_str(package_name).expect("valid crate id");
|
||||
let absolute_paths = paths.map(|s| {
|
||||
let whatever = workspace.join_many([~"src",
|
||||
crateid.to_str(),
|
||||
crateid.short_name_with_version(),
|
||||
s.to_owned()]);
|
||||
whatever.as_str().unwrap().to_owned()
|
||||
});
|
||||
|
@ -189,7 +186,7 @@ pub fn my_workspace(context: &Context, package_name: &str) -> Path {
|
|||
use bad_pkg_id = conditions::bad_pkg_id::cond;
|
||||
|
||||
// (this assumes no particular version is requested)
|
||||
let crateid = CrateId::new(package_name);
|
||||
let crateid = from_str(package_name).expect("valid crate id");
|
||||
let workspaces = pkg_parent_workspaces(context, &crateid);
|
||||
if workspaces.is_empty() {
|
||||
bad_pkg_id.raise((Path::new(package_name), package_name.to_owned()));
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// Useful conditions
|
||||
|
||||
pub use crate_id::CrateId;
|
||||
pub use syntax::crateid::CrateId;
|
||||
pub use std::io::FileStat;
|
||||
pub use std::io::process::ProcessExit;
|
||||
pub use std::path::Path;
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
// Copyright 2013 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.
|
||||
|
||||
use std::hash::Streaming;
|
||||
use syntax::crateid;
|
||||
use extra::hex::ToHex;
|
||||
use rustc::util::sha2::{Digest, Sha256};
|
||||
|
||||
/// Path-fragment identifier of a package such as
|
||||
/// 'github.com/graydon/test'; path must be a relative
|
||||
/// path with >=1 component.
|
||||
#[deriving(Clone)]
|
||||
pub struct CrateId {
|
||||
/// This is a path, on the local filesystem, referring to where the
|
||||
/// files for this package live. For example:
|
||||
/// github.com/mozilla/quux-whatever (it's assumed that if we're
|
||||
/// working with a package ID of this form, rustpkg has already cloned
|
||||
/// the sources into a local directory in the RUST_PATH).
|
||||
path: Path,
|
||||
/// Short name. This is the path's filestem, but we store it
|
||||
/// redundantly so as to not call get() everywhere (filestem() returns an
|
||||
/// option)
|
||||
/// The short name does not need to be a valid Rust identifier.
|
||||
/// Users can write: `extern mod foo = "...";` to get around the issue
|
||||
/// of package IDs whose short names aren't valid Rust identifiers.
|
||||
short_name: ~str,
|
||||
/// The requested package version.
|
||||
version: Option<~str>
|
||||
}
|
||||
|
||||
impl Eq for CrateId {
|
||||
fn eq(&self, other: &CrateId) -> bool {
|
||||
self.path == other.path && self.version == other.version
|
||||
}
|
||||
}
|
||||
|
||||
impl CrateId {
|
||||
pub fn version_or_default<'a>(&'a self) -> &'a str {
|
||||
match self.version {
|
||||
Some(ref ver) => ver.as_slice(),
|
||||
None => "0.0"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(s: &str) -> CrateId {
|
||||
use conditions::bad_pkg_id::cond;
|
||||
|
||||
let raw_crateid: Option<crateid::CrateId> = from_str(s);
|
||||
if raw_crateid.is_none() {
|
||||
return cond.raise((Path::new(s), ~"bad crateid"))
|
||||
}
|
||||
let raw_crateid = raw_crateid.unwrap();
|
||||
let crateid::CrateId { path, name, version } = raw_crateid;
|
||||
let path = Path::new(path);
|
||||
|
||||
CrateId {
|
||||
path: path,
|
||||
short_name: name,
|
||||
version: version
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_crate_id_str(&self) -> ~str {
|
||||
format!("{}\\#{}", self.path.as_str().unwrap(), self.version_or_default())
|
||||
}
|
||||
|
||||
pub fn to_lib_name(&self) -> ~str {
|
||||
format!("{}-{}-{}", self.short_name, self.hash(), self.version_or_default())
|
||||
}
|
||||
|
||||
pub fn hash(&self) -> ~str {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.reset();
|
||||
hasher.input_str(self.to_crate_id_str());
|
||||
let hash = hasher.result_bytes().to_hex();
|
||||
hash.slice_chars(0, 8).to_owned()
|
||||
}
|
||||
|
||||
pub fn short_name_with_version(&self) -> ~str {
|
||||
format!("{}-{}", self.short_name, self.version_or_default())
|
||||
}
|
||||
|
||||
/// True if the ID has multiple components
|
||||
pub fn is_complex(&self) -> bool {
|
||||
self.short_name.as_bytes() != self.path.as_vec()
|
||||
}
|
||||
|
||||
pub fn prefixes(&self) -> Prefixes {
|
||||
prefixes(&self.path)
|
||||
}
|
||||
|
||||
// This is the workcache function name for the *installed*
|
||||
// binaries for this package (as opposed to the built ones,
|
||||
// which are per-crate).
|
||||
pub fn install_tag(&self) -> ~str {
|
||||
format!("install({})", self.to_str())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prefixes(p: &Path) -> Prefixes {
|
||||
Prefixes {
|
||||
components: p.str_components().map(|x|x.unwrap().to_owned()).to_owned_vec(),
|
||||
remaining: ~[]
|
||||
}
|
||||
}
|
||||
|
||||
struct Prefixes {
|
||||
priv components: ~[~str],
|
||||
priv remaining: ~[~str]
|
||||
}
|
||||
|
||||
impl Iterator<(Path, Path)> for Prefixes {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<(Path, Path)> {
|
||||
if self.components.len() <= 1 {
|
||||
None
|
||||
}
|
||||
else {
|
||||
let last = self.components.pop().unwrap();
|
||||
self.remaining.unshift(last);
|
||||
// converting to str and then back is a little unfortunate
|
||||
Some((Path::new(self.components.connect("/")),
|
||||
Path::new(self.remaining.connect("/"))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToStr for CrateId {
|
||||
fn to_str(&self) -> ~str {
|
||||
// should probably use the filestem and not the whole path
|
||||
format!("{}-{}", self.path.as_str().unwrap(), self.version_or_default())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write<W: Writer>(writer: &mut W, string: &str) {
|
||||
writer.write(string.as_bytes());
|
||||
}
|
|
@ -11,10 +11,10 @@
|
|||
// Listing installed packages
|
||||
|
||||
use rustc::metadata::filesearch::rust_path;
|
||||
use path_util::*;
|
||||
use std::os;
|
||||
use std::io;
|
||||
use std::io::fs;
|
||||
use syntax::crateid::CrateId;
|
||||
|
||||
pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool {
|
||||
let workspaces = rust_path();
|
||||
|
@ -28,7 +28,8 @@ pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool {
|
|||
match exec.filestem_str() {
|
||||
None => (),
|
||||
Some(exec_path) => {
|
||||
if !f(&CrateId::new(exec_path)) {
|
||||
let crate_id = from_str(exec_path).expect("valid crate id");
|
||||
if !f(&crate_id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +51,8 @@ pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool {
|
|||
let rel_path = rel_p.join(basename);
|
||||
rel_path.display().with_str(|s| {
|
||||
debug!("Rel name: {}", s);
|
||||
f(&CrateId::new(s));
|
||||
let crate_id = from_str(s).expect("valid crate id");
|
||||
f(&crate_id);
|
||||
});
|
||||
}
|
||||
None => ()
|
||||
|
|
|
@ -33,6 +33,7 @@ use rustc::metadata::filesearch;
|
|||
use rustc::metadata::filesearch::rust_path;
|
||||
use rustc::util::sha2;
|
||||
use syntax::{ast, diagnostic};
|
||||
use syntax::crateid::CrateId;
|
||||
use messages::{error, warn, note};
|
||||
use parse_args::{ParseResult, parse_args};
|
||||
use path_util::{build_pkg_id_in_workspace, built_test_in_workspace};
|
||||
|
@ -46,7 +47,6 @@ use context::{BuildContext, Trans, Nothing, Pretty, Analysis,
|
|||
LLVMAssemble, LLVMCompileBitcode};
|
||||
use context::{Command, BuildCmd, CleanCmd, DoCmd, HelpCmd, InfoCmd, InstallCmd, ListCmd,
|
||||
PreferCmd, TestCmd, InitCmd, UninstallCmd, UnpreferCmd};
|
||||
use crate_id::CrateId;
|
||||
use package_source::PkgSrc;
|
||||
use target::{WhatToBuild, Everything, is_lib, is_main, is_test, is_bench};
|
||||
use target::{Main, Tests, MaybeCustom, Inferred, JustOne};
|
||||
|
@ -60,7 +60,6 @@ mod crate;
|
|||
pub mod exit_codes;
|
||||
mod installed_packages;
|
||||
mod messages;
|
||||
pub mod crate_id;
|
||||
pub mod package_source;
|
||||
mod parse_args;
|
||||
mod path_util;
|
||||
|
@ -103,7 +102,7 @@ impl<'a> PkgScript<'a> {
|
|||
workspace: &Path,
|
||||
id: &'a CrateId) -> PkgScript<'a> {
|
||||
// Get the executable name that was invoked
|
||||
let binary = os::args()[0].to_owned();
|
||||
let binary = os::args()[0];
|
||||
// Build the rustc session data structures to pass
|
||||
// to the compiler
|
||||
debug!("pkgscript parse: {}", sysroot.display());
|
||||
|
@ -244,7 +243,7 @@ impl CtxMethods for BuildContext {
|
|||
match cwd_to_workspace() {
|
||||
None if dir_has_crate_file(&cwd) => {
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let crateid = CrateId::new(cwd.filename_str().unwrap());
|
||||
let crateid = from_str(cwd.filename_str().unwrap()).expect("valid crate id");
|
||||
let mut pkg_src = PkgSrc::new(cwd, default_workspace(), true, crateid);
|
||||
self.build(&mut pkg_src, what);
|
||||
match pkg_src {
|
||||
|
@ -269,7 +268,7 @@ impl CtxMethods for BuildContext {
|
|||
} else {
|
||||
// The package id is presumed to be the first command-line
|
||||
// argument
|
||||
let crateid = CrateId::new(args[0].clone());
|
||||
let crateid = from_str(args[0]).expect("valid crate id");
|
||||
let mut dest_ws = default_workspace();
|
||||
each_pkg_parent_workspace(&self.context, &crateid, |workspace| {
|
||||
debug!("found pkg {} in workspace {}, trying to build",
|
||||
|
@ -308,7 +307,7 @@ impl CtxMethods for BuildContext {
|
|||
else {
|
||||
// The package id is presumed to be the first command-line
|
||||
// argument
|
||||
let crateid = CrateId::new(args[0].clone());
|
||||
let crateid = from_str(args[0]).expect("valid crate id");
|
||||
self.clean(&cwd, &crateid); // tjc: should use workspace, not cwd
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +340,7 @@ impl CtxMethods for BuildContext {
|
|||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
|
||||
let inferred_crateid =
|
||||
CrateId::new(cwd.filename_str().unwrap());
|
||||
from_str(cwd.filename_str().unwrap()).expect("valid crate id");
|
||||
self.install(PkgSrc::new(cwd, default_workspace(),
|
||||
true, inferred_crateid),
|
||||
&WhatToBuild::new(MaybeCustom, Everything));
|
||||
|
@ -357,7 +356,7 @@ impl CtxMethods for BuildContext {
|
|||
else {
|
||||
// The package id is presumed to be the first command-line
|
||||
// argument
|
||||
let crateid = CrateId::new(args[0]);
|
||||
let crateid = from_str(args[0]).expect("valid crate id");
|
||||
let workspaces = pkg_parent_workspaces(&self.context, &crateid);
|
||||
debug!("package ID = {}, found it in {:?} workspaces",
|
||||
crateid.to_str(), workspaces.len());
|
||||
|
@ -383,7 +382,7 @@ impl CtxMethods for BuildContext {
|
|||
ListCmd => {
|
||||
println!("Installed packages:");
|
||||
installed_packages::list_installed_packages(|pkg_id| {
|
||||
pkg_id.path.display().with_str(|s| println!("{}", s));
|
||||
println!("{}", pkg_id.path);
|
||||
true
|
||||
});
|
||||
}
|
||||
|
@ -420,7 +419,7 @@ impl CtxMethods for BuildContext {
|
|||
return usage::uninstall();
|
||||
}
|
||||
|
||||
let crateid = CrateId::new(args[0]);
|
||||
let crateid = from_str(args[0]).expect("valid crate id");
|
||||
if !installed_packages::package_is_installed(&crateid) {
|
||||
warn(format!("Package {} doesn't seem to be installed! \
|
||||
Doing nothing.", args[0]));
|
||||
|
@ -458,24 +457,24 @@ impl CtxMethods for BuildContext {
|
|||
let workspace = pkg_src.source_workspace.clone();
|
||||
let crateid = pkg_src.id.clone();
|
||||
|
||||
let path = crateid.path.as_slice();
|
||||
debug!("build: workspace = {} (in Rust path? {:?} is git dir? {:?} \
|
||||
crateid = {} pkgsrc start_dir = {}", workspace.display(),
|
||||
in_rust_path(&workspace), is_git_dir(&workspace.join(&crateid.path)),
|
||||
in_rust_path(&workspace), is_git_dir(&workspace.join(path)),
|
||||
crateid.to_str(), pkg_src.start_dir.display());
|
||||
debug!("build: what to build = {:?}", what_to_build);
|
||||
|
||||
// If workspace isn't in the RUST_PATH, and it's a git repo,
|
||||
// then clone it into the first entry in RUST_PATH, and repeat
|
||||
if !in_rust_path(&workspace) && is_git_dir(&workspace.join(&crateid.path)) {
|
||||
if !in_rust_path(&workspace) && is_git_dir(&workspace.join(path)) {
|
||||
let mut out_dir = default_workspace().join("src");
|
||||
out_dir.push(&crateid.path);
|
||||
let git_result = source_control::safe_git_clone(&workspace.join(&crateid.path),
|
||||
out_dir.push(path);
|
||||
let git_result = source_control::safe_git_clone(&workspace.join(path),
|
||||
&crateid.version,
|
||||
&out_dir);
|
||||
match git_result {
|
||||
CheckedOutSources => make_read_only(&out_dir),
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
_ => cond.raise((crateid.path.as_str().unwrap().to_owned(), out_dir.clone()))
|
||||
_ => cond.raise((path.to_owned(), out_dir.clone()))
|
||||
};
|
||||
let default_ws = default_workspace();
|
||||
debug!("Calling build recursively with {:?} and {:?}", default_ws.display(),
|
||||
|
@ -652,7 +651,8 @@ impl CtxMethods for BuildContext {
|
|||
target_exec.display(), target_lib,
|
||||
maybe_executable, maybe_library);
|
||||
|
||||
self.workcache_context.with_prep(id.install_tag(), |prep| {
|
||||
let install_tag = format!("install({}-{})", id.path, id.version_or_default());
|
||||
self.workcache_context.with_prep(install_tag, |prep| {
|
||||
for ee in maybe_executable.iter() {
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
prep.declare_input("binary",
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
extern mod extra;
|
||||
|
||||
use target::*;
|
||||
use crate_id::CrateId;
|
||||
use std::io;
|
||||
use std::io::fs;
|
||||
use std::os;
|
||||
|
@ -27,7 +26,7 @@ use workcache_support;
|
|||
use workcache_support::{digest_only_date, digest_file_with_date, crate_tag};
|
||||
use extra::workcache;
|
||||
use extra::treemap::TreeMap;
|
||||
|
||||
use syntax::crateid::CrateId;
|
||||
use rustc::driver::session;
|
||||
|
||||
// An enumeration of the unpacked source of a package workspace.
|
||||
|
@ -68,12 +67,38 @@ impl ToStr for PkgSrc {
|
|||
}
|
||||
}
|
||||
condition! {
|
||||
// #6009: should this be pub or not, when #8215 is fixed?
|
||||
build_err: (~str) -> ~str;
|
||||
}
|
||||
|
||||
impl PkgSrc {
|
||||
fn prefixes(p: &Path) -> Prefixes {
|
||||
Prefixes {
|
||||
components: p.str_components().map(|x|x.unwrap().to_owned()).to_owned_vec(),
|
||||
remaining: ~[]
|
||||
}
|
||||
}
|
||||
|
||||
struct Prefixes {
|
||||
priv components: ~[~str],
|
||||
priv remaining: ~[~str]
|
||||
}
|
||||
|
||||
impl Iterator<(Path, Path)> for Prefixes {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<(Path, Path)> {
|
||||
if self.components.len() <= 1 {
|
||||
None
|
||||
}
|
||||
else {
|
||||
let last = self.components.pop().unwrap();
|
||||
self.remaining.unshift(last);
|
||||
// converting to str and then back is a little unfortunate
|
||||
Some((Path::new(self.components.connect("/")),
|
||||
Path::new(self.remaining.connect("/"))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PkgSrc {
|
||||
pub fn new(mut source_workspace: Path,
|
||||
destination_workspace: Path,
|
||||
use_rust_path_hack: bool,
|
||||
|
@ -98,21 +123,22 @@ impl PkgSrc {
|
|||
} else {
|
||||
// We search for sources under both src/ and build/ , because build/ is where
|
||||
// automatically-checked-out sources go.
|
||||
let path = Path::new(id.path.as_slice());
|
||||
let mut result = source_workspace.join("src");
|
||||
result.push(&id.path.dir_path());
|
||||
result.push(&path.dir_path());
|
||||
result.push(id.short_name_with_version());
|
||||
to_try.push(result);
|
||||
let mut result = source_workspace.join("src");
|
||||
result.push(&id.path);
|
||||
result.push(&path);
|
||||
to_try.push(result);
|
||||
|
||||
let mut result = build_dir.join("src");
|
||||
result.push(&id.path.dir_path());
|
||||
result.push(&path.dir_path());
|
||||
result.push(id.short_name_with_version());
|
||||
to_try.push(result.clone());
|
||||
output_names.push(result);
|
||||
let mut other_result = build_dir.join("src");
|
||||
other_result.push(&id.path);
|
||||
other_result.push(&path);
|
||||
to_try.push(other_result.clone());
|
||||
output_names.push(other_result);
|
||||
|
||||
|
@ -132,9 +158,10 @@ impl PkgSrc {
|
|||
None => {
|
||||
// See if any of the prefixes of this package ID form a valid package ID
|
||||
// That is, is this a package ID that points into the middle of a workspace?
|
||||
for (prefix, suffix) in id.prefixes() {
|
||||
let crate_id = CrateId::new(prefix.as_str().unwrap());
|
||||
let path = build_dir.join(&crate_id.path);
|
||||
for (prefix, suffix) in prefixes(&Path::new(id.path.as_slice())) {
|
||||
let crate_id: Option<CrateId> = from_str(prefix.as_str().unwrap());
|
||||
let crate_id = crate_id.expect("valid crate id");
|
||||
let path = build_dir.join(crate_id.path.as_slice());
|
||||
debug!("in loop: checking if {} is a directory", path.display());
|
||||
if path.is_dir() {
|
||||
let ps = PkgSrc::new(source_workspace,
|
||||
|
@ -163,7 +190,7 @@ impl PkgSrc {
|
|||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Ok, no prefixes work, so try fetching from git
|
||||
|
@ -179,11 +206,12 @@ impl PkgSrc {
|
|||
}
|
||||
match ok_d {
|
||||
Some(ref d) => {
|
||||
if d.is_ancestor_of(&id.path)
|
||||
|| d.is_ancestor_of(&versionize(&id.path, &id.version)) {
|
||||
let path = Path::new(id.path.as_slice());
|
||||
if d.is_ancestor_of(&path)
|
||||
|| d.is_ancestor_of(&versionize(id.path, &id.version)) {
|
||||
// Strip off the package ID
|
||||
source_workspace = d.clone();
|
||||
for _ in id.path.components() {
|
||||
for _ in path.components() {
|
||||
source_workspace.pop();
|
||||
}
|
||||
// Strip off the src/ part
|
||||
|
@ -226,8 +254,7 @@ impl PkgSrc {
|
|||
exist, and couldn't interpret it as a URL fragment"))
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cond.raise((id.clone(),
|
||||
~"supplied path for package dir does not \
|
||||
exist, and couldn't interpret it as a URL fragment"))
|
||||
|
@ -268,24 +295,25 @@ impl PkgSrc {
|
|||
use conditions::git_checkout_failed::cond;
|
||||
|
||||
let cwd = os::getcwd();
|
||||
let path = Path::new(crateid.path.as_slice());
|
||||
debug!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}",
|
||||
crateid.to_str(), crateid.path.display(),
|
||||
crateid.to_str(), crateid.path,
|
||||
cwd.display(),
|
||||
crateid.path.exists());
|
||||
path.exists());
|
||||
|
||||
match safe_git_clone(&crateid.path, &crateid.version, local) {
|
||||
match safe_git_clone(&path, &crateid.version, local) {
|
||||
CheckedOutSources => {
|
||||
make_read_only(local);
|
||||
Some(local.clone())
|
||||
}
|
||||
DirToUse(clone_target) => {
|
||||
if crateid.path.components().nth(1).is_none() {
|
||||
if path.components().nth(1).is_none() {
|
||||
// If a non-URL, don't bother trying to fetch
|
||||
return None;
|
||||
}
|
||||
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let url = format!("https://{}", crateid.path.as_str().unwrap());
|
||||
let url = format!("https://{}", path.as_str().unwrap());
|
||||
debug!("Fetching package: git clone {} {} [version={}]",
|
||||
url, clone_target.display(), crateid.version_or_default());
|
||||
|
||||
|
@ -345,7 +373,7 @@ impl PkgSrc {
|
|||
use conditions::missing_pkg_files::cond;
|
||||
|
||||
let prefix = self.start_dir.components().len();
|
||||
debug!("Matching against {}", self.id.short_name);
|
||||
debug!("Matching against {}", self.id.name);
|
||||
for pth in fs::walk_dir(&self.start_dir) {
|
||||
let maybe_known_crate_set = match pth.filename_str() {
|
||||
Some(filename) if filter(filename) => match filename {
|
||||
|
|
|
@ -12,9 +12,8 @@
|
|||
|
||||
#[allow(dead_code)];
|
||||
|
||||
pub use crate_id::CrateId;
|
||||
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
|
||||
pub use version::{Version, split_version, split_version_general, try_parsing_version};
|
||||
pub use version::{Version, split_version_general};
|
||||
pub use rustc::metadata::filesearch::rust_path;
|
||||
|
||||
use std::libc;
|
||||
|
@ -22,6 +21,9 @@ use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
|
|||
use std::os;
|
||||
use std::io;
|
||||
use std::io::fs;
|
||||
use extra::hex::ToHex;
|
||||
use syntax::crateid::CrateId;
|
||||
use rustc::util::sha2::{Digest, Sha256};
|
||||
use rustc::metadata::filesearch::{libdir, relative_target_lib_path};
|
||||
use rustc::driver::driver::host_triple;
|
||||
use messages::*;
|
||||
|
@ -77,13 +79,13 @@ pub fn workspace_contains_crate_id_(crateid: &CrateId, workspace: &Path,
|
|||
let mut found = None;
|
||||
for p in fs::walk_dir(&src_dir) {
|
||||
if p.is_dir() {
|
||||
if p == src_dir.join(&crateid.path) || {
|
||||
if p == src_dir.join(crateid.path.as_slice()) || {
|
||||
let pf = p.filename_str();
|
||||
pf.iter().any(|&g| {
|
||||
match split_version_general(g, '-') {
|
||||
None => false,
|
||||
Some((ref might_match, ref vers)) => {
|
||||
*might_match == crateid.short_name
|
||||
*might_match == crateid.name
|
||||
&& (crateid.version == *vers || crateid.version == None)
|
||||
}
|
||||
}
|
||||
|
@ -178,33 +180,39 @@ pub fn built_library_in_workspace(crateid: &CrateId, workspace: &Path) -> Option
|
|||
/// Does the actual searching stuff
|
||||
pub fn installed_library_in_workspace(crate_id: &CrateId, workspace: &Path) -> Option<Path> {
|
||||
// This could break once we're handling multiple versions better -- I should add a test for it
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
match crate_id.path.filename_str() {
|
||||
let path = Path::new(crate_id.path.as_slice());
|
||||
match path.filename_str() {
|
||||
None => None,
|
||||
Some(_short_name) => library_in_workspace(crate_id, Install, workspace)
|
||||
}
|
||||
}
|
||||
|
||||
/// `workspace` is used to figure out the directory to search.
|
||||
/// `short_name` is taken as the link name of the library.
|
||||
/// `name` is taken as the link name of the library.
|
||||
pub fn library_in_workspace(crate_id: &CrateId, where: Target, workspace: &Path) -> Option<Path> {
|
||||
debug!("library_in_workspace: checking whether a library named {} exists",
|
||||
crate_id.short_name);
|
||||
crate_id.name);
|
||||
|
||||
let dir_to_search = match where {
|
||||
Build => target_build_dir(workspace).join(&crate_id.path),
|
||||
Build => target_build_dir(workspace).join(crate_id.path.as_slice()),
|
||||
Install => target_lib_dir(workspace)
|
||||
};
|
||||
|
||||
library_in(crate_id, &dir_to_search)
|
||||
}
|
||||
|
||||
pub fn system_library(sysroot: &Path, crate_id: &str) -> Option<Path> {
|
||||
library_in(&CrateId::new(crate_id), &sysroot.join(relative_target_lib_path(host_triple())))
|
||||
pub fn system_library(sysroot: &Path, crate_id: &CrateId) -> Option<Path> {
|
||||
library_in(crate_id, &sysroot.join(relative_target_lib_path(host_triple())))
|
||||
}
|
||||
|
||||
fn library_in(crate_id: &CrateId, dir_to_search: &Path) -> Option<Path> {
|
||||
let lib_name = crate_id.to_lib_name();
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.reset();
|
||||
hasher.input_str(crate_id.to_str());
|
||||
let hash = hasher.result_bytes().to_hex();
|
||||
let hash = hash.slice_chars(0, 8);
|
||||
|
||||
let lib_name = format!("{}-{}-{}", crate_id.name, hash, crate_id.version_or_default());
|
||||
let filenames = [
|
||||
format!("{}{}.{}", "lib", lib_name, "rlib"),
|
||||
format!("{}{}{}", os::consts::DLL_PREFIX, lib_name, os::consts::DLL_SUFFIX),
|
||||
|
@ -219,7 +227,7 @@ fn library_in(crate_id: &CrateId, dir_to_search: &Path) -> Option<Path> {
|
|||
}
|
||||
}
|
||||
debug!("warning: library_in_workspace didn't find a library in {} for {}",
|
||||
dir_to_search.display(), crate_id.short_name);
|
||||
dir_to_search.display(), crate_id.to_str());
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -271,7 +279,7 @@ fn target_file_in_workspace(crateid: &CrateId, workspace: &Path,
|
|||
// Artifacts in the build directory live in a package-ID-specific subdirectory,
|
||||
// but installed ones don't.
|
||||
let result = match (where, what) {
|
||||
(Build, _) => target_build_dir(workspace).join(&crateid.path),
|
||||
(Build, _) => target_build_dir(workspace).join(crateid.path.as_slice()),
|
||||
(Install, Lib) => target_lib_dir(workspace),
|
||||
(Install, _) => target_bin_dir(workspace)
|
||||
};
|
||||
|
@ -287,7 +295,7 @@ fn target_file_in_workspace(crateid: &CrateId, workspace: &Path,
|
|||
/// Creates it if it doesn't exist.
|
||||
pub fn build_pkg_id_in_workspace(crateid: &CrateId, workspace: &Path) -> Path {
|
||||
let mut result = target_build_dir(workspace);
|
||||
result.push(&crateid.path);
|
||||
result.push(crateid.path.as_slice());
|
||||
debug!("Creating build dir {} for package id {}", result.display(),
|
||||
crateid.to_str());
|
||||
fs::mkdir_recursive(&result, io::UserRWX);
|
||||
|
@ -297,24 +305,24 @@ pub fn build_pkg_id_in_workspace(crateid: &CrateId, 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, where: Target,
|
||||
pkg_id: &CrateId, workspace: Path) -> Path {
|
||||
let short_name_with_version = pkg_id.short_name_with_version();
|
||||
crate_id: &CrateId, workspace: Path) -> Path {
|
||||
let short_name_with_version = crate_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 = match where {
|
||||
// If we're installing, it just goes under <workspace>...
|
||||
Install => workspace,
|
||||
// and if we're just building, it goes in a package-specific subdir
|
||||
Build => workspace.join(&pkg_id.path)
|
||||
Build => workspace.join(crate_id.path.as_slice())
|
||||
};
|
||||
debug!("[{:?}:{:?}] mk_output_path: short_name = {}, path = {}", what, where,
|
||||
if what == Lib { short_name_with_version.clone() } else { pkg_id.short_name.clone() },
|
||||
debug!("[{:?}:{:?}] mk_output_path: name = {}, path = {}", what, where,
|
||||
if what == Lib { short_name_with_version.clone() } else { crate_id.name.clone() },
|
||||
dir.display());
|
||||
let mut output_path = match what {
|
||||
// this code is duplicated from elsewhere; fix this
|
||||
Lib => dir.join(os::dll_filename(short_name_with_version)),
|
||||
// executable names *aren't* versioned
|
||||
_ => dir.join(format!("{}{}{}", pkg_id.short_name,
|
||||
_ => dir.join(format!("{}{}{}", crate_id.name,
|
||||
match what {
|
||||
Test => "test",
|
||||
Bench => "bench",
|
||||
|
@ -361,11 +369,12 @@ fn dir_has_file(dir: &Path, file: &str) -> bool {
|
|||
|
||||
pub fn find_dir_using_rust_path_hack(p: &CrateId) -> Option<Path> {
|
||||
let rp = rust_path();
|
||||
let path = Path::new(p.path.as_slice());
|
||||
for dir in rp.iter() {
|
||||
// Require that the parent directory match the package ID
|
||||
// Note that this only matches if the package ID being searched for
|
||||
// has a name that's a single component
|
||||
if dir.ends_with_path(&p.path) || dir.ends_with_path(&versionize(&p.path, &p.version)) {
|
||||
if dir.ends_with_path(&path) || dir.ends_with_path(&versionize(p.path, &p.version)) {
|
||||
debug!("In find_dir_using_rust_path_hack: checking dir {}", dir.display());
|
||||
if dir_has_crate_file(dir) {
|
||||
debug!("Did find id {} in dir {}", p.to_str(), dir.display());
|
||||
|
@ -387,7 +396,8 @@ pub fn user_set_rust_path() -> bool {
|
|||
}
|
||||
|
||||
/// Append the version string onto the end of the path's filename
|
||||
pub fn versionize(p: &Path, v: &Version) -> Path {
|
||||
pub fn versionize(p: &str, v: &Version) -> Path {
|
||||
let p = Path::new(p);
|
||||
let q = p.filename().expect("path is a directory");
|
||||
let mut q = q.to_owned();
|
||||
q.push('-' as u8);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,6 +10,10 @@
|
|||
|
||||
#[allow(dead_code)];
|
||||
|
||||
pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename};
|
||||
pub use target::{Target, Build, Install};
|
||||
pub use target::{lib_name_of, lib_crate_filename, WhatToBuild, MaybeCustom, Inferred};
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::libc;
|
||||
use std::os;
|
||||
|
@ -17,7 +21,7 @@ use std::io;
|
|||
use std::io::fs;
|
||||
use extra::workcache;
|
||||
use rustc::metadata::creader::Loader;
|
||||
use rustc::driver::{driver, session};
|
||||
use extra::treemap::TreeMap;
|
||||
use extra::getopts::groups::getopts;
|
||||
use syntax;
|
||||
use syntax::codemap::{DUMMY_SP, Spanned};
|
||||
|
@ -28,19 +32,16 @@ use syntax::attr::AttrMetaMethods;
|
|||
use syntax::fold::Folder;
|
||||
use syntax::visit::Visitor;
|
||||
use syntax::util::small_vector::SmallVector;
|
||||
use syntax::crateid::CrateId;
|
||||
use rustc::back::link::OutputTypeExe;
|
||||
use rustc::back::link;
|
||||
use rustc::driver::{driver, session};
|
||||
use CtxMethods;
|
||||
use context::{in_target, StopBefore, Link, Assemble, BuildContext};
|
||||
use crate_id::CrateId;
|
||||
use package_source::PkgSrc;
|
||||
use workspace::pkg_parent_workspaces;
|
||||
use path_util::{system_library, target_build_dir};
|
||||
use path_util::{default_workspace, built_library_in_workspace};
|
||||
pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename};
|
||||
pub use target::{Target, Build, Install};
|
||||
use extra::treemap::TreeMap;
|
||||
pub use target::{lib_name_of, lib_crate_filename, WhatToBuild, MaybeCustom, Inferred};
|
||||
use workcache_support::{digest_file_with_date, digest_only_date};
|
||||
use messages::error;
|
||||
|
||||
|
@ -177,11 +178,11 @@ pub fn compile_input(context: &BuildContext,
|
|||
// not sure if we should support anything else
|
||||
|
||||
let mut out_dir = target_build_dir(workspace);
|
||||
out_dir.push(&crate_id.path);
|
||||
out_dir.push(crate_id.path.as_slice());
|
||||
// Make the output directory if it doesn't exist already
|
||||
fs::mkdir_recursive(&out_dir, io::UserRWX);
|
||||
|
||||
let binary = os::args()[0].to_owned();
|
||||
let binary = os::args()[0];
|
||||
|
||||
debug!("flags: {}", flags.connect(" "));
|
||||
debug!("cfgs: {}", cfgs.connect(" "));
|
||||
|
@ -312,7 +313,7 @@ pub fn compile_input(context: &BuildContext,
|
|||
if !attr::contains_name(crate.attrs, "crate_id") {
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let crateid_attr =
|
||||
attr::mk_name_value_item_str(@"crate_id", crate_id.to_crate_id_str().to_managed());
|
||||
attr::mk_name_value_item_str(@"crate_id", crate_id.to_str().to_managed());
|
||||
|
||||
debug!("crateid attr: {:?}", crateid_attr);
|
||||
crate.attrs.push(attr::mk_attr(crateid_attr));
|
||||
|
@ -441,7 +442,7 @@ pub fn compile_crate(ctxt: &BuildContext,
|
|||
opt: session::OptLevel,
|
||||
what: OutputType) -> Option<Path> {
|
||||
debug!("compile_crate: crate={}, workspace={}", crate.display(), workspace.display());
|
||||
debug!("compile_crate: short_name = {}, flags =...", crate_id.to_str());
|
||||
debug!("compile_crate: name = {}, flags =...", crate_id.to_str());
|
||||
for fl in flags.iter() {
|
||||
debug!("+++ {}", *fl);
|
||||
}
|
||||
|
@ -470,8 +471,9 @@ impl<'a> CrateInstaller<'a> {
|
|||
None => self.sess.str_of(lib_ident)
|
||||
};
|
||||
debug!("Finding and installing... {}", lib_name);
|
||||
let crate_id: CrateId = from_str(lib_name).expect("valid crate id");
|
||||
// Check standard Rust library path first
|
||||
let whatever = system_library(&self.context.sysroot_to_use(), lib_name);
|
||||
let whatever = system_library(&self.context.sysroot_to_use(), &crate_id);
|
||||
debug!("system library returned {:?}", whatever);
|
||||
match whatever {
|
||||
Some(ref installed_path) => {
|
||||
|
@ -491,10 +493,8 @@ impl<'a> CrateInstaller<'a> {
|
|||
}
|
||||
None => {
|
||||
// FIXME #8711: need to parse version out of path_opt
|
||||
debug!("Trying to install library {}, rebuilding it",
|
||||
lib_name.to_str());
|
||||
debug!("Trying to install library {}, rebuilding it", crate_id.to_str());
|
||||
// Try to install it
|
||||
let crate_id = CrateId::new(lib_name);
|
||||
// Find all the workspaces in the RUST_PATH that contain this package.
|
||||
let workspaces = pkg_parent_workspaces(&self.context.context,
|
||||
&crate_id);
|
||||
|
@ -526,8 +526,8 @@ impl<'a> CrateInstaller<'a> {
|
|||
// Nonexistent package? Then print a better error
|
||||
error(format!("Package {} depends on {}, but I don't know \
|
||||
how to find it",
|
||||
self.parent.path.display(),
|
||||
crate_id.path.display()));
|
||||
self.parent.path,
|
||||
crate_id.path));
|
||||
fail!()
|
||||
}).inside(|| {
|
||||
PkgSrc::new(source_workspace.clone(),
|
||||
|
|
|
@ -11,12 +11,11 @@
|
|||
// rustpkg utilities having to do with workspaces
|
||||
|
||||
use std::os;
|
||||
use std::path::Path;
|
||||
use context::Context;
|
||||
use path_util::{workspace_contains_crate_id, find_dir_using_rust_path_hack, default_workspace};
|
||||
use path_util::rust_path;
|
||||
use util::option_to_vec;
|
||||
use crate_id::CrateId;
|
||||
use syntax::crateid::CrateId;
|
||||
|
||||
pub fn each_pkg_parent_workspace(cx: &Context,
|
||||
crateid: &CrateId,
|
||||
|
@ -29,7 +28,7 @@ pub fn each_pkg_parent_workspace(cx: &Context,
|
|||
// tjc: make this a condition
|
||||
fail!("Package {} not found in any of \
|
||||
the following workspaces: {}",
|
||||
crateid.path.display(),
|
||||
crateid.path,
|
||||
rust_path().map(|p| p.display().to_str()).to_str());
|
||||
}
|
||||
for ws in workspaces.iter() {
|
||||
|
@ -64,7 +63,8 @@ pub fn cwd_to_workspace() -> Option<(Path, CrateId)> {
|
|||
let rel = cwd.path_relative_from(&srcpath);
|
||||
let rel_s = rel.as_ref().and_then(|p|p.as_str());
|
||||
if rel_s.is_some() {
|
||||
return Some((path, CrateId::new(rel_s.unwrap())));
|
||||
let crate_id = from_str(rel_s.unwrap()).expect("valid crate id");
|
||||
return Some((path, crate_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,11 @@ impl FromStr for CrateId {
|
|||
};
|
||||
|
||||
let version = if !hash_version.is_empty() {
|
||||
Some(hash_version.to_owned())
|
||||
if hash_version == "0.0" {
|
||||
None
|
||||
} else {
|
||||
Some(hash_version.to_owned())
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -93,6 +97,10 @@ impl CrateId {
|
|||
Some(ref version) => version.as_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn short_name_with_version(&self) -> ~str {
|
||||
format!("{}-{}", self.name, self.version_or_default())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Reference in a new issue