Skip to content

Commit

Permalink
feat: support flavors on macOS (#2780)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Jan 17, 2025
1 parent 09dfd60 commit a190236
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/shorebird_cli/lib/src/artifact_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class ArtifactManager {
}

/// The directory containing the compiled macOS .app file, if it exists.
Directory? getMacOSAppDirectory() {
Directory? getMacOSAppDirectory({String? flavor}) {
final projectRoot = shorebirdEnv.getShorebirdProjectRoot()!;

final appDirectory = Directory(
Expand All @@ -275,7 +275,7 @@ class ArtifactManager {
'macos',
'Build',
'Products',
'Release',
flavor != null ? 'Release-$flavor' : 'Release',
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
throw ProcessExit(ExitCode.software.code);
}

final appPath = artifactManager.getMacOSAppDirectory()!.path;
final appPath = artifactManager.getMacOSAppDirectory(flavor: flavor)!.path;
final tempDir = await Directory.systemTemp.createTemp();
final zippedApp = File(p.join(tempDir.path, '${p.basename(appPath)}.zip'));
await ditto.archive(
Expand All @@ -258,7 +258,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
}

// Verify that we have built a patch .app
if (artifactManager.getMacOSAppDirectory()?.path == null) {
if (artifactManager.getMacOSAppDirectory(flavor: flavor)?.path == null) {
logger.err('Unable to find .app directory');
throw ProcessExit(ExitCode.software.code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
throw ProcessExit(ExitCode.software.code);
}

final appDirectory = artifactManager.getMacOSAppDirectory();
final appDirectory = artifactManager.getMacOSAppDirectory(flavor: flavor);
if (appDirectory == null) {
logger.err('Unable to find .app directory');
throw ProcessExit(ExitCode.software.code);
Expand Down Expand Up @@ -161,7 +161,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
required Release release,
required String appId,
}) async {
final appDirectory = artifactManager.getMacOSAppDirectory();
final appDirectory = artifactManager.getMacOSAppDirectory(flavor: flavor);
if (appDirectory == null) {
logger.err('Unable to find .app directory');
throw ProcessExit(ExitCode.software.code);
Expand Down Expand Up @@ -204,6 +204,6 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
@override
String get postReleaseInstructions => '''
macOS app created at ${artifactManager.getMacOSAppDirectory()!.path}.
macOS app created at ${artifactManager.getMacOSAppDirectory(flavor: flavor)!.path}.
''';
}
27 changes: 27 additions & 0 deletions packages/shorebird_cli/test/src/artifact_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,33 @@ void main() {
);
});
});

group('when a flavor is provided', () {
const flavor = 'my-flavor';
late Directory appDirectory;

setUp(() {
appDirectory = Directory(
p.join(
projectRoot.path,
'build',
'macos',
'Build',
'Products',
'Release-$flavor',
'my.app',
),
)..createSync(recursive: true);
});

test('includes flavor in lookup path', () async {
final result = runWithOverrides(
() => artifactManager.getMacOSAppDirectory(flavor: flavor),
);

expect(result!.path, equals(appDirectory.path));
});
});
});

group('getIosAppDirectory', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,39 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
);
});

group('when flavor is provided', () {
const flavor = 'my-flavor';

setUp(() {
patcher = MacosPatcher(
argParser: argParser,
argResults: argResults,
flavor: flavor,
target: null,
);

when(
() => artifactManager.getMacOSAppDirectory(flavor: flavor),
).thenReturn(appDirectory);
});

test('builds with flavor', () async {
await runWithOverrides(patcher.buildPatchArtifact);
verify(
() => artifactBuilder.buildMacos(
codesign: any(named: 'codesign'),
args: any(named: 'args'),
flavor: flavor,
target: any(named: 'target'),
buildProgress: any(named: 'buildProgress'),
),
).called(1);
verify(
() => artifactManager.getMacOSAppDirectory(flavor: flavor),
).called(1);
});
});

group('when --split-debug-info is provided', () {
final tempDir = Directory.systemTemp.createTempSync();
final splitDebugInfoPath = p.join(tempDir.path, 'symbols');
Expand Down Expand Up @@ -1295,6 +1328,38 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
);
});

group('when flavor is provided', () {
const flavor = 'my-flavor';

setUp(() {
patcher = MacosPatcher(
argParser: argParser,
argResults: argResults,
flavor: flavor,
target: null,
);

when(
() => artifactManager.getMacOSAppDirectory(flavor: flavor),
).thenReturn(appDirectory);
});

test('finds app directory corresponding to flavor', () async {
await runWithOverrides(
() => patcher.createPatchArtifacts(
appId: appId,
releaseId: releaseId,
releaseArtifact: releaseArtifactFile,
supplementArtifact: supplementArtifactFile,
),
);

verify(
() => artifactManager.getMacOSAppDirectory(flavor: flavor),
).called(1);
});
});

group('when class table link info is not present', () {
setUp(() {
when(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,37 @@ To change the version of this release, change your app's version in your pubspec
).thenAnswer((_) async => flutterVersionAndRevision);
});

group('when flavor is provided', () {
const flavor = 'myFlavor';

setUp(() {
releaser = MacosReleaser(
argResults: argResults,
flavor: flavor,
target: null,
);

when(
() => artifactManager.getMacOSAppDirectory(flavor: flavor),
).thenReturn(appDirectory);
});

test('forwards flavor to artifact builder', () async {
await runWithOverrides(releaser.buildReleaseArtifacts);

verify(
() => artifactBuilder.buildMacos(
flavor: flavor,
args: any(named: 'args'),
buildProgress: any(named: 'buildProgress'),
),
).called(1);
verify(
() => artifactManager.getMacOSAppDirectory(flavor: flavor),
).called(1);
});
});

group('when not codesigning', () {
setUp(() {
when(() => argResults['codesign']).thenReturn(false);
Expand Down

0 comments on commit a190236

Please sign in to comment.