8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- extern mod extra;
12
-
13
11
use target:: * ;
14
12
use package_id:: PkgId ;
15
13
use std:: path:: Path ;
@@ -18,9 +16,8 @@ use context::*;
18
16
use crate :: Crate ;
19
17
use messages:: * ;
20
18
use source_control:: { git_clone, git_clone_general} ;
21
- use path_util:: { pkgid_src_in_workspace, find_dir_using_rust_path_hack , default_workspace } ;
19
+ use path_util:: pkgid_src_in_workspace;
22
20
use util:: compile_crate;
23
- use workspace:: is_workspace;
24
21
25
22
// An enumeration of the unpacked source of a package workspace.
26
23
// This contains a list of files found in the source workspace.
@@ -51,7 +48,7 @@ impl PkgSrc {
51
48
}
52
49
53
50
54
- fn check_dir( & self , cx : & Ctx ) -> Path {
51
+ fn check_dir ( & self ) -> Path {
55
52
use conditions:: nonexistent_package:: cond;
56
53
57
54
debug ! ( "Pushing onto root: %s | %s" , self . id. path. to_str( ) , self . root. to_str( ) ) ;
@@ -62,21 +59,12 @@ impl PkgSrc {
62
59
63
60
let dir = match path {
64
61
Some ( d) => ( * d) . clone ( ) ,
65
- None => {
66
- match self . fetch_git ( ) {
67
- Some ( d) => d,
68
- None => {
69
- match find_dir_using_rust_path_hack ( cx, & self . id ) {
70
- Some ( d) => d,
71
- None => cond. raise ( ( self . id . clone ( ) ,
72
- ~"supplied path for package dir does not \
73
- exist, and couldn' t interpret it as a URL fragment") )
74
- }
75
- }
76
- }
62
+ None => match self . fetch_git ( ) {
63
+ Some ( d) => d,
64
+ None => cond. raise ( ( self . id . clone ( ) , ~"supplied path for package dir does not \
65
+ exist, and couldn' t interpret it as a URL fragment") )
77
66
}
78
67
} ;
79
- debug ! ( "For package id %s, returning %s" , self . id. to_str( ) , dir. to_str( ) ) ;
80
68
if !os:: path_is_dir ( & dir) {
81
69
cond. raise ( ( self . id . clone ( ) , ~"supplied path for package dir is a \
82
70
non-directory") ) ;
@@ -91,19 +79,11 @@ impl PkgSrc {
91
79
/// refers to a git repo on the local version, also check it out.
92
80
/// (right now we only support git)
93
81
pub fn fetch_git ( & self ) -> Option < Path > {
94
- use conditions:: failed_to_create_temp_dir:: cond;
95
-
96
- // We use a temporary directory because if the git clone fails,
97
- // it creates the target directory anyway and doesn't delete it
98
-
99
- let scratch_dir = extra:: tempfile:: mkdtemp ( & os:: tmpdir ( ) , "rustpkg" ) ;
100
- let clone_target = match scratch_dir {
101
- Some ( d) => d. push ( "rustpkg_temp" ) ,
102
- None => cond. raise ( ~"Failed to create temporary directory for fetching git sources")
103
- } ;
104
82
105
83
let mut local = self . root . push ( "src" ) ;
106
84
local = local. push ( self . id . to_str ( ) ) ;
85
+ // Git can't clone into a non-empty directory
86
+ os:: remove_dir_recursive ( & local) ;
107
87
108
88
debug ! ( "Checking whether %s exists locally. Cwd = %s, does it? %?" ,
109
89
self . id. path. to_str( ) ,
@@ -113,28 +93,15 @@ impl PkgSrc {
113
93
if os:: path_exists ( & self . id . path ) {
114
94
debug ! ( "%s exists locally! Cloning it into %s" ,
115
95
self . id. path. to_str( ) , local. to_str( ) ) ;
116
- // Ok to use local here; we know it will succeed
117
96
git_clone ( & self . id . path , & local, & self . id . version ) ;
118
97
return Some ( local) ;
119
98
}
120
99
121
- if ( self . id . path . clone ( ) ) . components ( ) . len ( ) < 2 {
122
- // If a non-URL, don't bother trying to fetch
123
- return None ;
124
- }
125
-
126
100
let url = fmt ! ( "https://%s" , self . id. path. to_str( ) ) ;
127
101
note ( fmt ! ( "Fetching package: git clone %s %s [version=%s]" ,
128
- url, clone_target. to_str( ) , self . id. version. to_str( ) ) ) ;
129
-
130
- if git_clone_general ( url, & clone_target, & self . id . version ) {
131
- // since the operation succeeded, move clone_target to local
132
- if !os:: rename_file ( & clone_target, & local) {
133
- None
134
- }
135
- else {
136
- Some ( local)
137
- }
102
+ url, local. to_str( ) , self . id. version. to_str( ) ) ) ;
103
+ if git_clone_general ( url, & local, & self . id . version ) {
104
+ Some ( local)
138
105
}
139
106
else {
140
107
None
@@ -171,10 +138,10 @@ impl PkgSrc {
171
138
172
139
/// Infers crates to build. Called only in the case where there
173
140
/// is no custom build logic
174
- pub fn find_crates ( & mut self , cx : & Ctx ) {
141
+ pub fn find_crates ( & mut self ) {
175
142
use conditions:: missing_pkg_files:: cond;
176
143
177
- let dir = self . check_dir ( cx ) ;
144
+ let dir = self . check_dir ( ) ;
178
145
debug ! ( "Called check_dir, I'm in %s" , dir. to_str( ) ) ;
179
146
let prefix = dir. components . len ( ) ;
180
147
debug ! ( "Matching against %?" , self . id. short_name) ;
@@ -216,7 +183,6 @@ impl PkgSrc {
216
183
fn build_crates ( & self ,
217
184
ctx : & Ctx ,
218
185
src_dir : & Path ,
219
- destination_dir : & Path ,
220
186
crates : & [ Crate ] ,
221
187
cfgs : & [ ~str ] ,
222
188
what : OutputType ) {
@@ -228,8 +194,8 @@ impl PkgSrc {
228
194
let result = compile_crate ( ctx,
229
195
& self . id ,
230
196
path,
231
- // compile_crate wants the destination workspace
232
- destination_dir ,
197
+ // compile_crate wants the workspace
198
+ & self . root ,
233
199
crate . flags,
234
200
crate . cfgs + cfgs,
235
201
false ,
@@ -243,39 +209,15 @@ impl PkgSrc {
243
209
}
244
210
}
245
211
246
- pub fn build ( & self , ctx : & Ctx , cfgs : ~[ ~str ] ) -> Path {
247
- use conditions:: not_a_workspace:: cond;
248
-
249
- // Determine the destination workspace (which depends on whether
250
- // we're using the rust_path_hack)
251
- let destination_workspace = if is_workspace ( & self . root ) {
252
- debug ! ( "%s is indeed a workspace" , self . root. to_str( ) ) ;
253
- self . root . clone ( )
254
- }
255
- else {
256
- // It would be nice to have only one place in the code that checks
257
- // for the use_rust_path_hack flag...
258
- if ctx. use_rust_path_hack {
259
- let rs = default_workspace ( ) ;
260
- debug ! ( "Using hack: %s" , rs. to_str( ) ) ;
261
- rs
262
- }
263
- else {
264
- cond. raise ( fmt ! ( "Package root %s is not a workspace; pass in --rust_path_hack \
265
- if you want to treat it as a package source", self . root. to_str( ) ) )
266
- }
267
- } ;
268
-
269
- let dir = self . check_dir ( ctx) ;
270
- debug ! ( "Building libs in %s, destination = %s" , dir. to_str( ) ,
271
- destination_workspace. to_str( ) ) ;
272
- self . build_crates ( ctx, & dir, & destination_workspace, self . libs , cfgs, Lib ) ;
212
+ pub fn build ( & self , ctx : & Ctx , cfgs : ~[ ~str ] ) {
213
+ let dir = self . check_dir ( ) ;
214
+ debug ! ( "Building libs in %s" , dir. to_str( ) ) ;
215
+ self . build_crates ( ctx, & dir, self . libs , cfgs, Lib ) ;
273
216
debug ! ( "Building mains" ) ;
274
- self . build_crates ( ctx, & dir, & destination_workspace , self . mains , cfgs, Main ) ;
217
+ self . build_crates ( ctx, & dir, self . mains , cfgs, Main ) ;
275
218
debug ! ( "Building tests" ) ;
276
- self . build_crates ( ctx, & dir, & destination_workspace , self . tests , cfgs, Test ) ;
219
+ self . build_crates ( ctx, & dir, self . tests , cfgs, Test ) ;
277
220
debug ! ( "Building benches" ) ;
278
- self . build_crates ( ctx, & dir, & destination_workspace, self . benchs , cfgs, Bench ) ;
279
- destination_workspace
221
+ self . build_crates ( ctx, & dir, self . benchs , cfgs, Bench ) ;
280
222
}
281
223
}
0 commit comments