@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/build_system/exceptions.dart';
1313import 'package:flutter_tools/src/build_system/targets/common.dart' ;
1414import 'package:flutter_tools/src/build_system/targets/ios.dart' ;
1515import 'package:flutter_tools/src/compile.dart' ;
16+ import 'package:flutter_tools/src/convert.dart' ;
1617import 'package:flutter_tools/src/ios/xcodeproj.dart' ;
1718import 'package:test/fake.dart' ;
1819
@@ -440,69 +441,76 @@ void main() {
440441 );
441442
442443 testUsingContext (
443- "tool exits when $ kAppFlavor is already set in user's environment" ,
444+ 'KernelSnapshot sets flavor in dartDefines from Xcode build configuration if ios app' ,
444445 () async {
445446 fileSystem.file ('.dart_tool/package_config.json' )
446447 ..createSync (recursive: true )
447448 ..writeAsStringSync ('{"configVersion": 2, "packages":[]}' );
448- final Future <void > buildResult = const KernelSnapshot ().build (
449- androidEnvironment
450- ..defines[kTargetPlatform] = getNameForTargetPlatform (TargetPlatform .android)
451- ..defines[kBuildMode] = BuildMode .debug.cliName
452- ..defines[kFlavor] = 'strawberry'
453- ..defines[kTrackWidgetCreation] = 'false' ,
449+ final String build = iosEnvironment.buildDir.path;
450+ final String flutterPatchedSdkPath = artifacts.getArtifactPath (
451+ Artifact .flutterPatchedSdkPath,
452+ platform: TargetPlatform .ios,
453+ mode: BuildMode .debug,
454454 );
455-
456- expect (
457- buildResult,
458- throwsToolExit (
459- message: '$kAppFlavor is used by the framework and cannot be set in the environment.' ,
455+ fileSystem.directory ('/ios/Runner.xcodeproj' ).createSync (recursive: true );
456+ processManager.addCommands (< FakeCommand > [
457+ FakeCommand (
458+ command: < String > [
459+ artifacts.getArtifactPath (Artifact .engineDartAotRuntime),
460+ artifacts.getArtifactPath (Artifact .frontendServerSnapshotForEngineDartSdk),
461+ '--sdk-root' ,
462+ '$flutterPatchedSdkPath /' ,
463+ '--target=flutter' ,
464+ '--no-print-incremental-dependencies' ,
465+ '-D$kAppFlavor =chocolate' ,
466+ ...buildModeOptions (BuildMode .debug, < String > []),
467+ '--no-link-platform' ,
468+ '--packages' ,
469+ '/.dart_tool/package_config.json' ,
470+ '--output-dill' ,
471+ '$build /app.dill' ,
472+ '--depfile' ,
473+ '$build /kernel_snapshot_program.d' ,
474+ '--incremental' ,
475+ '--initialize-from-dill' ,
476+ '$build /app.dill' ,
477+ '--verbosity=error' ,
478+ 'file:///lib/main.dart' ,
479+ ],
480+ stdout: 'result $kBoundaryKey \n $kBoundaryKey \n $kBoundaryKey $build /app.dill 0\n ' ,
460481 ),
461- );
462- },
463- overrides: < Type , Generator > {
464- Platform : () => FakePlatform (environment: < String , String > {kAppFlavor: 'I was already set' }),
465- },
466- );
482+ ]);
467483
468- testUsingContext (
469- 'tool exits when $kAppFlavor is set in --dart-define or --dart-define-from-file' ,
470- () async {
471- fileSystem.file ('.dart_tool/package_config.json' )
472- ..createSync (recursive: true )
473- ..writeAsStringSync ('{"configVersion": 2, "packages":[]}' );
474- final Future <void > buildResult = const KernelSnapshot ().build (
475- androidEnvironment
476- ..defines[kTargetPlatform] = getNameForTargetPlatform (TargetPlatform .android)
484+ await const KernelSnapshot ().build (
485+ iosEnvironment
486+ ..defines[kTargetPlatform] = getNameForTargetPlatform (TargetPlatform .ios)
477487 ..defines[kBuildMode] = BuildMode .debug.cliName
478488 ..defines[kFlavor] = 'strawberry'
479- ..defines[kDartDefines ] = encodeDartDefines ( < String > [kAppFlavor, 'strawberry' ])
489+ ..defines[kXcodeConfiguration ] = 'Debug-chocolate'
480490 ..defines[kTrackWidgetCreation] = 'false' ,
481491 );
482492
483- expect (
484- buildResult,
485- throwsToolExit (
486- message:
487- '$kAppFlavor is used by the framework and cannot be set using --dart-define or --dart-define-from-file' ,
488- ),
489- );
493+ expect (processManager, hasNoRemainingExpectations);
494+ },
495+ overrides: < Type , Generator > {
496+ XcodeProjectInterpreter :
497+ () => FakeXcodeProjectInterpreter (schemes: < String > ['Runner' , 'chocolate' ]),
490498 },
491499 );
492500
493501 testUsingContext (
494- 'KernelSnapshot sets flavor in dartDefines from Xcode build configuration if ios app' ,
502+ 'KernelSnapshot sets flavor in dartDefines from Xcode build configuration if macos app' ,
495503 () async {
496504 fileSystem.file ('.dart_tool/package_config.json' )
497505 ..createSync (recursive: true )
498506 ..writeAsStringSync ('{"configVersion": 2, "packages":[]}' );
499507 final String build = iosEnvironment.buildDir.path;
500508 final String flutterPatchedSdkPath = artifacts.getArtifactPath (
501509 Artifact .flutterPatchedSdkPath,
502- platform: TargetPlatform .ios ,
510+ platform: TargetPlatform .darwin ,
503511 mode: BuildMode .debug,
504512 );
505- fileSystem.directory ('/ios /Runner.xcodeproj' ).createSync (recursive: true );
513+ fileSystem.directory ('/macos /Runner.xcodeproj' ).createSync (recursive: true );
506514 processManager.addCommands (< FakeCommand > [
507515 FakeCommand (
508516 command: < String > [
@@ -514,7 +522,6 @@ void main() {
514522 '--no-print-incremental-dependencies' ,
515523 '-D$kAppFlavor =chocolate' ,
516524 ...buildModeOptions (BuildMode .debug, < String > []),
517- '--no-link-platform' ,
518525 '--packages' ,
519526 '/.dart_tool/package_config.json' ,
520527 '--output-dill' ,
@@ -533,7 +540,7 @@ void main() {
533540
534541 await const KernelSnapshot ().build (
535542 iosEnvironment
536- ..defines[kTargetPlatform] = getNameForTargetPlatform (TargetPlatform .ios )
543+ ..defines[kTargetPlatform] = getNameForTargetPlatform (TargetPlatform .darwin )
537544 ..defines[kBuildMode] = BuildMode .debug.cliName
538545 ..defines[kFlavor] = 'strawberry'
539546 ..defines[kXcodeConfiguration] = 'Debug-chocolate'
@@ -549,7 +556,7 @@ void main() {
549556 );
550557
551558 testUsingContext (
552- 'KernelSnapshot sets flavor in dartDefines from Xcode build configuration if macos app ' ,
559+ 'KernelSnapshot does not add kAppFlavor twice to Dart defines ' ,
553560 () async {
554561 fileSystem.file ('.dart_tool/package_config.json' )
555562 ..createSync (recursive: true )
@@ -560,7 +567,6 @@ void main() {
560567 platform: TargetPlatform .darwin,
561568 mode: BuildMode .debug,
562569 );
563- fileSystem.directory ('/macos/Runner.xcodeproj' ).createSync (recursive: true );
564570 processManager.addCommands (< FakeCommand > [
565571 FakeCommand (
566572 command: < String > [
@@ -570,7 +576,7 @@ void main() {
570576 '$flutterPatchedSdkPath /' ,
571577 '--target=flutter' ,
572578 '--no-print-incremental-dependencies' ,
573- '-D$kAppFlavor =chocolate ' ,
579+ '-D$kAppFlavor =vanilla ' ,
574580 ...buildModeOptions (BuildMode .debug, < String > []),
575581 '--packages' ,
576582 '/.dart_tool/package_config.json' ,
@@ -592,16 +598,17 @@ void main() {
592598 iosEnvironment
593599 ..defines[kTargetPlatform] = getNameForTargetPlatform (TargetPlatform .darwin)
594600 ..defines[kBuildMode] = BuildMode .debug.cliName
601+ ..defines[kDartDefines] = base64Encode (utf8.encode ('FLUTTER_APP_FLAVOR=vanilla' ))
595602 ..defines[kFlavor] = 'strawberry'
596- ..defines[kXcodeConfiguration] = 'Debug-chocolate'
597603 ..defines[kTrackWidgetCreation] = 'false' ,
598604 );
599605
600606 expect (processManager, hasNoRemainingExpectations);
601607 },
602608 overrides: < Type , Generator > {
603- XcodeProjectInterpreter :
604- () => FakeXcodeProjectInterpreter (schemes: < String > ['Runner' , 'chocolate' ]),
609+ Platform : () => macPlatform,
610+ FileSystem : () => fileSystem,
611+ ProcessManager : () => processManager,
605612 },
606613 );
607614
0 commit comments