Xcode 8-compatible provisioning profiles in devicelab tests (#8987)
This commit is contained in:
82
dev/devicelab/lib/framework/ios.dart
Normal file
82
dev/devicelab/lib/framework/ios.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' as dart_io;
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/local.dart' as io;
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
const String _kProvisioningConfigFileEnvironmentVariable = 'FLUTTER_DEVICELAB_XCODE_PROVISIONING_CONFIG';
|
||||
const String _kTestXcconfigFileName = 'TestConfig.xcconfig';
|
||||
const FileSystem _fs = const io.LocalFileSystem();
|
||||
|
||||
/// Patches the given Xcode project adding provisioning certificates and team
|
||||
/// information required to build and run the project.
|
||||
Future<Null> prepareProvisioningCertificates(String flutterProjectPath) async {
|
||||
final String certificateConfig = await _readProvisioningConfigFile();
|
||||
await _patchFlutterXcconfigIfNotPatched(flutterProjectPath);
|
||||
|
||||
final File testXcconfig = _fs.file(path.join(flutterProjectPath, 'ios/Flutter/$_kTestXcconfigFileName'));
|
||||
await testXcconfig.writeAsString(certificateConfig);
|
||||
}
|
||||
|
||||
Future<Null> _patchFlutterXcconfigIfNotPatched(String flutterProjectPath) async {
|
||||
final File flutterXcconfig = _fs.file(path.join(flutterProjectPath, 'ios/Flutter/Flutter.xcconfig'));
|
||||
|
||||
if (!(await flutterXcconfig.exists())) {
|
||||
throw 'File not found: ${flutterXcconfig.path}';
|
||||
}
|
||||
|
||||
const String include = '#include "$_kTestXcconfigFileName"';
|
||||
final String contents = await flutterXcconfig.readAsString();
|
||||
if (!contents.contains(include)) {
|
||||
final IOSink patchOut = flutterXcconfig.openWrite(mode: FileMode.APPEND);
|
||||
patchOut.writeln(include);
|
||||
await patchOut.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _readProvisioningConfigFile() async {
|
||||
void throwUsageError(String specificMessage) {
|
||||
throw '''
|
||||
================================================================================
|
||||
You are attempting to build an XCode project, which requires a provisioning
|
||||
certificate and team information. The test framework attempted to locate an
|
||||
.xcconfig file whose path is defined by the environment variable
|
||||
$_kProvisioningConfigFileEnvironmentVariable.
|
||||
|
||||
$specificMessage
|
||||
================================================================================
|
||||
'''.trim();
|
||||
}
|
||||
|
||||
if (!dart_io.Platform.environment.containsKey(_kProvisioningConfigFileEnvironmentVariable)) {
|
||||
throwUsageError('''
|
||||
$_kProvisioningConfigFileEnvironmentVariable variable is not defined in your
|
||||
environment. Please, define it and try again.
|
||||
|
||||
Example provisioining xcconfig:
|
||||
|
||||
ProvisioningStyle=Manual
|
||||
CODE_SIGN_IDENTITY=...
|
||||
PROVISIONING_PROFILE=...
|
||||
DEVELOPMENT_TEAM=...
|
||||
PROVISIONING_PROFILE_SPECIFIER=...
|
||||
'''.trim());
|
||||
}
|
||||
|
||||
final String filePath = dart_io.Platform.environment[_kProvisioningConfigFileEnvironmentVariable];
|
||||
final File file = _fs.file(filePath);
|
||||
if (!(await file.exists())) {
|
||||
throwUsageError('''
|
||||
File not found: $filePath
|
||||
|
||||
It is defined by environment variable $_kProvisioningConfigFileEnvironmentVariable
|
||||
'''.trim());
|
||||
}
|
||||
|
||||
return file.readAsString();
|
||||
}
|
||||
Reference in New Issue
Block a user