31
31
extern crate derivative;
32
32
33
33
use std:: collections:: { BTreeMap , BTreeSet } ;
34
- use std:: convert:: TryFrom ;
34
+ use std:: convert:: { TryFrom , TryInto } ;
35
35
use std:: path:: PathBuf ;
36
36
use std:: sync:: Arc ;
37
37
@@ -40,7 +40,7 @@ pub use log::Level;
40
40
use async_semaphore:: AsyncSemaphore ;
41
41
use async_trait:: async_trait;
42
42
use bazel_protos:: gen:: build:: bazel:: remote:: execution:: v2 as remexec;
43
- use hashing:: { Digest , EMPTY_FINGERPRINT } ;
43
+ use hashing:: Digest ;
44
44
use remexec:: ExecutedActionMetadata ;
45
45
use serde:: { Deserialize , Serialize } ;
46
46
use workunit_store:: { RunningWorkunit , WorkunitStore } ;
@@ -323,51 +323,6 @@ impl Process {
323
323
}
324
324
}
325
325
326
- impl TryFrom < MultiPlatformProcess > for Process {
327
- type Error = String ;
328
-
329
- fn try_from ( req : MultiPlatformProcess ) -> Result < Self , Self :: Error > {
330
- match req. 0 . get ( & None ) {
331
- Some ( crossplatform_req) => Ok ( crossplatform_req. clone ( ) ) ,
332
- None => Err ( String :: from (
333
- "Cannot coerce to a simple Process, no cross platform request exists." ,
334
- ) ) ,
335
- }
336
- }
337
- }
338
-
339
- ///
340
- /// A container of platform constrained processes.
341
- ///
342
- #[ derive( Derivative , Clone , Debug , Eq , PartialEq , Hash ) ]
343
- pub struct MultiPlatformProcess ( pub BTreeMap < Option < Platform > , Process > ) ;
344
-
345
- impl MultiPlatformProcess {
346
- pub fn user_facing_name ( & self ) -> String {
347
- self
348
- . 0
349
- . iter ( )
350
- . next ( )
351
- . map ( |( _platforms, process) | process. description . clone ( ) )
352
- . unwrap_or_else ( || "<Unnamed process>" . to_string ( ) )
353
- }
354
-
355
- pub fn workunit_level ( & self ) -> log:: Level {
356
- self
357
- . 0
358
- . iter ( )
359
- . next ( )
360
- . map ( |( _platforms, process) | process. level )
361
- . unwrap_or ( Level :: Info )
362
- }
363
- }
364
-
365
- impl From < Process > for MultiPlatformProcess {
366
- fn from ( proc : Process ) -> Self {
367
- MultiPlatformProcess ( vec ! [ ( None , proc) ] . into_iter ( ) . collect ( ) )
368
- }
369
- }
370
-
371
326
///
372
327
/// Metadata surrounding an Process which factors into its cache key when cached
373
328
/// externally from the engine graph (e.g. when using remote execution or an external process
@@ -526,40 +481,15 @@ pub trait CommandRunner: Send + Sync {
526
481
& self ,
527
482
context : Context ,
528
483
workunit : & mut RunningWorkunit ,
529
- req : MultiPlatformProcess ,
484
+ req : Process ,
530
485
) -> Result < FallibleProcessResultWithPlatform , String > ;
531
-
532
- ///
533
- /// Given a multi platform request which may have some platform
534
- /// constraints determine if any of the requests contained within are compatible
535
- /// with the current command runners platform configuration. If so return the
536
- /// first candidate that will be run if the multi platform request is submitted to
537
- /// `fn run(..)`
538
- fn extract_compatible_request ( & self , req : & MultiPlatformProcess ) -> Option < Process > ;
539
486
}
540
487
541
488
// TODO(#8513) possibly move to the MEPR struct, or to the hashing crate?
542
- pub fn digest ( req : MultiPlatformProcess , metadata : & ProcessMetadata ) -> Digest {
543
- let mut hashes: Vec < String > = req
544
- . 0
545
- . values ( )
546
- . map ( |process| crate :: remote:: make_execute_request ( process, metadata. clone ( ) ) . unwrap ( ) )
547
- . map ( |( _a, _b, er) | {
548
- er. action_digest
549
- . map ( |d| d. hash )
550
- . unwrap_or_else ( || EMPTY_FINGERPRINT . to_hex ( ) )
551
- } )
552
- . collect ( ) ;
553
- hashes. sort ( ) ;
554
- Digest :: of_bytes (
555
- hashes
556
- . iter ( )
557
- . fold ( String :: new ( ) , |mut acc, hash| {
558
- acc. push_str ( hash) ;
559
- acc
560
- } )
561
- . as_bytes ( ) ,
562
- )
489
+ pub fn digest ( process : & Process , metadata : & ProcessMetadata ) -> Digest {
490
+ let ( _, _, execute_request) =
491
+ crate :: remote:: make_execute_request ( process, metadata. clone ( ) ) . unwrap ( ) ;
492
+ execute_request. action_digest . unwrap ( ) . try_into ( ) . unwrap ( )
563
493
}
564
494
565
495
///
@@ -584,7 +514,7 @@ impl CommandRunner for BoundedCommandRunner {
584
514
& self ,
585
515
context : Context ,
586
516
workunit : & mut RunningWorkunit ,
587
- mut req : MultiPlatformProcess ,
517
+ mut process : Process ,
588
518
) -> Result < FallibleProcessResultWithPlatform , String > {
589
519
let semaphore = self . inner . 1 . clone ( ) ;
590
520
let inner = self . inner . clone ( ) ;
@@ -593,28 +523,22 @@ impl CommandRunner for BoundedCommandRunner {
593
523
. with_acquired ( |concurrency_id| {
594
524
log:: debug!(
595
525
"Running {} under semaphore with concurrency id: {}" ,
596
- req . user_facing_name ( ) ,
526
+ process . description ,
597
527
concurrency_id
598
528
) ;
599
529
std:: mem:: drop ( blocking_token) ;
600
530
601
- for ( _, process) in req. 0 . iter_mut ( ) {
602
- if let Some ( ref execution_slot_env_var) = process. execution_slot_variable {
603
- let execution_slot = format ! ( "{}" , concurrency_id) ;
604
- process
605
- . env
606
- . insert ( execution_slot_env_var. clone ( ) , execution_slot) ;
607
- }
531
+ if let Some ( ref execution_slot_env_var) = process. execution_slot_variable {
532
+ let execution_slot = format ! ( "{}" , concurrency_id) ;
533
+ process
534
+ . env
535
+ . insert ( execution_slot_env_var. clone ( ) , execution_slot) ;
608
536
}
609
537
610
- inner. 0 . run ( context, workunit, req )
538
+ inner. 0 . run ( context, workunit, process )
611
539
} )
612
540
. await
613
541
}
614
-
615
- fn extract_compatible_request ( & self , req : & MultiPlatformProcess ) -> Option < Process > {
616
- self . inner . 0 . extract_compatible_request ( req)
617
- }
618
542
}
619
543
620
544
impl From < Box < BoundedCommandRunner > > for Arc < dyn CommandRunner > {
0 commit comments