@@ -13,49 +13,101 @@ use crate::*;
13
13
use package_id:: * ;
14
14
use package_source:: * ;
15
15
use version:: Version ;
16
+ use workcache_support:: * ;
16
17
18
+ use extra:: arc:: { Arc , RWArc } ;
19
+ use extra:: workcache;
20
+ use extra:: workcache:: * ;
17
21
use std:: os;
18
- use std :: hashmap :: * ;
22
+ use extra :: treemap :: TreeMap ;
19
23
20
24
/// Convenience functions intended for calling from pkg.rs
25
+ /// p is where to put the cache file for dependencies
26
+ pub fn default_ctxt ( p : Path ) -> BuildCtx {
27
+ new_default_ctx ( new_workcache_cx ( & p) , p)
28
+ }
21
29
22
- fn default_ctxt ( p : @Path ) -> Ctx {
23
- Ctx {
24
- use_rust_path_hack : false ,
25
- sysroot_opt : Some ( p) ,
26
- json : false ,
27
- dep_cache : @mut HashMap :: new ( )
30
+ pub fn new_default_ctx ( c : Context , p : Path ) -> BuildCtx {
31
+ BuildCtx {
32
+ cx : Ctx { use_rust_path_hack : false ,
33
+ sysroot_opt : p } ,
34
+ workcache_cx : c
28
35
}
29
36
}
30
37
31
- pub fn build_lib ( sysroot : @Path , root : Path , name : ~str , version : Version ,
32
- lib : Path ) {
38
+ fn file_is_fresh ( path : & str , in_hash : & str ) -> bool {
39
+ in_hash == digest_file_with_date ( & Path ( path) )
40
+ }
33
41
34
- let pkg_src = PkgSrc {
35
- root : root,
36
- id : PkgId { version : version, ..PkgId :: new ( name) } ,
37
- libs : ~[ mk_crate ( lib) ] ,
38
- mains : ~[ ] ,
39
- tests : ~[ ] ,
40
- benchs : ~[ ]
41
- } ;
42
- pkg_src. build ( & default_ctxt ( sysroot) , ~[ ] ) ;
42
+ fn binary_is_fresh ( path : & str , in_hash : & str ) -> bool {
43
+ in_hash == digest_only_date ( & Path ( path) )
43
44
}
44
45
45
- pub fn build_exe ( sysroot : @Path , root : Path , name : ~str , version : Version , main : Path ) {
46
- let pkg_src = PkgSrc {
47
- root : root,
48
- id : PkgId { version : version, ..PkgId :: new ( name) } ,
49
- libs : ~[ ] ,
50
- mains : ~[ mk_crate ( main) ] ,
51
- tests : ~[ ] ,
52
- benchs : ~[ ]
46
+
47
+ pub fn new_workcache_cx ( p : & Path ) -> Context {
48
+ let db_file = p. push ( "rustpkg_db.json" ) ; // ??? probably wrong
49
+ debug ! ( "Workcache database file: %s" , db_file. to_str( ) ) ;
50
+ let db = RWArc :: new ( Database :: new ( db_file) ) ;
51
+ let lg = RWArc :: new ( Logger :: new ( ) ) ;
52
+ let cfg = Arc :: new ( TreeMap :: new ( ) ) ;
53
+ let mut rslt: FreshnessMap = TreeMap :: new ( ) ;
54
+ // Set up freshness functions for every type of dependency rustpkg
55
+ // knows about
56
+ rslt. insert ( ~"file", file_is_fresh) ;
57
+ rslt. insert ( ~"binary", binary_is_fresh) ;
58
+ workcache:: Context :: new_with_freshness ( db, lg, cfg, Arc :: new ( rslt) )
59
+ }
60
+
61
+ pub fn build_lib ( sysroot : Path , root : Path , name : ~str , version : Version ,
62
+ lib : Path ) {
63
+ let cx = default_ctxt ( sysroot) ;
64
+ let subroot = root. clone ( ) ;
65
+ let subversion = version. clone ( ) ;
66
+ let sublib = lib. clone ( ) ;
67
+ do cx. workcache_cx . with_prep ( name) |prep| {
68
+ let pkg_src = PkgSrc {
69
+ workspace : subroot. clone ( ) ,
70
+ start_dir : subroot. push ( "src" ) . push ( name) ,
71
+ id : PkgId { version : subversion. clone ( ) , ..PkgId :: new ( name) } ,
72
+ libs : ~[ mk_crate ( sublib. clone ( ) ) ] ,
73
+ mains : ~[ ] ,
74
+ tests : ~[ ] ,
75
+ benchs : ~[ ]
76
+ } ;
77
+ pkg_src. declare_inputs ( prep) ;
78
+ let subcx = cx. clone ( ) ;
79
+ let subsrc = pkg_src. clone ( ) ;
80
+ do prep. exec |exec| {
81
+ subsrc. clone ( ) . build ( exec, & subcx. clone ( ) , ~[ ] ) ;
82
+ }
53
83
} ;
54
- pkg_src . build ( & default_ctxt ( sysroot ) , ~ [ ] ) ;
84
+ }
55
85
86
+ pub fn build_exe ( sysroot : Path , root : Path , name : ~str , version : Version ,
87
+ main : Path ) {
88
+ let cx = default_ctxt ( sysroot) ;
89
+ let subroot = root. clone ( ) ;
90
+ let submain = main. clone ( ) ;
91
+ do cx. workcache_cx . with_prep ( name) |prep| {
92
+ let pkg_src = PkgSrc {
93
+ workspace : subroot. clone ( ) ,
94
+ start_dir : subroot. push ( "src" ) . push ( name) ,
95
+ id : PkgId { version : version. clone ( ) , ..PkgId :: new ( name) } ,
96
+ libs : ~[ ] ,
97
+ mains : ~[ mk_crate ( submain. clone ( ) ) ] ,
98
+ tests : ~[ ] ,
99
+ benchs : ~[ ]
100
+ } ;
101
+ pkg_src. declare_inputs ( prep) ;
102
+ let subsrc = pkg_src. clone ( ) ;
103
+ let subcx = cx. clone ( ) ;
104
+ do prep. exec |exec| {
105
+ subsrc. clone ( ) . build ( exec, & subcx. clone ( ) , ~[ ] ) ;
106
+ }
107
+ }
56
108
}
57
109
58
- pub fn install_lib ( sysroot : @ Path ,
110
+ pub fn install_lib ( sysroot : Path ,
59
111
workspace : Path ,
60
112
name : ~str ,
61
113
lib_path : Path ,
@@ -65,23 +117,33 @@ pub fn install_lib(sysroot: @Path,
65
117
debug ! ( "workspace = %s" , workspace. to_str( ) ) ;
66
118
// make a PkgSrc
67
119
let pkg_id = PkgId { version : version, ..PkgId :: new ( name) } ;
68
- let pkg_src = PkgSrc {
69
- root : workspace. clone ( ) ,
70
- id : pkg_id. clone ( ) ,
71
- libs : ~[ mk_crate ( lib_path) ] ,
72
- mains : ~[ ] ,
73
- tests : ~[ ] ,
74
- benchs : ~[ ]
75
- } ;
76
120
let cx = default_ctxt ( sysroot) ;
77
- pkg_src. build ( & cx, ~[ ] ) ;
121
+ let subpath = lib_path. clone ( ) ;
122
+ do cx. workcache_cx . with_prep ( pkg_id. to_str ( ) ) |prep| {
123
+ let pkg_src = PkgSrc {
124
+ workspace : workspace. clone ( ) ,
125
+ start_dir : subpath. push ( "src" ) . push ( name) ,
126
+ id : pkg_id. clone ( ) ,
127
+ libs : ~[ mk_crate ( subpath. clone ( ) ) ] ,
128
+ mains : ~[ ] ,
129
+ tests : ~[ ] ,
130
+ benchs : ~[ ]
131
+ } ;
132
+ pkg_src. declare_inputs ( prep) ;
133
+ let subcx = cx. clone ( ) ;
134
+ let subpkg_src = pkg_src. clone ( ) ;
135
+ do prep. exec |exec| {
136
+ subpkg_src. clone ( ) . build ( exec, & subcx. clone ( ) , ~[ ] ) ;
137
+ }
138
+ }
78
139
cx. install_no_build ( & workspace, & pkg_id) ;
79
140
}
80
141
81
- pub fn install_exe ( sysroot : @Path , workspace : Path , name : ~str , version : Version ) {
82
- default_ctxt ( sysroot) . install ( & workspace, & PkgId { version : version,
83
- ..PkgId :: new ( name) } ) ;
84
-
142
+ pub fn install_exe ( sysroot : Path , workspace : Path , name : ~str , version : Version ) {
143
+ let cx = default_ctxt ( sysroot) ;
144
+ debug ! ( "install_exe calling with_prep" ) ;
145
+ let pkgid = PkgId { version : version, ..PkgId :: new ( name) } ;
146
+ cx. install ( PkgSrc :: new ( workspace, false , pkgid) ) ;
85
147
}
86
148
87
149
fn mk_crate ( p : Path ) -> Crate {
0 commit comments