Commit 91f7902a authored by Jenn Magder's avatar Jenn Magder Committed by Flutter GitHub Bot

Move Xcode context fetch to global.dart (#49458)

parent 2042c7d5
......@@ -244,12 +244,12 @@ class AOTSnapshotter {
final String assemblyO = globals.fs.path.join(outputPath, 'snapshot_assembly.o');
List<String> isysrootArgs;
if (isIOS) {
final String iPhoneSDKLocation = await xcode.sdkLocation(SdkType.iPhone);
final String iPhoneSDKLocation = await globals.xcode.sdkLocation(SdkType.iPhone);
if (iPhoneSDKLocation != null) {
isysrootArgs = <String>['-isysroot', iPhoneSDKLocation];
}
}
final RunResult compileResult = await xcode.cc(<String>[
final RunResult compileResult = await globals.xcode.cc(<String>[
'-arch', targetArch,
if (isysrootArgs != null) ...isysrootArgs,
if (bitcode) embedBitcodeArg,
......@@ -277,7 +277,7 @@ class AOTSnapshotter {
'-o', appLib,
assemblyO,
];
final RunResult linkResult = await xcode.clang(linkArgs);
final RunResult linkResult = await globals.xcode.clang(linkArgs);
if (linkResult.exitCode != 0) {
globals.printError('Failed to link AOT snapshot. Linker terminated with exit code ${compileResult.exitCode}');
}
......
......@@ -179,7 +179,7 @@ Future<RunResult> createStubAppFramework(File outputFile, SdkType sdk) async {
];
}
return await xcode.clang(<String>[
return await globals.xcode.clang(<String>[
'-x',
'c',
...archFlags,
......@@ -189,7 +189,7 @@ Future<RunResult> createStubAppFramework(File outputFile, SdkType sdk) async {
'-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks',
'-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks',
'-install_name', '@rpath/App.framework/App',
'-isysroot', await xcode.sdkLocation(sdk),
'-isysroot', await globals.xcode.sdkLocation(sdk),
'-o', outputFile.path,
]);
} finally {
......
......@@ -9,7 +9,6 @@ import '../../base/io.dart';
import '../../base/process.dart';
import '../../build_info.dart';
import '../../globals.dart' as globals;
import '../../macos/xcode.dart';
import '../build_system.dart';
import '../depfile.dart';
import '../exceptions.dart';
......@@ -155,7 +154,7 @@ class DebugMacOSFramework extends Target {
..writeAsStringSync(r'''
static const int Moo = 88;
''');
final RunResult result = await xcode.clang(<String>[
final RunResult result = await globals.xcode.clang(<String>[
'-x',
'c',
debugApp.path,
......
......@@ -127,7 +127,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
if (!boolArg('universal') && !boolArg('xcframework')) {
throwToolExit('--universal or --xcframework is required.');
}
if (boolArg('xcframework') && xcode.majorVersion < 11) {
if (boolArg('xcframework') && globals.xcode.majorVersion < 11) {
throwToolExit('--xcframework requires Xcode 11.');
}
if (buildModes.isEmpty) {
......
......@@ -11,7 +11,6 @@ import '../base/logger.dart';
import '../build_info.dart';
import '../globals.dart' as globals;
import '../ios/xcodeproj.dart';
import '../macos/xcode.dart';
import '../project.dart';
import '../runner/flutter_command.dart';
......@@ -34,7 +33,7 @@ class CleanCommand extends FlutterCommand {
// Clean Xcode to remove intermediate DerivedData artifacts.
// Do this before removing ephemeral directory, which would delete the xcworkspace.
final FlutterProject flutterProject = FlutterProject.current();
if (xcode.isInstalledAndMeetsVersionCheck) {
if (globals.xcode.isInstalledAndMeetsVersionCheck) {
await _cleanXcode(flutterProject.ios);
await _cleanXcode(flutterProject.macos);
}
......
......@@ -14,6 +14,7 @@ import 'base/io.dart';
import 'base/logger.dart';
import 'base/terminal.dart';
import 'cache.dart';
import 'macos/xcode.dart';
Logger get logger => context.get<Logger>();
Cache get cache => context.get<Cache>();
......@@ -40,6 +41,7 @@ const Platform _kLocalPlatform = LocalPlatform();
Platform get platform => context.get<Platform>() ?? _kLocalPlatform;
Xcode get xcode => context.get<Xcode>();
/// Display an error level message to the user. Commands should use this if they
/// fail in some way.
......
......@@ -8,7 +8,6 @@ import '../base/process.dart';
import '../device.dart';
import '../emulator.dart';
import '../globals.dart' as globals;
import '../macos/xcode.dart';
import 'ios_workflow.dart';
import 'simulators.dart';
......@@ -45,7 +44,7 @@ class IOSEmulator extends Emulator {
'open',
...additionalArgs,
'-a',
xcode.getSimulatorPath(),
globals.xcode.getSimulatorPath(),
];
final RunResult launchResult = await processUtils.run(args);
......@@ -69,7 +68,7 @@ class IOSEmulator extends Emulator {
/// Return the list of iOS Simulators (there can only be zero or one).
List<IOSEmulator> getEmulators() {
final String simulatorPath = xcode.getSimulatorPath();
final String simulatorPath = globals.xcode.getSimulatorPath();
if (simulatorPath == null) {
return <IOSEmulator>[];
}
......
......@@ -5,7 +5,6 @@
import '../base/context.dart';
import '../doctor.dart';
import '../globals.dart' as globals;
import '../macos/xcode.dart';
IOSWorkflow get iosWorkflow => context.get<IOSWorkflow>();
......@@ -17,12 +16,12 @@ class IOSWorkflow implements Workflow {
// We need xcode (+simctl) to list simulator devices, and libimobiledevice to list real devices.
@override
bool get canListDevices => xcode.isInstalledAndMeetsVersionCheck && xcode.isSimctlInstalled;
bool get canListDevices => globals.xcode.isInstalledAndMeetsVersionCheck && globals.xcode.isSimctlInstalled;
// We need xcode to launch simulator devices, and ideviceinstaller and ios-deploy
// for real devices.
@override
bool get canLaunchDevices => xcode.isInstalledAndMeetsVersionCheck;
bool get canLaunchDevices => globals.xcode.isInstalledAndMeetsVersionCheck;
@override
bool get canListEmulators => false;
......
......@@ -717,7 +717,7 @@ bool _checkXcodeVersion() {
globals.printError('Cannot find "xcodebuild". $_xcodeRequirement');
return false;
}
if (!xcode.isVersionSatisfactory) {
if (!globals.xcode.isVersionSatisfactory) {
globals.printError('Found "${xcodeProjectInterpreter.versionText}". $_xcodeRequirement');
return false;
}
......
......@@ -19,7 +19,6 @@ import '../bundle.dart';
import '../convert.dart';
import '../device.dart';
import '../globals.dart' as globals;
import '../macos/xcode.dart';
import '../project.dart';
import '../protocol_discovery.dart';
import 'ios_workflow.dart';
......@@ -47,7 +46,7 @@ class IOSSimulatorUtils {
static IOSSimulatorUtils get instance => context.get<IOSSimulatorUtils>();
Future<List<IOSSimulator>> getAttachedDevices() async {
if (!xcode.isInstalledAndMeetsVersionCheck) {
if (!globals.xcode.isInstalledAndMeetsVersionCheck) {
return <IOSSimulator>[];
}
......@@ -519,7 +518,7 @@ class IOSSimulator extends Device {
}
bool get _xcodeVersionSupportsScreenshot {
return xcode.majorVersion > 8 || (xcode.majorVersion == 8 && xcode.minorVersion >= 2);
return globals.xcode.majorVersion > 8 || (globals.xcode.majorVersion == 8 && globals.xcode.minorVersion >= 2);
}
@override
......
......@@ -9,7 +9,6 @@ import 'package:platform/platform.dart';
import 'package:process/process.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
......@@ -19,8 +18,6 @@ import '../ios/xcodeproj.dart';
const int kXcodeRequiredVersionMajor = 10;
const int kXcodeRequiredVersionMinor = 2;
Xcode get xcode => context.get<Xcode>();
enum SdkType {
iPhone,
iPhoneSimulator,
......
......@@ -5,6 +5,7 @@
import '../base/context.dart';
import '../base/user_messages.dart';
import '../doctor.dart';
import '../globals.dart' as globals;
import 'xcode.dart';
XcodeValidator get xcodeValidator => context.get<XcodeValidator>();
......@@ -18,36 +19,36 @@ class XcodeValidator extends DoctorValidator {
ValidationType xcodeStatus = ValidationType.missing;
String xcodeVersionInfo;
if (xcode.isInstalled) {
if (globals.xcode.isInstalled) {
xcodeStatus = ValidationType.installed;
messages.add(ValidationMessage(userMessages.xcodeLocation(xcode.xcodeSelectPath)));
messages.add(ValidationMessage(userMessages.xcodeLocation(globals.xcode.xcodeSelectPath)));
xcodeVersionInfo = xcode.versionText;
xcodeVersionInfo = globals.xcode.versionText;
if (xcodeVersionInfo.contains(',')) {
xcodeVersionInfo = xcodeVersionInfo.substring(0, xcodeVersionInfo.indexOf(','));
}
messages.add(ValidationMessage(xcode.versionText));
messages.add(ValidationMessage(globals.xcode.versionText));
if (!xcode.isInstalledAndMeetsVersionCheck) {
if (!globals.xcode.isInstalledAndMeetsVersionCheck) {
xcodeStatus = ValidationType.partial;
messages.add(ValidationMessage.error(
userMessages.xcodeOutdated(kXcodeRequiredVersionMajor, kXcodeRequiredVersionMinor)
));
}
if (!xcode.eulaSigned) {
if (!globals.xcode.eulaSigned) {
xcodeStatus = ValidationType.partial;
messages.add(ValidationMessage.error(userMessages.xcodeEula));
}
if (!xcode.isSimctlInstalled) {
if (!globals.xcode.isSimctlInstalled) {
xcodeStatus = ValidationType.partial;
messages.add(ValidationMessage.error(userMessages.xcodeMissingSimct));
}
} else {
xcodeStatus = ValidationType.missing;
if (xcode.xcodeSelectPath == null || xcode.xcodeSelectPath.isEmpty) {
if (globals.xcode.xcodeSelectPath == null || globals.xcode.xcodeSelectPath.isEmpty) {
messages.add(ValidationMessage.error(userMessages.xcodeMissing));
} else {
messages.add(ValidationMessage.error(userMessages.xcodeIncomplete));
......
......@@ -308,8 +308,8 @@ void main() {
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.ios,
......@@ -334,14 +334,14 @@ void main() {
'main.dill',
]);
final VerificationResult toVerifyCC = verify(xcode.cc(captureAny));
final VerificationResult toVerifyCC = verify(mockXcode.cc(captureAny));
expect(toVerifyCC.callCount, 1);
final dynamic ccArgs = toVerifyCC.captured.first;
expect(ccArgs, contains('-fembed-bitcode'));
expect(ccArgs, contains('-isysroot'));
expect(ccArgs, contains(kSDKPath));
final VerificationResult toVerifyClang = verify(xcode.clang(captureAny));
final VerificationResult toVerifyClang = verify(mockXcode.clang(captureAny));
expect(toVerifyClang.callCount, 1);
final dynamic clangArgs = toVerifyClang.captured.first;
expect(clangArgs, contains('-fembed-bitcode'));
......@@ -365,8 +365,8 @@ void main() {
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.ios,
......@@ -391,14 +391,14 @@ void main() {
'main.dill',
]);
final VerificationResult toVerifyCC = verify(xcode.cc(captureAny));
final VerificationResult toVerifyCC = verify(mockXcode.cc(captureAny));
expect(toVerifyCC.callCount, 1);
final dynamic ccArgs = toVerifyCC.captured.first;
expect(ccArgs, contains('-fembed-bitcode'));
expect(ccArgs, contains('-isysroot'));
expect(ccArgs, contains(kSDKPath));
final VerificationResult toVerifyClang = verify(xcode.clang(captureAny));
final VerificationResult toVerifyClang = verify(mockXcode.clang(captureAny));
expect(toVerifyClang.callCount, 1);
final dynamic clangArgs = toVerifyClang.captured.first;
expect(clangArgs, contains('-fembed-bitcode'));
......@@ -425,8 +425,8 @@ void main() {
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.ios,
......@@ -450,11 +450,11 @@ void main() {
'--no-use-integer-division',
'main.dill',
]);
verifyNever(xcode.cc(argThat(contains('-fembed-bitcode'))));
verifyNever(xcode.clang(argThat(contains('-fembed-bitcode'))));
verifyNever(mockXcode.cc(argThat(contains('-fembed-bitcode'))));
verifyNever(mockXcode.clang(argThat(contains('-fembed-bitcode'))));
verify(xcode.cc(argThat(contains('-isysroot')))).called(1);
verify(xcode.clang(argThat(contains('-isysroot')))).called(1);
verify(mockXcode.cc(argThat(contains('-isysroot')))).called(1);
verify(mockXcode.clang(argThat(contains('-isysroot')))).called(1);
final File assemblyFile = globals.fs.file(assembly);
expect(assemblyFile.existsSync(), true);
......@@ -472,8 +472,8 @@ void main() {
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.ios,
......@@ -508,8 +508,8 @@ void main() {
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.ios,
......@@ -546,8 +546,8 @@ void main() {
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.ios,
......@@ -640,8 +640,8 @@ void main() {
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
final int genSnapshotExitCode = await snapshotterWithTimings.build(
platform: TargetPlatform.android_arm,
......
......@@ -49,6 +49,7 @@ void main() {
Testbed testbed;
Environment environment;
MockPlatform mockPlatform;
MockXcode mockXcode;
setUpAll(() {
Cache.disableLocking();
......@@ -56,6 +57,7 @@ void main() {
});
setUp(() {
mockXcode = MockXcode();
mockPlatform = MockPlatform();
when(mockPlatform.isWindows).thenReturn(false);
when(mockPlatform.isMacOS).thenReturn(true);
......@@ -202,10 +204,10 @@ void main() {
environment.buildDir.childFile('snapshot_assembly.S').createSync();
return Future<int>.value(0);
});
when(xcode.cc(any)).thenAnswer((Invocation invocation) {
when(mockXcode.cc(any)).thenAnswer((Invocation invocation) {
return Future<RunResult>.value(RunResult(FakeProcessResult()..exitCode = 0, <String>['test']));
});
when(xcode.clang(any)).thenAnswer((Invocation invocation) {
when(mockXcode.clang(any)).thenAnswer((Invocation invocation) {
return Future<RunResult>.value(RunResult(FakeProcessResult()..exitCode = 0, <String>['test']));
});
environment.buildDir.childFile('app.dill').createSync(recursive: true);
......@@ -218,7 +220,7 @@ flutter_tools:lib/''');
await const CompileMacOSFramework().build(environment..defines[kBuildMode] = 'release');
}, overrides: <Type, Generator>{
GenSnapshot: () => MockGenSnapshot(),
Xcode: () => MockXCode(),
Xcode: () => mockXcode,
}));
}
......@@ -226,7 +228,7 @@ class MockPlatform extends Mock implements Platform {}
class MockCocoaPods extends Mock implements CocoaPods {}
class MockProcessManager extends Mock implements ProcessManager {}
class MockGenSnapshot extends Mock implements GenSnapshot {}
class MockXCode extends Mock implements Xcode {}
class MockXcode extends Mock implements Xcode {}
class FakeProcessResult implements ProcessResult {
@override
int exitCode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment