@@ -8,13 +8,16 @@ import 'package:async/async.dart';
8
8
import 'package:convert/convert.dart' ;
9
9
import 'package:crypto/crypto.dart' ;
10
10
import 'package:meta/meta.dart' ;
11
+ import 'package:platform/platform.dart' ;
11
12
import 'package:pool/pool.dart' ;
13
+ import 'package:process/process.dart' ;
12
14
15
+ import '../artifacts.dart' ;
13
16
import '../base/file_system.dart' ;
17
+ import '../base/logger.dart' ;
14
18
import '../base/utils.dart' ;
15
19
import '../cache.dart' ;
16
20
import '../convert.dart' ;
17
- import '../globals.dart' as globals;
18
21
import 'exceptions.dart' ;
19
22
import 'file_hash_store.dart' ;
20
23
import 'source.dart' ;
@@ -286,6 +289,10 @@ class Environment {
286
289
@required Directory outputDir,
287
290
@required Directory cacheDir,
288
291
@required Directory flutterRootDir,
292
+ @required FileSystem fileSystem,
293
+ @required Logger logger,
294
+ @required Artifacts artifacts,
295
+ @required ProcessManager processManager,
289
296
Directory buildDir,
290
297
Map <String , String > defines = const < String , String > {},
291
298
}) {
@@ -314,6 +321,10 @@ class Environment {
314
321
cacheDir: cacheDir,
315
322
defines: defines,
316
323
flutterRootDir: flutterRootDir,
324
+ fileSystem: fileSystem,
325
+ logger: logger,
326
+ artifacts: artifacts,
327
+ processManager: processManager,
317
328
);
318
329
}
319
330
@@ -327,6 +338,10 @@ class Environment {
327
338
Directory flutterRootDir,
328
339
Directory buildDir,
329
340
Map <String , String > defines = const < String , String > {},
341
+ @required FileSystem fileSystem,
342
+ @required Logger logger,
343
+ @required Artifacts artifacts,
344
+ @required ProcessManager processManager,
330
345
}) {
331
346
return Environment (
332
347
projectDir: projectDir ?? testDirectory,
@@ -335,6 +350,10 @@ class Environment {
335
350
flutterRootDir: flutterRootDir ?? testDirectory,
336
351
buildDir: buildDir,
337
352
defines: defines,
353
+ fileSystem: fileSystem,
354
+ logger: logger,
355
+ artifacts: artifacts,
356
+ processManager: processManager,
338
357
);
339
358
}
340
359
@@ -346,6 +365,10 @@ class Environment {
346
365
@required this .cacheDir,
347
366
@required this .defines,
348
367
@required this .flutterRootDir,
368
+ @required this .processManager,
369
+ @required this .logger,
370
+ @required this .fileSystem,
371
+ @required this .artifacts,
349
372
});
350
373
351
374
/// The [Source] value which is substituted with the path to [projectDir] .
@@ -399,6 +422,14 @@ class Environment {
399
422
400
423
/// The root build directory shared by all builds.
401
424
final Directory rootBuildDir;
425
+
426
+ final ProcessManager processManager;
427
+
428
+ final Logger logger;
429
+
430
+ final Artifacts artifacts;
431
+
432
+ final FileSystem fileSystem;
402
433
}
403
434
404
435
/// The result information from the build system.
@@ -422,7 +453,17 @@ class BuildResult {
422
453
423
454
/// The build system is responsible for invoking and ordering [Target] s.
424
455
class BuildSystem {
425
- const BuildSystem ();
456
+ const BuildSystem ({
457
+ @required FileSystem fileSystem,
458
+ @required Platform platform,
459
+ @required Logger logger,
460
+ }) : _fileSystem = fileSystem,
461
+ _platform = platform,
462
+ _logger = logger;
463
+
464
+ final FileSystem _fileSystem;
465
+ final Platform _platform;
466
+ final Logger _logger;
426
467
427
468
/// Build `target` and all of its dependencies.
428
469
Future <BuildResult > build (
@@ -436,15 +477,22 @@ class BuildSystem {
436
477
// Load file hash store from previous builds.
437
478
final FileHashStore fileCache = FileHashStore (
438
479
environment: environment,
439
- fileSystem: globals.fs ,
440
- logger: globals.logger ,
480
+ fileSystem: _fileSystem ,
481
+ logger: _logger ,
441
482
)..initialize ();
442
483
443
484
// Perform sanity checks on build.
444
485
checkCycles (target);
445
486
446
487
final Node node = target._toNode (environment);
447
- final _BuildInstance buildInstance = _BuildInstance (environment, fileCache, buildSystemConfig);
488
+ final _BuildInstance buildInstance = _BuildInstance (
489
+ environment: environment,
490
+ fileCache: fileCache,
491
+ buildSystemConfig: buildSystemConfig,
492
+ logger: _logger,
493
+ fileSystem: _fileSystem,
494
+ platform: _platform,
495
+ );
448
496
bool passed = true ;
449
497
try {
450
498
passed = await buildInstance.invokeTarget (node);
@@ -486,9 +534,18 @@ class BuildSystem {
486
534
487
535
/// An active instance of a build.
488
536
class _BuildInstance {
489
- _BuildInstance (this .environment, this .fileCache, this .buildSystemConfig)
490
- : resourcePool = Pool (buildSystemConfig.resourcePoolSize ?? globals.platform? .numberOfProcessors ?? 1 );
491
-
537
+ _BuildInstance ({
538
+ this .environment,
539
+ this .fileCache,
540
+ this .buildSystemConfig,
541
+ this .logger,
542
+ this .fileSystem,
543
+ Platform platform,
544
+ })
545
+ : resourcePool = Pool (buildSystemConfig.resourcePoolSize ?? platform? .numberOfProcessors ?? 1 );
546
+
547
+ final Logger logger;
548
+ final FileSystem fileSystem;
492
549
final BuildSystemConfig buildSystemConfig;
493
550
final Pool resourcePool;
494
551
final Map <String , AsyncMemoizer <bool >> pending = < String , AsyncMemoizer <bool >> {};
@@ -545,17 +602,17 @@ class _BuildInstance {
545
602
// If we're missing a depfile, wait until after evaluating the target to
546
603
// compute changes.
547
604
final bool canSkip = ! node.missingDepfile &&
548
- await node.computeChanges (environment, fileCache);
605
+ await node.computeChanges (environment, fileCache, fileSystem, logger );
549
606
550
607
if (canSkip) {
551
608
skipped = true ;
552
- globals .printTrace ('Skipping target: ${node .target .name }' );
609
+ logger .printTrace ('Skipping target: ${node .target .name }' );
553
610
updateGraph ();
554
611
return passed;
555
612
}
556
- globals .printTrace ('${node .target .name }: Starting due to ${node .invalidatedReasons }' );
613
+ logger .printTrace ('${node .target .name }: Starting due to ${node .invalidatedReasons }' );
557
614
await node.target.build (environment);
558
- globals .printTrace ('${node .target .name }: Complete' );
615
+ logger .printTrace ('${node .target .name }: Complete' );
559
616
560
617
node.inputs
561
618
..clear ()
@@ -581,7 +638,7 @@ class _BuildInstance {
581
638
if (outputFiles.containsKey (previousOutput)) {
582
639
continue ;
583
640
}
584
- final File previousFile = globals.fs .file (previousOutput);
641
+ final File previousFile = fileSystem .file (previousOutput);
585
642
if (previousFile.existsSync ()) {
586
643
previousFile.deleteSync ();
587
644
}
@@ -771,6 +828,8 @@ class Node {
771
828
Future <bool > computeChanges (
772
829
Environment environment,
773
830
FileHashStore fileHashStore,
831
+ FileSystem fileSystem,
832
+ Logger logger,
774
833
) async {
775
834
final Set <String > currentOutputPaths = < String > {
776
835
for (final File file in outputs) file.path,
@@ -808,7 +867,7 @@ class Node {
808
867
// if this isn't a current output file there is no reason to compute the hash.
809
868
continue ;
810
869
}
811
- final File file = globals.fs .file (previousOutput);
870
+ final File file = fileSystem .file (previousOutput);
812
871
if (! file.existsSync ()) {
813
872
invalidatedReasons.add (InvalidatedReason .outputMissing);
814
873
_dirty = true ;
@@ -833,7 +892,7 @@ class Node {
833
892
if (missingInputs.isNotEmpty) {
834
893
_dirty = true ;
835
894
final String missingMessage = missingInputs.map ((File file) => file.path).join (', ' );
836
- globals .printTrace ('invalidated build due to missing files: $missingMessage ' );
895
+ logger .printTrace ('invalidated build due to missing files: $missingMessage ' );
837
896
invalidatedReasons.add (InvalidatedReason .inputMissing);
838
897
}
839
898
0 commit comments