feat: support flavors on macOS (#2780)

This commit is contained in:
Bryan Oltman
2025-01-17 13:36:54 -05:00
committed by GitHub
parent 09dfd603e5
commit a190236409
6 changed files with 130 additions and 7 deletions
@@ -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(
@@ -275,7 +275,7 @@ class ArtifactManager {
'macos',
'Build',
'Products',
'Release',
flavor != null ? 'Release-$flavor' : 'Release',
),
);
@@ -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(
@@ -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);
}
@@ -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);
@@ -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);
@@ -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}.
''';
}
@@ -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', () {
@@ -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');
@@ -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(
@@ -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);