def main(json_file): """Extracts information about the tools present on this host. Args: json_file: File to write JSON containing the tools information. """ info = { } info['Xcode Version'], info['Xcode Build Version'] = extract_xcode_version( utils.call('xcodebuild', '-version').stdout) info['Xcode SDKs'] = extract_sdks( utils.call('xcodebuild', '-showsdks').stdout) info['Free Space'] = get_free_disk_space() info['Logical CPUs'] = get_num_cpus() info['Python Version'] = get_python_version() info['Python Location'] = get_python_location() info['Mac OS X Version'] = get_osx_version() info['Available Tools'], info['Missing Tools'] = check_for_tools() if json_file: with open(json_file, 'w') as json_file: json.dump(info, json_file)
def main(json_file): """Extracts information about the tools present on this host. Args: json_file: File to write JSON containing the tools information. """ info = {} info['Xcode Version'], info['Xcode Build Version'] = extract_xcode_version( utils.call('xcodebuild', '-version').stdout) info['Xcode SDKs'] = extract_sdks( utils.call('xcodebuild', '-showsdks').stdout) info['Free Space'] = get_free_disk_space() info['Logical CPUs'] = get_num_cpus() info['Python Version'] = get_python_version() info['Python Location'] = get_python_location() info['Mac OS X Version'] = get_osx_version() info['Available Tools'], info['Missing Tools'] = check_for_tools() if json_file: with open(json_file, 'w') as json_file: json.dump(info, json_file)
def testCallNoArgs(self): # Set up mocks and call the method under test. self.getcwd.return_value = 'cwd' instance = self.popen.return_value instance.communicate.return_value = 'out', 'err' instance.returncode = 123 cr = utils.call('binary',) # Assert os.getcwd was called exactly once, without arguments. self.getcwd.assert_called_once() self.failIf(self.getcwd.call_args[0]) self.failIf(self.getcwd.call_args[1]) # Assert exactly one Popen was created, with correct arguments. self.popen.assert_called_once() popen_args = self.popen.call_args_list[0][0] popen_kwargs = self.popen.call_args_list[0][1] self.assertEqual(len(popen_args), 1) self.assertSequenceEqual(popen_args[0], ['binary']) self.assertDictEqual(popen_kwargs, { 'stdout': utils.subprocess.PIPE, 'stderr': utils.subprocess.PIPE, }) # Assert Popen.communicate was called exactly once, without arguments. instance.communicate.assert_called_once() self.failIf(instance.communicate.call_args[0]) self.failIf(instance.communicate.call_args[1]) # Assert the returned CallResult struct is correct. self.assertEqual(cr.returncode, 123) self.assertTupleEqual(cr.stdout, ('out',)) self.assertTupleEqual(cr.stderr, ('err',))
def FindTestDocumentsDirectory(self, apps_dir): """Finds the test's Documents directory in the given Applications directory. Args: apps_dir: The Applications directory, containing app ID directories. Returns: The Documents directory, or None if it doesn't exist. """ for appid_dir in os.listdir(apps_dir): appid_dir = os.path.join(apps_dir, appid_dir) app_bundle = os.path.join(appid_dir, '%s.app' % self.app_name) metadata_plist = os.path.join( appid_dir, '.com.apple.mobile_container_manager.metadata.plist') docs_dir = os.path.join(appid_dir, 'Documents') if os.path.exists(docs_dir): # iOS 7 app ID directories contain the app bundle. iOS 8 app ID # directories contain a metadata plist with the CFBundleIdentifier. if os.path.exists(app_bundle): return docs_dir elif os.path.exists(metadata_plist) and utils.call( utils.PLIST_BUDDY, '-c', 'Print:MCMMetadataIdentifier', metadata_plist, ).stdout[0] == self.cfbundleid: return docs_dir self.Print('Could not find %s on the simulator.' % self.app_name)
def KillSimulators(self): """Forcibly kills any running iOS simulator instances.""" kill_cmd = [ 'pkill', '-9', '-x', # The iOS simulator has a different name depending on the Xcode version. 'iPhone Simulator', # Xcode 5 'iOS Simulator', # Xcode 6 'Simulator', # Xcode 7 ] # If a signal was sent, wait for the simulator to actually be killed. if not utils.call(*kill_cmd).returncode: time.sleep(5)
def get_current_xcode_info(): """Returns the current Xcode path, version, and build number. Returns: A dict with 'path', 'version', and 'build' keys. 'path': The absolute path to the Xcode installation. 'version': The Xcode version. 'build': The Xcode build version. """ version, build_version = get_xcode_version('xcodebuild') return { 'path': utils.call('xcode-select', '--print-path').stdout[0], 'version': version, 'build': build_version, }
def get_xcode_version(xcodebuild): """Returns the Xcode version and build version. Args: xcodebuild: The absolute path to the xcodebuild binary. Returns: A tuple of (version string, build version string). e.g. ("6.0.1", "6A317") """ # Sample output: # Xcode 6.0.1 # Build version 6A317 version_output = utils.call(xcodebuild, '-version').stdout return version_output[0].split(' ')[-1], version_output[1].split(' ')[-1]
def find_xcode(target_version=None): """Finds all Xcode versions, switching to the given Xcode version. Args: target_version: The version of Xcode to switch to, or None if the Xcode version should not be switched. Returns: A summary dict as described in the usage section above. """ xcode_info = { 'installations': {}, 'current version': {}, } if target_version: xcode_info['found'] = False xcode_info['matches'] = {} xcode_info['previous version'] = get_current_xcode_info() if xcode_info['previous version']['version'] == target_version: xcode_info['found'] = True for app in os.listdir(os.path.join('/', 'Applications')): if app.startswith('Xcode'): installation_path = os.path.join('/', 'Applications', app) xcodebuild = get_xcodebuild_path(installation_path) if os.path.exists(xcodebuild): version, build_version = get_xcode_version(xcodebuild) xcode_info['installations'][installation_path] = "%s (%s)" % ( version, build_version, ) if target_version and version == target_version: xcode_info['matches'][installation_path] = "%s (%s)" % ( version, build_version, ) # If this is the first match, switch to it. if not xcode_info['found']: utils.call( 'sudo', 'xcode-select', '-switch', os.path.join('/', 'Applications', app), ) xcode_info['found'] = True xcode_info['current version'] = get_current_xcode_info() if target_version and not xcode_info['found']: # Flush buffers to ensure correct output ordering for buildbot. sys.stdout.flush() sys.stderr.write('Target Xcode version not found: %s\n' % target_version) sys.stderr.flush() return xcode_info
def try_call(binary): try: utils.call(binary) available.append(binary) except OSError: missing.append(binary)
def find_xcode(target_version=None): """Finds all Xcode versions, switching to the given Xcode version. Args: target_version: The version of Xcode to switch to, or None if the Xcode version should not be switched. Returns: A summary dict as described in the usage section above. """ xcode_info = { 'installations': { }, 'current version': { }, } if target_version: xcode_info['found'] = False xcode_info['matches'] = {} xcode_info['previous version'] = get_current_xcode_info() if xcode_info['previous version']['version'] == target_version: xcode_info['found'] = True for app in os.listdir(os.path.join('/', 'Applications')): if app.startswith('Xcode'): installation_path = os.path.join('/', 'Applications', app) xcodebuild = get_xcodebuild_path(installation_path) if os.path.exists(xcodebuild): version, build_version = get_xcode_version(xcodebuild) xcode_info['installations'][installation_path] = "%s (%s)" % ( version, build_version, ) if target_version and version == target_version: xcode_info['matches'][installation_path] = "%s (%s)" % ( version, build_version, ) # If this is the first match, switch to it. if not xcode_info['found']: utils.call( 'sudo', 'xcode-select', '-switch', os.path.join('/', 'Applications', app), ) xcode_info['found'] = True xcode_info['current version'] = get_current_xcode_info() if target_version and not xcode_info['found']: # Flush buffers to ensure correct output ordering for buildbot. sys.stdout.flush() sys.stderr.write('Target Xcode version not found: %s\n' % target_version) sys.stderr.flush() return xcode_info
def __init__( self, app_path, iossim_path, platform, version, xcode_version=None, gs_bucket=None, perf_bot_name=None, perf_build_number=None, perf_builder_name=None, perf_master_name=None, perf_revision=None, perf_x_value=None, test_args=None, ): """Initializes an instance of the SimulatorTestRunner class. Args: app_path: Full path to the compiled app to run. iossim_path: Full path to the iossim executable to launch. platform: The platform to simulate. Supported values can be found by running 'iossim -l'. e.g. 'iPhone 5', 'iPhone 5s'. version: The iOS version the simulator should be running. Supported values can be found by running 'iossim -l'. e.g. '8.0', '7.1'. xcode_version: Version of Xcode to use. gs_bucket: Google Storage bucket to upload test data to, or None if the test data should not be uploaded. perf_bot_name: Name of this bot as indicated to the perf dashboard. perf_build_number: Build number to indicate to the perf dashboard. perf_builder_name: Name of this builder as indicated to the perf dashboard. perf_master_name: Name of the master as indicated to the perf dashboard. perf_revision: Revision to indicate to the perf dashboard. perf_x_value: Value to use on the x axis for all data uploaded to the perf dashboard. test_args: Arguments to pass when launching the test. Raises: SimulatorNotFoundError: If the given iossim path cannot be found. """ super(SimulatorTestRunner, self).__init__( app_path, xcode_version=xcode_version, gs_bucket=gs_bucket, perf_bot_name=perf_bot_name, perf_build_number=perf_build_number, perf_builder_name=perf_builder_name, perf_master_name=perf_master_name, perf_revision=perf_revision, perf_x_value=perf_x_value, test_args=test_args, ) if not os.path.exists(iossim_path): raise SimulatorNotFoundError(iossim_path) self.cfbundleid = utils.call( utils.PLIST_BUDDY, '-c', 'Print:CFBundleIdentifier', os.path.join(self.app_path, 'Info.plist'), ).stdout[0] self.iossim_path = iossim_path self.platform = platform self.version = version self.timeout = '120' self.homedir = '' self.start_time = None