Skip to content

Commit 2b62371

Browse files
committed
auto merge of #11478 : klutzy/rust/rustpkg-crate-id, r=cmr
This patchset consists of three parts: - rustpkg doesn't guess crate version if it is not given by user. - `rustpkg::version::Version` is replaced by `Option<~str>`. It removes some semantic versioning portions which is not currently used. (cc #8405 and #11396) `rustpkg::crate_id::CrateId` is also replaced by `syntax::crateid::CrateId`. - rustpkg now computes hash to find crate, instead of manual filename parse. cc @metajack
2 parents 9f4e5b6 + a6a31ec commit 2b62371

File tree

15 files changed

+503
-911
lines changed

15 files changed

+503
-911
lines changed

src/librustpkg/api.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
use CtxMethods;
1212
use context::*;
1313
use crate::*;
14-
use crate_id::*;
1514
use package_source::*;
1615
use path_util::{platform_library_name, target_build_dir};
1716
use target::*;
18-
use version::Version;
1917
use workspace::pkg_parent_workspaces;
2018
use workcache_support::*;
2119
pub use path_util::default_workspace;
@@ -27,6 +25,7 @@ use extra::arc::{Arc,RWArc};
2725
use extra::workcache;
2826
use extra::workcache::{Database, FreshnessMap};
2927
use extra::treemap::TreeMap;
28+
use syntax::crateid::CrateId;
3029

3130
// A little sad -- duplicated from rustc::back::*
3231
#[cfg(target_arch = "arm")]
@@ -79,20 +78,19 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context {
7978
workcache::Context::new_with_freshness(db, cfg, Arc::new(freshness))
8079
}
8180

82-
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
83-
lib: Path) {
84-
build_lib_with_cfgs(sysroot, root, name, version, lib, ~[])
81+
pub fn build_lib(sysroot: Path, root: Path, name: ~str, lib: Path) {
82+
build_lib_with_cfgs(sysroot, root, name, lib, ~[])
8583
}
8684

87-
pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
88-
version: Version, lib: Path, cfgs: ~[~str]) {
85+
pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str, lib: Path, cfgs: ~[~str]) {
8986
let cx = default_context(sysroot, root.clone());
87+
let crate_id: CrateId = from_str(name).expect("valid crate id");
9088
let pkg_src = PkgSrc {
9189
source_workspace: root.clone(),
9290
build_in_destination: false,
9391
destination_workspace: root.clone(),
9492
start_dir: root.join_many(["src", name.as_slice()]),
95-
id: CrateId{ version: version, ..CrateId::new(name)},
93+
id: crate_id,
9694
// n.b. This assumes the package only has one crate
9795
libs: ~[mk_crate(lib)],
9896
mains: ~[],
@@ -102,20 +100,19 @@ pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
102100
pkg_src.build(&cx, cfgs, []);
103101
}
104102

105-
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
106-
main: Path) {
107-
build_exe_with_cfgs(sysroot, root, name, version, main, ~[])
103+
pub fn build_exe(sysroot: Path, root: Path, name: ~str, main: Path) {
104+
build_exe_with_cfgs(sysroot, root, name, main, ~[])
108105
}
109106

110-
pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
111-
version: Version, main: Path, cfgs: ~[~str]) {
107+
pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str, main: Path, cfgs: ~[~str]) {
112108
let cx = default_context(sysroot, root.clone());
109+
let crate_id: CrateId = from_str(name).expect("valid crate id");
113110
let pkg_src = PkgSrc {
114111
source_workspace: root.clone(),
115112
build_in_destination: false,
116113
destination_workspace: root.clone(),
117114
start_dir: root.join_many(["src", name.as_slice()]),
118-
id: CrateId{ version: version, ..CrateId::new(name)},
115+
id: crate_id,
119116
libs: ~[],
120117
// n.b. This assumes the package only has one crate
121118
mains: ~[mk_crate(main)],
@@ -129,11 +126,10 @@ pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
129126
pub fn install_pkg(cx: &BuildContext,
130127
workspace: Path,
131128
name: ~str,
132-
version: Version,
133129
// For now, these inputs are assumed to be inputs to each of the crates
134130
more_inputs: ~[(~str, Path)]) { // pairs of Kind and Path
135-
let crateid = CrateId{ version: version, ..CrateId::new(name)};
136-
cx.install(PkgSrc::new(workspace.clone(), workspace, false, crateid),
131+
let crate_id: CrateId = from_str(name).expect("valid crate id");
132+
cx.install(PkgSrc::new(workspace.clone(), workspace, false, crate_id),
137133
&WhatToBuild{ build_type: Inferred,
138134
inputs_to_discover: more_inputs,
139135
sources: Everything });
@@ -157,10 +153,10 @@ pub fn build_library_in_workspace(exec: &mut workcache::Exec,
157153
let out_name = workspace_build_dir.join_many([package_name.to_str(),
158154
platform_library_name(output)]);
159155
// make paths absolute
160-
let crateid = CrateId::new(package_name);
156+
let crateid: CrateId = from_str(package_name).expect("valid crate id");
161157
let absolute_paths = paths.map(|s| {
162158
let whatever = workspace.join_many([~"src",
163-
crateid.to_str(),
159+
crateid.short_name_with_version(),
164160
s.to_owned()]);
165161
whatever.as_str().unwrap().to_owned()
166162
});
@@ -190,7 +186,7 @@ pub fn my_workspace(context: &Context, package_name: &str) -> Path {
190186
use bad_pkg_id = conditions::bad_pkg_id::cond;
191187

192188
// (this assumes no particular version is requested)
193-
let crateid = CrateId::new(package_name);
189+
let crateid = from_str(package_name).expect("valid crate id");
194190
let workspaces = pkg_parent_workspaces(context, &crateid);
195191
if workspaces.is_empty() {
196192
bad_pkg_id.raise((Path::new(package_name), package_name.to_owned()));

src/librustpkg/conditions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Useful conditions
1212

13-
pub use crate_id::CrateId;
13+
pub use syntax::crateid::CrateId;
1414
pub use std::io::FileStat;
1515
pub use std::io::process::ProcessExit;
1616
pub use std::path::Path;

src/librustpkg/crate_id.rs

-150
This file was deleted.

src/librustpkg/installed_packages.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// Listing installed packages
1212

1313
use rustc::metadata::filesearch::rust_path;
14-
use path_util::*;
1514
use std::os;
1615
use std::io;
1716
use std::io::fs;
17+
use syntax::crateid::CrateId;
1818

1919
pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool {
2020
let workspaces = rust_path();
@@ -28,7 +28,8 @@ pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool {
2828
match exec.filestem_str() {
2929
None => (),
3030
Some(exec_path) => {
31-
if !f(&CrateId::new(exec_path)) {
31+
let crate_id = from_str(exec_path).expect("valid crate id");
32+
if !f(&crate_id) {
3233
return false;
3334
}
3435
}
@@ -50,7 +51,8 @@ pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool {
5051
let rel_path = rel_p.join(basename);
5152
rel_path.display().with_str(|s| {
5253
debug!("Rel name: {}", s);
53-
f(&CrateId::new(s));
54+
let crate_id = from_str(s).expect("valid crate id");
55+
f(&crate_id);
5456
});
5557
}
5658
None => ()

0 commit comments

Comments
 (0)