@@ -13,49 +13,101 @@ use crate::*;
1313use package_id:: * ;
1414use package_source:: * ;
1515use version:: Version ;
16+ use workcache_support:: * ;
1617
18+ use extra:: arc:: { Arc , RWArc } ;
19+ use extra:: workcache;
20+ use extra:: workcache:: * ;
1721use std:: os;
18- use std :: hashmap :: * ;
22+ use extra :: treemap :: TreeMap ;
1923
2024/// 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+ }
2129
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
2835 }
2936}
3037
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+ }
3341
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) )
4344}
4445
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+ }
5383 } ;
54- pkg_src . build ( & default_ctxt ( sysroot ) , ~ [ ] ) ;
84+ }
5585
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+ }
56108}
57109
58- pub fn install_lib ( sysroot : @ Path ,
110+ pub fn install_lib ( sysroot : Path ,
59111 workspace : Path ,
60112 name : ~str ,
61113 lib_path : Path ,
@@ -65,23 +117,33 @@ pub fn install_lib(sysroot: @Path,
65117 debug ! ( "workspace = %s" , workspace. to_str( ) ) ;
66118 // make a PkgSrc
67119 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- } ;
76120 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+ }
78139 cx. install_no_build ( & workspace, & pkg_id) ;
79140}
80141
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) ) ;
85147}
86148
87149fn mk_crate ( p : Path ) -> Crate {
0 commit comments