@@ -36,7 +36,8 @@ use rustc::metadata::filesearch;
36
36
use std::{getopts};
37
37
use syntax::{ast, diagnostic};
38
38
use util::*;
39
- use path_util::{dest_dir, normalize};
39
+ use path_util::{normalize, workspace_contains_package_id};
40
+ use path_util::{build_pkg_id_in_workspace, pkgid_src_in_workspace, rust_path};
40
41
use rustc::driver::session::{lib_crate, bin_crate, crate_type};
41
42
42
43
mod conditions;
@@ -70,7 +71,7 @@ impl PkgScript {
70
71
/// Given the path name for a package script
71
72
/// and a package ID, parse the package script into
72
73
/// a PkgScript that we can then execute
73
- fn parse(script: Path, id: PkgId) -> PkgScript {
74
+ fn parse(script: Path, workspace: &Path, id: PkgId) -> PkgScript {
74
75
// Get the executable name that was invoked
75
76
let binary = os::args()[0];
76
77
// Build the rustc session data structures to pass
@@ -85,7 +86,7 @@ impl PkgScript {
85
86
let cfg = driver::build_configuration(sess, @binary, &input);
86
87
let (crate, _) = driver::compile_upto(sess, cfg, &input,
87
88
driver::cu_parse, None);
88
- let work_dir = dest_dir (id);
89
+ let work_dir = build_pkg_id_in_workspace (id, workspace );
89
90
90
91
debug!("Returning package script with id %?", id);
91
92
@@ -193,54 +194,60 @@ impl Ctx {
193
194
// The package id is presumed to be the first command-line
194
195
// argument
195
196
let pkgid = PkgId::new(args[0]);
196
- // Should allow the build directory to be configured.
197
- // Right now it's always the "build" subdirectory in
198
- // the package directory
199
- let dst_dir = dest_dir(pkgid);
200
- debug!("Destination dir = %s", dst_dir.to_str());
201
- // Right now, we assume the pkgid path is a valid dir
202
- // relative to the CWD. In the future, we should search
203
- // paths
204
- let cwd = os::getcwd().normalize();
205
- debug!("Current working directory = %s", cwd.to_str());
206
-
207
- // Create the package source
208
- let mut src = PkgSrc::new(&cwd, &dst_dir, &pkgid);
209
- debug!("Package src = %?", src);
210
-
211
- // Is there custom build logic? If so, use it
212
- let pkg_src_dir = cwd.push_rel(&pkgid.path);
213
- let mut custom = false;;
214
- debug!("Package source directory = %s", pkg_src_dir.to_str());
215
- let cfgs = match src.package_script_option(&pkg_src_dir) {
216
- Some(package_script_path) => {
217
- let pscript = PkgScript::parse(package_script_path,
218
- pkgid);
219
- // Limited right now -- we're only running the post_build
220
- // hook and probably fail otherwise
221
- // also post_build should be called pre_build
222
- let (cfgs, hook_result) = pscript.run_custom(~"post_build");
223
- debug!("Command return code = %?", hook_result);
224
- if hook_result != 0 {
225
- fail!(fmt!("Error running custom build command"))
197
+ // Using the RUST_PATH, find workspaces that contain
198
+ // this package ID
199
+ let workspaces = rust_path().filtered(|ws|
200
+ workspace_contains_package_id(pkgid, ws));
201
+ if workspaces.is_empty() {
202
+ fail!(fmt!("Package %s not found in any of \
203
+ the following workspaces: %s",
204
+ pkgid.path.to_str(),
205
+ rust_path().to_str()));
206
+ }
207
+ for workspaces.each |workspace| {
208
+ let src_dir = pkgid_src_in_workspace(pkgid, workspace);
209
+ let build_dir = build_pkg_id_in_workspace(pkgid, workspace);
210
+ debug!("Destination dir = %s", build_dir.to_str());
211
+
212
+ // Create the package source
213
+ let mut src = PkgSrc::new(&workspace.push("src"), &build_dir, &pkgid);
214
+ debug!("Package src = %?", src);
215
+
216
+ // Is there custom build logic? If so, use it
217
+ let pkg_src_dir = src_dir;
218
+ let mut custom = false;
219
+ debug!("Package source directory = %s", pkg_src_dir.to_str());
220
+ let cfgs = match src.package_script_option(&pkg_src_dir) {
221
+ Some(package_script_path) => {
222
+ let pscript = PkgScript::parse(package_script_path,
223
+ workspace,
224
+ pkgid);
225
+ // Limited right now -- we're only running the post_build
226
+ // hook and probably fail otherwise
227
+ // also post_build should be called pre_build
228
+ let (cfgs, hook_result) = pscript.run_custom(~"post_build");
229
+ debug!("Command return code = %?", hook_result);
230
+ if hook_result != 0 {
231
+ fail!(fmt!("Error running custom build command"))
232
+ }
233
+ custom = true;
234
+ // otherwise, the package script succeeded
235
+ cfgs
226
236
}
227
- custom = true;
228
- // otherwise, the package script succeeded
229
- cfgs
230
- }
231
- None => {
232
- debug!("No package script, continuing");
233
- ~[]
237
+ None => {
238
+ debug!("No package script, continuing");
239
+ ~[]
240
+ }
241
+ };
242
+
243
+ // If there was a package script, it should have finished
244
+ // the build already. Otherwise...
245
+ if !custom {
246
+ // Find crates inside the workspace
247
+ src.find_crates();
248
+ // Build it!
249
+ src.build(&build_dir, cfgs);
234
250
}
235
- };
236
-
237
- // If there was a package script, it should have finished
238
- // the build already. Otherwise...
239
- if !custom {
240
- // Find crates inside the workspace
241
- src.find_crates();
242
- // Build it!
243
- src.build(&dst_dir, cfgs);
244
251
}
245
252
}
246
253
~"clean" => {
@@ -250,8 +257,8 @@ impl Ctx {
250
257
// The package id is presumed to be the first command-line
251
258
// argument
252
259
let pkgid = PkgId::new(args[0]);
253
-
254
- self.clean(pkgid);
260
+ let cwd = os::getcwd();
261
+ self.clean(&cwd, pkgid); // tjc: should use workspace, not cwd
255
262
}
256
263
~"do" => {
257
264
if args.len() < 2 {
@@ -304,57 +311,16 @@ impl Ctx {
304
311
}
305
312
306
313
fn do_cmd(&self, cmd: ~str, pkgname: ~str) {
307
- match cmd {
308
- ~"build" | ~"test" => {
309
- util::error(~"that command cannot be manually called");
310
- fail!(~"do_cmd");
311
- }
312
- _ => {}
313
- }
314
-
315
- let cwd = &os::getcwd();
316
- let pkgid = PkgId::new(pkgname);
317
- // Always use the "build" subdirectory of the package dir,
318
- // but we should allow this to be configured
319
- let dst_dir = dest_dir(pkgid);
320
-
321
- let mut src = PkgSrc::new(cwd, &dst_dir, &pkgid);
322
- match src.package_script_option(cwd) {
323
- Some(script_path) => {
324
- let script = PkgScript::parse(script_path, pkgid);
325
- let (_, status) = script.run_custom(cmd); // Ignore cfgs?
326
- if status == 42 {
327
- util::error(~"no fns are listening for that cmd");
328
- fail!(~"do_cmd");
329
- }
330
- }
331
- None => {
332
- util::error(fmt!("invoked `do`, but there is no package script in %s",
333
- cwd.to_str()));
334
- fail!(~"do_cmd");
335
- }
336
- }
337
- }
338
-
339
- fn build(&self, _dir: &Path, _verbose: bool, _opt: bool,
340
- _test: bool) -> Option<PkgScript> {
341
- // either not needed anymore,
342
- // or needed only when we don't have a package script. Not sure which one.
343
- fail!();
344
- }
345
-
346
- fn compile(&self, _crate: &Path, _dir: &Path, _flags: ~[~str],
347
- _cfgs: ~[~str], _opt: bool, _test: bool) {
348
- // What's the difference between build and compile?
349
- fail!(~"compile not yet implemented");
314
+ // stub
315
+ fail!("`do` not yet implemented");
350
316
}
351
317
352
- fn clean(&self, id: PkgId) {
318
+ fn clean(&self, workspace: &Path, id: PkgId) {
353
319
// Could also support a custom build hook in the pkg
354
320
// script for cleaning files rustpkg doesn't know about.
355
321
// Do something reasonable for now
356
322
357
- let dir = dest_dir (id);
323
+ let dir = build_pkg_id_in_workspace (id, workspace );
358
324
util::note(fmt!("Cleaning package %s (removing directory %s)",
359
325
id.to_str(), dir.to_str()));
360
326
if os::path_exists(&dir) {
0 commit comments