11use dirs:: { CARGO_HOME , RUSTUP_HOME } ;
2- use docker:: { ContainerBuilder , MountPerms , IMAGE_NAME } ;
2+ use docker:: DockerEnv ;
3+ use docker:: { ContainerBuilder , MountPerms } ;
34use failure:: Error ;
45use futures:: { future, Future , Stream } ;
56use native;
@@ -123,8 +124,8 @@ impl RunCommand {
123124 self
124125 }
125126
126- pub ( crate ) fn sandboxed ( self ) -> SandboxedCommand {
127- SandboxedCommand :: new ( self )
127+ pub ( crate ) fn sandboxed ( self , docker_env : & DockerEnv ) -> SandboxedCommand {
128+ SandboxedCommand :: new ( self , docker_env )
128129 }
129130
130131 pub ( crate ) fn run ( self ) -> Fallible < ( ) > {
@@ -187,14 +188,14 @@ impl RunCommand {
187188 }
188189}
189190
190- pub ( crate ) struct SandboxedCommand {
191+ pub ( crate ) struct SandboxedCommand < ' a > {
191192 command : RunCommand ,
192- container : ContainerBuilder ,
193+ container : ContainerBuilder < ' a > ,
193194}
194195
195- impl SandboxedCommand {
196- fn new ( command : RunCommand ) -> Self {
197- let container = ContainerBuilder :: new ( IMAGE_NAME )
196+ impl < ' a > SandboxedCommand < ' a > {
197+ fn new ( command : RunCommand , docker_env : & ' a DockerEnv ) -> Self {
198+ let container = ContainerBuilder :: new ( docker_env )
198199 . env ( "USER_ID" , native:: current_user ( ) . to_string ( ) )
199200 . enable_networking ( false ) ;
200201
@@ -218,16 +219,21 @@ impl SandboxedCommand {
218219
219220 pub ( crate ) fn run ( mut self ) -> Fallible < ( ) > {
220221 // Build the full CLI
221- let mut cmd = match self . command . binary {
222- Binary :: Global ( path) => path,
223- Binary :: InstalledByCrater ( path) => path,
224- }
225- . to_string_lossy ( )
226- . as_ref ( )
227- . to_string ( ) ;
222+ let mut cmd = Vec :: new ( ) ;
223+ cmd. push (
224+ match self . command . binary {
225+ Binary :: Global ( path) => path,
226+ Binary :: InstalledByCrater ( path) => {
227+ PathBuf :: from ( "/opt/crater/cargo-home/bin" ) . join ( path)
228+ }
229+ }
230+ . to_string_lossy ( )
231+ . as_ref ( )
232+ . to_string ( ) ,
233+ ) ;
234+
228235 for arg in self . command . args {
229- cmd. push ( ' ' ) ;
230- cmd. push_str ( arg. to_string_lossy ( ) . as_ref ( ) ) ;
236+ cmd. push ( arg. to_string_lossy ( ) . to_string ( ) ) ;
231237 }
232238
233239 let source_dir = match self . command . cd {
@@ -237,10 +243,11 @@ impl SandboxedCommand {
237243
238244 self . container = self
239245 . container
240- . mount ( source_dir, "/source" , MountPerms :: ReadOnly )
241- . env ( "SOURCE_DIR" , "/source" )
242- . env ( "USER_ID" , native:: current_user ( ) . to_string ( ) )
243- . env ( "CMD" , cmd) ;
246+ . mount ( source_dir, "/opt/crater/workdir" , MountPerms :: ReadOnly )
247+ . env ( "SOURCE_DIR" , "/opt/crater/workdir" )
248+ . env ( "MAP_USER_ID" , native:: current_user ( ) . to_string ( ) )
249+ . workdir ( "/opt/crater/workdir" )
250+ . cmd ( cmd) ;
244251
245252 for ( key, value) in self . command . env {
246253 self . container = self . container . env (
@@ -252,10 +259,14 @@ impl SandboxedCommand {
252259 if self . command . local_rustup {
253260 self . container = self
254261 . container
255- . mount ( & * CARGO_HOME , "/cargo-home" , MountPerms :: ReadOnly )
256- . mount ( & * RUSTUP_HOME , "/rustup-home" , MountPerms :: ReadOnly )
257- . env ( "CARGO_HOME" , "/cargo-home" )
258- . env ( "RUSTUP_HOME" , "/rustup-home" ) ;
262+ . mount ( & * CARGO_HOME , "/opt/crater/cargo-home" , MountPerms :: ReadOnly )
263+ . mount (
264+ & * RUSTUP_HOME ,
265+ "/opt/crater/rustup-home" ,
266+ MountPerms :: ReadOnly ,
267+ )
268+ . env ( "CARGO_HOME" , "/opt/crater/cargo-home" )
269+ . env ( "RUSTUP_HOME" , "/opt/crater/rustup-home" ) ;
259270 }
260271
261272 self . container . run ( self . command . quiet )
0 commit comments