@@ -12,22 +12,35 @@ use context::*;
1212use crate :: * ;
1313use package_id:: * ;
1414use package_source:: * ;
15+ use path_util:: { platform_library_name, target_build_dir} ;
1516use target:: * ;
1617use version:: Version ;
18+ use workspace:: pkg_parent_workspaces;
1719use workcache_support:: * ;
20+ pub use path_util:: default_workspace;
1821
1922pub use source_control:: { safe_git_clone, git_clone_url} ;
2023
21- use std:: os ;
24+ use std:: { os , run } ;
2225use extra:: arc:: { Arc , RWArc } ;
2326use extra:: workcache;
2427use extra:: workcache:: { Database , Logger , FreshnessMap } ;
2528use extra:: treemap:: TreeMap ;
2629
30+ // A little sad -- duplicated from rustc::back::*
31+ #[ cfg( target_arch = "arm" ) ]
32+ fn cc_args ( ) -> ~[ ~str ] { ~[ ~"-marm"] }
33+ #[ cfg( target_arch = "mips" ) ]
34+ fn cc_args ( ) -> ~[ ~str ] { ~[ ] }
35+ #[ cfg( target_arch = "x86" ) ]
36+ fn cc_args ( ) -> ~[ ~str ] { ~[ ~"-m32"] }
37+ #[ cfg( target_arch = "x86_64" ) ]
38+ fn cc_args ( ) -> ~[ ~str ] { ~[ ~"-m64"] }
39+
2740/// Convenience functions intended for calling from pkg.rs
2841/// p is where to put the cache file for dependencies
29- pub fn default_context ( p : Path ) -> BuildContext {
30- new_default_context ( new_workcache_context ( & p) , p )
42+ pub fn default_context ( sysroot : Path , p : Path ) -> BuildContext {
43+ new_default_context ( new_workcache_context ( & p) , sysroot )
3144}
3245
3346pub fn new_default_context ( c : workcache:: Context , p : Path ) -> BuildContext {
@@ -68,7 +81,7 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context {
6881
6982pub fn build_lib ( sysroot : Path , root : Path , name : ~str , version : Version ,
7083 lib : Path ) {
71- let cx = default_context ( sysroot) ;
84+ let cx = default_context ( sysroot, root . clone ( ) ) ;
7285 let pkg_src = PkgSrc {
7386 source_workspace : root. clone ( ) ,
7487 build_in_destination : false ,
@@ -81,12 +94,12 @@ pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
8194 tests : ~[ ] ,
8295 benchs : ~[ ]
8396 } ;
84- pkg_src. build ( & cx, ~[ ] ) ;
97+ pkg_src. build ( & cx, ~[ ] , [ ] ) ;
8598}
8699
87100pub fn build_exe ( sysroot : Path , root : Path , name : ~str , version : Version ,
88101 main : Path ) {
89- let cx = default_context ( sysroot) ;
102+ let cx = default_context ( sysroot, root . clone ( ) ) ;
90103 let pkg_src = PkgSrc {
91104 source_workspace : root. clone ( ) ,
92105 build_in_destination : false ,
@@ -100,13 +113,76 @@ pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
100113 benchs : ~[ ]
101114 } ;
102115
103- pkg_src. build ( & cx, ~[ ] ) ;
116+ pkg_src. build ( & cx, ~[ ] , [ ] ) ;
104117}
105118
106- pub fn install_pkg ( sysroot : Path , workspace : Path , name : ~str , version : Version ) {
107- let cx = default_context ( sysroot) ;
119+ pub fn install_pkg ( cx : & BuildContext ,
120+ workspace : Path ,
121+ name : ~str ,
122+ version : Version ,
123+ // For now, these inputs are assumed to be inputs to each of the crates
124+ more_inputs : ~[ ( ~str , Path ) ] ) { // pairs of Kind and Path
108125 let pkgid = PkgId { version : version, ..PkgId :: new ( name) } ;
109- cx. install ( PkgSrc :: new ( workspace. clone ( ) , workspace, false , pkgid) , & Everything ) ;
126+ cx. install ( PkgSrc :: new ( workspace. clone ( ) , workspace, false , pkgid) ,
127+ & WhatToBuild { build_type : Inferred ,
128+ inputs_to_discover : more_inputs,
129+ sources : Everything } ) ;
130+ }
131+
132+ /// Builds an arbitrary library whose short name is `output`,
133+ /// by invoking `tool` with arguments `args` plus "-o %s", where %s
134+ /// is the platform-specific library name for `output`.
135+ /// Returns that platform-specific name.
136+ pub fn build_library_in_workspace ( exec : & mut workcache:: Exec ,
137+ context : & mut Context ,
138+ package_name : & str ,
139+ tool : & str ,
140+ flags : & [ ~str ] ,
141+ paths : & [ ~str ] ,
142+ output : & str ) -> ~str {
143+ use command_failed = conditions:: command_failed:: cond;
144+
145+ let workspace = my_workspace ( context, package_name) ;
146+ let workspace_build_dir = target_build_dir ( & workspace) ;
147+ let out_name = workspace_build_dir. join_many ( [ package_name. to_str ( ) ,
148+ platform_library_name ( output) ] ) ;
149+ // make paths absolute
150+ let pkgid = PkgId :: new ( package_name) ;
151+ let absolute_paths = paths. map ( |s| {
152+ let whatever = workspace. join_many ( [ ~"src",
153+ pkgid. to_str ( ) ,
154+ s. to_owned ( ) ] ) ;
155+ whatever. as_str ( ) . unwrap ( ) . to_owned ( )
156+ } ) ;
157+
158+ let cc_args = cc_args ( ) ;
159+
160+ let all_args = flags + absolute_paths + cc_args +
161+ ~[ ~"-o", out_name. as_str ( ) . unwrap ( ) . to_owned ( ) ] ;
162+ let exit_code = run:: process_status ( tool, all_args) ;
163+ if exit_code != 0 {
164+ command_failed. raise ( ( tool. to_owned ( ) , all_args, exit_code) )
165+ }
166+ else {
167+ let out_name_str = out_name. as_str ( ) . unwrap ( ) . to_owned ( ) ;
168+ exec. discover_output ( "binary" ,
169+ out_name_str,
170+ digest_only_date ( & out_name) ) ;
171+ context. add_library_path ( out_name. dir_path ( ) ) ;
172+ out_name_str
173+ }
174+ }
175+
176+ pub fn my_workspace ( context : & Context , package_name : & str ) -> Path {
177+ use bad_pkg_id = conditions:: bad_pkg_id:: cond;
178+
179+ // (this assumes no particular version is requested)
180+ let pkgid = PkgId :: new ( package_name) ;
181+ let workspaces = pkg_parent_workspaces ( context, & pkgid) ;
182+ if workspaces. is_empty ( ) {
183+ bad_pkg_id. raise ( ( Path :: new ( package_name) , package_name. to_owned ( ) ) ) ;
184+ }
185+ workspaces[ 0 ]
110186}
111187
112188fn mk_crate ( p : Path ) -> Crate {
0 commit comments