@@ -36,8 +36,9 @@ use rustc::metadata::filesearch;
36
36
use std::net::url;
37
37
use std::{getopts};
38
38
use syntax::{ast, diagnostic};
39
- use util::{ExitCode, Pkg, PkgId};
40
- use path_util::dest_dir;
39
+ use util::*;
40
+ use path_util::{dest_dir, normalize};
41
+ use rustc::driver::session::{lib_crate, bin_crate, unknown_crate, crate_type};
41
42
42
43
mod conditions;
43
44
mod usage;
@@ -117,9 +118,12 @@ impl PkgScript {
117
118
Ok(r) => {
118
119
let root = r.pop().pop().pop().pop(); // :-\
119
120
debug!("Root is %s, calling compile_rest", root.to_str());
120
- util::compile_crate_from_input(self.input, Some(self.build_dir),
121
- sess, Some(crate), os::args()[0]);
122
121
let exe = self.build_dir.push(~"pkg" + util::exe_suffix());
122
+ util::compile_crate_from_input(self.input, self.id,
123
+ Some(self.build_dir),
124
+ sess, Some(crate),
125
+ exe, os::args()[0],
126
+ driver::cu_everything);
123
127
debug!("Running program: %s %s %s", exe.to_str(), root.to_str(), what);
124
128
let status = run::run_program(exe.to_str(), ~[root.to_str(), what]);
125
129
if status != 0 {
@@ -199,15 +203,15 @@ impl Ctx {
199
203
// relative to the CWD. In the future, we should search
200
204
// paths
201
205
let cwd = os::getcwd().normalize();
202
- debug!("Current working directory = %? ", cwd);
206
+ debug!("Current working directory = %s ", cwd.to_str() );
203
207
204
- // Find crates inside the workspace
208
+ // Create the package source
205
209
let mut src = PkgSrc::new(&cwd, &dst_dir, &pkgid);
206
210
debug!("Package src = %?", src);
207
- src.find_crates();
208
211
209
212
// Is there custom build logic? If so, use it
210
213
let pkg_src_dir = cwd.push_rel(&pkgid.path);
214
+ let mut custom = false;;
211
215
debug!("Package source directory = %s", pkg_src_dir.to_str());
212
216
let cfgs = match src.package_script_option(&pkg_src_dir) {
213
217
Some(package_script_path) => {
@@ -221,6 +225,7 @@ impl Ctx {
221
225
if hook_result != 0 {
222
226
fail!(fmt!("Error running custom build command"))
223
227
}
228
+ custom = true;
224
229
// otherwise, the package script succeeded
225
230
cfgs
226
231
}
@@ -229,6 +234,13 @@ impl Ctx {
229
234
~[]
230
235
}
231
236
};
237
+
238
+ // Find crates inside the workspace
239
+ if !custom {
240
+ src.find_crates();
241
+ }
242
+
243
+ // Build it!
232
244
src.build(&dst_dir, cfgs);
233
245
}
234
246
~"clean" => {
@@ -728,7 +740,6 @@ condition! {
728
740
729
741
impl PkgSrc {
730
742
731
-
732
743
fn new(src_dir: &Path, dst_dir: &Path,
733
744
id: &PkgId) -> PkgSrc {
734
745
PkgSrc {
@@ -765,12 +776,6 @@ impl PkgSrc {
765
776
dir
766
777
}
767
778
768
-
769
- fn has_pkg_file(&self) -> bool {
770
- let dir = self.check_dir();
771
- dir.push("pkg.rs").exists()
772
- }
773
-
774
779
// If a file named "pkg.rs" in the current directory exists,
775
780
// return the path for it. Otherwise, None
776
781
fn package_script_option(&self, cwd: &Path) -> Option<Path> {
@@ -786,14 +791,16 @@ impl PkgSrc {
786
791
/// True if the given path's stem is self's pkg ID's stem
787
792
/// or if the pkg ID's stem is <rust-foo> and the given path's
788
793
/// stem is foo
794
+ /// Requires that dashes in p have already been normalized to
795
+ /// underscores
789
796
fn stem_matches(&self, p: &Path) -> bool {
790
- let self_id = self.id.path.filestem();
797
+ let self_id = normalize(~ self.id.path) .filestem();
791
798
if self_id == p.filestem() {
792
799
return true;
793
800
}
794
801
else {
795
802
for self_id.each |pth| {
796
- if pth.starts_with("rust-")
803
+ if pth.starts_with("rust_") // because p is already normalized
797
804
&& match p.filestem() {
798
805
Some(s) => str::eq_slice(s, pth.slice(5, pth.len())),
799
806
None => false
@@ -814,17 +821,14 @@ impl PkgSrc {
814
821
cs.push(Crate::new(&sub));
815
822
}
816
823
824
+ /// Infers crates to build. Called only in the case where there
825
+ /// is no custom build logic
817
826
fn find_crates(&mut self) {
818
827
use PkgSrc::push_crate;
819
828
820
829
let dir = self.check_dir();
821
830
let prefix = dir.components.len();
822
- // This is ugly, but can go away once we get rid
823
- // of .rc files
824
- let mut saw_rs = false;
825
- let mut saw_rc = false;
826
- debug!("Matching against %?",
827
- self.id.path.filestem());
831
+ debug!("Matching against %?", self.id.path.filestem());
828
832
for os::walk_dir(&dir) |pth| {
829
833
match pth.filename() {
830
834
Some(~"lib.rs") => push_crate(&mut self.libs,
@@ -836,30 +840,10 @@ impl PkgSrc {
836
840
Some(~"bench.rs") => push_crate(&mut self.benchs,
837
841
prefix, pth),
838
842
_ => {
839
- // If the file stem is the same as the
840
- // package ID, with an .rs or .rc extension,
841
- // consider it to be a crate
842
- let ext = pth.filetype();
843
- let matches = |p: &Path| {
844
- self.stem_matches(p) && (ext == Some(~".rc")
845
- || ext == Some(~".rs"))
846
- };
847
- debug!("Checking %? which %s and ext = %? %? %?", pth.filestem(),
848
- if matches(pth) { "matches" } else { "does not match" },
849
- ext, saw_rs, saw_rc);
850
- if matches(pth) &&
851
- // Avoid pushing foo.rc *and* foo.rs
852
- !((ext == Some(~".rc") && saw_rs) ||
853
- (ext == Some(~".rs") && saw_rc)) {
854
- push_crate(&mut self.libs, // ????
855
- prefix, pth);
856
- if ext == Some(~".rc") {
857
- saw_rc = true;
858
- }
859
- else if ext == Some(~".rs") {
860
- saw_rs = true;
861
- }
862
- }
843
+ util::note(~"Couldn't infer any crates to build.\n\
844
+ Try naming a crate `main.rs`, `lib.rs`, \
845
+ `test.rs`, or `bench.rs`.");
846
+ fail!(~"Failed to infer crates to build");
863
847
}
864
848
}
865
849
}
@@ -870,22 +854,22 @@ impl PkgSrc {
870
854
self.benchs.len())
871
855
}
872
856
873
- fn build_crates(dst_dir: &Path,
857
+ fn build_crates(&self, dst_dir: &Path,
874
858
src_dir: &Path,
875
859
crates: &[Crate],
876
860
cfgs: ~[~str],
877
- test: bool) {
861
+ test: bool, crate_type: crate_type ) {
878
862
879
863
for crates.each |&crate| {
880
864
let path = &src_dir.push_rel(&crate.file).normalize();
881
865
util::note(fmt!("build_crates: compiling %s", path.to_str()));
882
866
util::note(fmt!("build_crates: destination dir is %s", dst_dir.to_str()));
883
867
884
- let result = util::compile_crate(None, path,
868
+ let result = util::compile_crate(None, self.id, path,
885
869
dst_dir,
886
870
crate.flags,
887
871
crate.cfgs + cfgs,
888
- false, test);
872
+ false, test, crate_type );
889
873
if !result {
890
874
build_err::cond.raise(fmt!("build failure on %s",
891
875
path.to_str()));
@@ -898,12 +882,12 @@ impl PkgSrc {
898
882
fn build(&self, dst_dir: &Path, cfgs: ~[~str]) {
899
883
let dir = self.check_dir();
900
884
debug!("Building libs");
901
- PkgSrc:: build_crates(dst_dir, &dir, self.libs, cfgs, false);
885
+ self. build_crates(dst_dir, &dir, self.libs, cfgs, false, lib_crate );
902
886
debug!("Building mains");
903
- PkgSrc:: build_crates(dst_dir, &dir, self.mains, cfgs, false);
887
+ self. build_crates(dst_dir, &dir, self.mains, cfgs, false, bin_crate );
904
888
debug!("Building tests");
905
- PkgSrc:: build_crates(dst_dir, &dir, self.tests, cfgs, true);
889
+ self. build_crates(dst_dir, &dir, self.tests, cfgs, true, bin_crate );
906
890
debug!("Building benches");
907
- PkgSrc:: build_crates(dst_dir, &dir, self.benchs, cfgs, true);
891
+ self. build_crates(dst_dir, &dir, self.benchs, cfgs, true, bin_crate );
908
892
}
909
893
}
0 commit comments