Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review edits
  • Loading branch information
jmagman committed Nov 5, 2024
commit 937765c3fa2398a9b1b56d376f23faa110f5b4f4
120 changes: 62 additions & 58 deletions script/tool/lib/src/common/xcode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,76 @@ class Xcode {
required String scheme,
String? configuration,
List<String> extraFlags = const <String>[],
required Platform platform,
required Platform hostPlatform,
}) async {
final FileSystem fileSystem = exampleDirectory.fileSystem;
String? resultBundlePath;
final Directory? logsDirectory = ciLogsDirectory(platform, fileSystem);
final Directory? logsDirectory = ciLogsDirectory(hostPlatform, fileSystem);
Directory? resultBundleTemp;
if (logsDirectory != null) {
resultBundleTemp = fileSystem.systemTempDirectory
.createTempSync('flutter_xcresult.');
resultBundlePath = resultBundleTemp
.childDirectory('result')
.path;
}
File? disabledSandboxEntitlementFile;
if (actions.contains('test') && targetPlatform.toLowerCase() == 'macos') {
disabledSandboxEntitlementFile = _createDisabledSandboxEntitlementFile(
exampleDirectory.childDirectory(targetPlatform.toLowerCase()),
configuration ?? 'Debug',
);
}
final List<String> args = <String>[
_xcodeBuildCommand,
...actions,
...<String>['-workspace', workspace],
...<String>['-scheme', scheme],
if (resultBundlePath != null)
...<String>['-resultBundlePath', resultBundlePath],
if (configuration != null) ...<String>['-configuration', configuration],
...extraFlags,
if (disabledSandboxEntitlementFile != null)
'CODE_SIGN_ENTITLEMENTS=${disabledSandboxEntitlementFile.path}',
];
final String completeTestCommand = '$_xcRunCommand ${args.join(' ')}';
if (log) {
print(completeTestCommand);
}
final int resultExit = await processRunner.runAndStream(_xcRunCommand, args,
workingDir: exampleDirectory);

if (resultExit != 0 && resultBundleTemp != null) {
final Directory xcresultBundle = resultBundleTemp.childDirectory(
'result.xcresult');
try {
if (logsDirectory != null) {
if (xcresultBundle.existsSync()) {
// Zip the test results to the artifacts directory for upload.
final File zipPath = logsDirectory.childFile(
'xcodebuild-${DateTime.now().toLocal().toIso8601String()}.zip');
await processRunner.run(
'zip',
<String>[
'-r',
'-9',
'-q',
zipPath.path,
xcresultBundle.basename,
],
workingDir: resultBundleTemp,
);
} else {
print('xcresult bundle ${xcresultBundle
.path} does not exist, skipping upload');
resultBundleTemp = fileSystem.systemTempDirectory
.createTempSync('flutter_xcresult.');
resultBundlePath = resultBundleTemp
.childDirectory('result')
.path;
}
File? disabledSandboxEntitlementFile;
if (actions.contains('test') && targetPlatform.toLowerCase() == 'macos') {
disabledSandboxEntitlementFile = _createDisabledSandboxEntitlementFile(
exampleDirectory.childDirectory(targetPlatform.toLowerCase()),
configuration ?? 'Debug',
);
}
final List<String> args = <String>[
_xcodeBuildCommand,
...actions,
...<String>['-workspace', workspace],
...<String>['-scheme', scheme],
if (resultBundlePath != null)
...<String>['-resultBundlePath', resultBundlePath],
if (configuration != null) ...<String>['-configuration', configuration],
...extraFlags,
if (disabledSandboxEntitlementFile != null)
'CODE_SIGN_ENTITLEMENTS=${disabledSandboxEntitlementFile.path}',
];
final String completeTestCommand = '$_xcRunCommand ${args.join(' ')}';
if (log) {
print(completeTestCommand);
}
final int resultExit = await processRunner.runAndStream(
_xcRunCommand, args,
workingDir: exampleDirectory);

if (resultExit != 0 && resultBundleTemp != null) {
final Directory xcresultBundle = resultBundleTemp.childDirectory(
'result.xcresult');
if (logsDirectory != null) {
if (xcresultBundle.existsSync()) {
// Zip the test results to the artifacts directory for upload.
final File zipPath = logsDirectory.childFile(
'xcodebuild-${DateTime.now().toLocal().toIso8601String()}.zip');
await processRunner.run(
'zip',
<String>[
'-r',
'-9',
'-q',
zipPath.path,
xcresultBundle.basename,
],
workingDir: resultBundleTemp,
);
} else {
print('xcresult bundle ${xcresultBundle
.path} does not exist, skipping upload');
}
}
}
return resultExit;
} finally {
resultBundleTemp?.deleteSync();
}
return resultExit;

}

/// Returns true if [project], which should be an .xcodeproj directory,
Expand Down
11 changes: 5 additions & 6 deletions script/tool/lib/src/drive_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,12 @@ class DriveExamplesCommand extends PackageLoopingCommand {
final List<File> failures = <File>[];

final String enableExperiment = getStringArg(kEnableExperiment);
final Directory? logsDirectory = ciLogsDirectory(platform, driver.fileSystem);
final String screenshotBasename =
'${exampleName.replaceAll(platform.pathSeparator, '_')}-drive';
final Directory? screenshotDirectory = ciLogsDirectory(platform, driver.fileSystem)
?.childDirectory(screenshotBasename);

for (final File target in targets) {
Directory? screenshotDirectory;
if (logsDirectory != null) {
screenshotDirectory = logsDirectory.childDirectory('$exampleName-drive');
}
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
Expand Down Expand Up @@ -428,7 +427,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
required List<File> testFiles,
}) async {
final String enableExperiment = getStringArg(kEnableExperiment);
final Directory? logsDirectory = testFiles.isNotEmpty ? ciLogsDirectory(platform, testFiles.first.fileSystem) : null;
final Directory? logsDirectory = ciLogsDirectory(platform, testFiles.first.fileSystem);

// Workaround for https://github.com/flutter/flutter/issues/135673
// Once that is fixed on stable, this logic can be removed and the command
Expand Down
2 changes: 1 addition & 1 deletion script/tool/lib/src/native_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ this command.
workspace: '${targetPlatform.toLowerCase()}/Runner.xcworkspace',
scheme: 'Runner',
configuration: 'Debug',
platform: platform,
hostPlatform: platform,
extraFlags: <String>[
if (testTarget != null) '-only-testing:$testTarget',
...extraFlags,
Expand Down
2 changes: 1 addition & 1 deletion script/tool/lib/src/xcode_analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
workspace: '${targetPlatform.toLowerCase()}/Runner.xcworkspace',
scheme: 'Runner',
configuration: 'Debug',
platform: platform,
hostPlatform: platform,
extraFlags: <String>[
...extraFlags,
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
Expand Down
8 changes: 4 additions & 4 deletions script/tool/test/common/xcode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void main() {
'ios',
workspace: 'A.xcworkspace',
scheme: 'AScheme',
platform: MockPlatform(),
hostPlatform: MockPlatform(),
);

expect(exitCode, 0);
Expand Down Expand Up @@ -194,7 +194,7 @@ void main() {
workspace: 'A.xcworkspace',
scheme: 'AScheme',
configuration: 'Debug',
platform: MockPlatform(),
hostPlatform: MockPlatform(),
extraFlags: <String>['-a', '-b', 'c=d']);

expect(exitCode, 0);
Expand Down Expand Up @@ -232,7 +232,7 @@ void main() {
'ios',
workspace: 'A.xcworkspace',
scheme: 'AScheme',
platform: MockPlatform(),
hostPlatform: MockPlatform(),
);

expect(exitCode, 1);
Expand Down Expand Up @@ -267,7 +267,7 @@ void main() {
'macos',
workspace: 'A.xcworkspace',
scheme: 'AScheme',
platform: MockPlatform(),
hostPlatform: MockPlatform(),
actions: <String>['test'],
);

Expand Down
2 changes: 1 addition & 1 deletion script/tool/test/drive_examples_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ void main() {
'--web-port=7357',
'--browser-name=chrome',
'--web-renderer=canvaskit',
'--screenshot=/path/to/logs/a_package/example/with_web-drive',
'--screenshot=/path/to/logs/a_package/example_with_web-drive',
'--driver',
'test_driver/integration_test.dart',
'--target',
Expand Down