def testLocalPathInitialized(self, binary_manager_mock): expected = [mock.call.binary_manager.BinaryManager( ['base_config_object']), mock.call.binary_manager.BinaryManager().LocalPath( 'dep', 'plat_arch')] binary_manager.InitDependencyManager(None) binary_manager.LocalPath('dep', 'plat', 'arch') binary_manager_mock.assert_call_args(expected)
def testLocalPathInitialized(self, base_config_mock, dep_manager_mock): base_config_mock.return_value = 'base_config_object' expected = [mock.call.dependency_manager.DependencyManager( ['base_config_object']), mock.call.dependency_manager.DependencyManager().LocalPath( 'dep', 'plat_arch')] binary_manager.InitDependencyManager(None) binary_manager.LocalPath('dep', 'plat', 'arch') dep_manager_mock.assert_call_args(expected) base_config_mock.assert_called_once_with( binary_manager.TELEMETRY_PROJECT_CONFIG)
def testLocalPathInitialized(self, base_config_mock, binary_manager_mock): base_config_mock.return_value = 'base_config_object' expected = [ mock.call.binary_manager.BinaryManager(['base_config_object']), mock.call.binary_manager.BinaryManager().LocalPath( 'dep', 'plat_arch') ] binary_manager.InitDependencyManager(None) binary_manager.LocalPath('dep', 'plat', 'arch') binary_manager_mock.assert_call_args(expected) base_config_mock.assert_has_calls([ mock.call.base_config.BaseConfig( binary_manager.TELEMETRY_PROJECT_CONFIG), mock.call.base_config.BaseConfig( binary_manager.CHROME_BINARY_CONFIG) ]) self.assertEqual(2, base_config_mock.call_count)
def FindAllAvailableBrowsers(finder_options, device): """Finds all the desktop browsers available on this machine.""" if not isinstance(device, desktop_device.DesktopDevice): return [] browsers = [] if not CanFindAvailableBrowsers(): return [] has_x11_display = True if sys.platform.startswith('linux') and os.getenv('DISPLAY') is None: has_x11_display = False os_name = platform_module.GetHostPlatform().GetOSName() arch_name = platform_module.GetHostPlatform().GetArchName() try: flash_path = binary_manager.LocalPath('flash', arch_name, os_name) except dependency_manager.NoPathFoundError: flash_path = None logging.warning( 'Chrome build location for %s_%s not found. Browser will be run ' 'without Flash.', os_name, arch_name) chromium_app_names = [] if sys.platform == 'darwin': chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium') chromium_app_names.append('Google Chrome.app/Contents/MacOS/Google Chrome') content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell' elif sys.platform.startswith('linux'): chromium_app_names.append('chrome') content_shell_app_name = 'content_shell' elif sys.platform.startswith('win'): chromium_app_names.append('chrome.exe') content_shell_app_name = 'content_shell.exe' else: raise Exception('Platform not recognized') # Add the explicit browser executable if given and we can handle it. if finder_options.browser_executable: is_content_shell = finder_options.browser_executable.endswith( content_shell_app_name) # It is okay if the executable name doesn't match any of known chrome # browser executables, since it may be of a different browser. normalized_executable = os.path.expanduser( finder_options.browser_executable) if path_module.IsExecutable(normalized_executable): browser_directory = os.path.dirname(finder_options.browser_executable) browsers.append(PossibleDesktopBrowser( 'exact', finder_options, normalized_executable, flash_path, is_content_shell, browser_directory)) else: raise exceptions.PathMissingError( '%s specified by --browser-executable does not exist or is not ' 'executable' % normalized_executable) def AddIfFound(browser_type, build_path, app_name, content_shell): app = os.path.join(build_path, app_name) if path_module.IsExecutable(app): browsers.append(PossibleDesktopBrowser( browser_type, finder_options, app, flash_path, content_shell, build_path, is_local_build=True)) return True return False # Add local builds for build_path in path_module.GetBuildDirectories(finder_options.chrome_root): # TODO(agrieve): Extract browser_type from args.gn's is_debug. browser_type = os.path.basename(build_path).lower() for chromium_app_name in chromium_app_names: AddIfFound(browser_type, build_path, chromium_app_name, False) AddIfFound('content-shell-' + browser_type, build_path, content_shell_app_name, True) reference_build = None if finder_options.browser_type == 'reference': # Reference builds are only available in a Chromium checkout. We should not # raise an error just because they don't exist. os_name = platform_module.GetHostPlatform().GetOSName() arch_name = platform_module.GetHostPlatform().GetArchName() reference_build = binary_manager.FetchPath( 'chrome_stable', arch_name, os_name) # Mac-specific options. if sys.platform == 'darwin': mac_canary_root = '/Applications/Google Chrome Canary.app/' mac_canary = mac_canary_root + 'Contents/MacOS/Google Chrome Canary' mac_system_root = '/Applications/Google Chrome.app' mac_system = mac_system_root + '/Contents/MacOS/Google Chrome' if path_module.IsExecutable(mac_canary): browsers.append(PossibleDesktopBrowser('canary', finder_options, mac_canary, None, False, mac_canary_root)) if path_module.IsExecutable(mac_system): browsers.append(PossibleDesktopBrowser('system', finder_options, mac_system, None, False, mac_system_root)) if reference_build and path_module.IsExecutable(reference_build): reference_root = os.path.dirname(os.path.dirname(os.path.dirname( reference_build))) browsers.append(PossibleDesktopBrowser('reference', finder_options, reference_build, None, False, reference_root)) # Linux specific options. if sys.platform.startswith('linux'): versions = { 'system': os.path.split(os.path.realpath('/usr/bin/google-chrome'))[0], 'stable': '/opt/google/chrome', 'beta': '/opt/google/chrome-beta', 'dev': '/opt/google/chrome-unstable' } for version, root in versions.iteritems(): browser_path = os.path.join(root, 'chrome') if path_module.IsExecutable(browser_path): browsers.append(PossibleDesktopBrowser(version, finder_options, browser_path, None, False, root)) if reference_build and path_module.IsExecutable(reference_build): reference_root = os.path.dirname(reference_build) browsers.append(PossibleDesktopBrowser('reference', finder_options, reference_build, None, False, reference_root)) # Win32-specific options. if sys.platform.startswith('win'): app_paths = [ ('system', os.path.join('Google', 'Chrome', 'Application')), ('canary', os.path.join('Google', 'Chrome SxS', 'Application')), ] if reference_build: app_paths.append( ('reference', os.path.dirname(reference_build))) for browser_name, app_path in app_paths: for chromium_app_name in chromium_app_names: full_path = path_module.FindInstalledWindowsApplication( os.path.join(app_path, chromium_app_name)) if full_path: browsers.append(PossibleDesktopBrowser( browser_name, finder_options, full_path, None, False, os.path.dirname(full_path))) has_ozone_platform = False for arg in finder_options.browser_options.extra_browser_args: if "--ozone-platform" in arg: has_ozone_platform = True if len(browsers) and not has_x11_display and not has_ozone_platform: logging.warning( 'Found (%s), but you do not have a DISPLAY environment set.', ','.join( [b.browser_type for b in browsers])) return [] return browsers
def testLocalPathUninitialized(self): with self.assertRaises(exceptions.InitializationError): binary_manager.LocalPath('dep', 'arch', 'plat')
def testLocalPathInitialized(self, binary_manager_mock): binary_manager.InitDependencyManager(None) binary_manager.LocalPath('dep', 'arch', 'plat') binary_manager_mock.return_value.LocalPath.assert_called_with( 'dep', 'plat', 'arch', None)
def FindAllAvailableBrowsers(finder_options, device): """Finds all the desktop browsers available on this machine.""" if not isinstance(device, desktop_device.DesktopDevice): return [] browsers = [] if not CanFindAvailableBrowsers(): return [] has_x11_display = True if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None): has_x11_display = False os_name = platform_module.GetHostPlatform().GetOSName() arch_name = platform_module.GetHostPlatform().GetArchName() try: flash_path = binary_manager.LocalPath('flash', arch_name, os_name) except dm_exceptions.NoPathFoundError: flash_path = None logging.warning( 'Chrome build location is not specified. Browser will be run without ' 'Flash.') chromium_app_names = [] if sys.platform == 'darwin': chromium_app_names.append('Vivaldi.app/Contents/MacOS/Vivaldi') chromium_app_names.append('Vivaldi.app/Contents/MacOS/Vivaldi') content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell' elif sys.platform.startswith('linux'): chromium_app_names.append('vivaldi') content_shell_app_name = 'content_shell' elif sys.platform.startswith('win'): chromium_app_names.append('vivaldi.exe') content_shell_app_name = 'content_shell.exe' else: raise Exception('Platform not recognized') # Add the explicit browser executable if given and we can handle it. if (finder_options.browser_executable and CanPossiblyHandlePath(finder_options.browser_executable)): is_content_shell = finder_options.browser_executable.endswith( content_shell_app_name) is_chrome_or_chromium = len([ x for x in chromium_app_names if finder_options.browser_executable.endswith(x) ]) != 0 # It is okay if the executable name doesn't match any of known chrome # browser executables, since it may be of a different browser (say, # mandoline). if is_chrome_or_chromium or is_content_shell: normalized_executable = os.path.expanduser( finder_options.browser_executable) if path_module.IsExecutable(normalized_executable): browser_directory = os.path.dirname( finder_options.browser_executable) browsers.append( PossibleDesktopBrowser('exact', finder_options, normalized_executable, flash_path, is_content_shell, browser_directory)) else: raise exceptions.PathMissingError( '%s specified by --browser-executable does not exist or is not ' 'executable' % normalized_executable) def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell): if not finder_options.chrome_root: return False browser_directory = os.path.join(finder_options.chrome_root, "..", build_dir, type_dir) app = os.path.join(browser_directory, app_name) if path_module.IsExecutable(app): browsers.append( PossibleDesktopBrowser(browser_type, finder_options, app, flash_path, content_shell, browser_directory, is_local_build=True)) return True return False # Add local builds for build_dir, build_type in path_module.GetBuildDirectories(): for chromium_app_name in chromium_app_names: AddIfFound(build_type.lower(), build_dir, build_type, chromium_app_name, False) AddIfFound('content-shell-' + build_type.lower(), build_dir, build_type, content_shell_app_name, True) reference_build = None if finder_options.browser_type == 'reference': # Reference builds are only available in a Chromium checkout. We should not # raise an error just because they don't exist. os_name = platform_module.GetHostPlatform().GetOSName() arch_name = platform_module.GetHostPlatform().GetArchName() reference_build = binary_manager.FetchPath('reference_build', arch_name, os_name) # Mac-specific options. if sys.platform == 'darwin': mac_canary_root = '/Applications/Vivaldi Canary.app/' mac_canary = mac_canary_root + 'Contents/MacOS/Vivaldi Canary' mac_system_root = '/Applications/Vivaldi.app' mac_system = mac_system_root + '/Contents/MacOS/Vivaldi' if path_module.IsExecutable(mac_canary): browsers.append( PossibleDesktopBrowser('canary', finder_options, mac_canary, None, False, mac_canary_root)) if path_module.IsExecutable(mac_system): browsers.append( PossibleDesktopBrowser('system', finder_options, mac_system, None, False, mac_system_root)) if reference_build and path_module.IsExecutable(reference_build): reference_root = os.path.dirname( os.path.dirname(os.path.dirname(reference_build))) browsers.append( PossibleDesktopBrowser('reference', finder_options, reference_build, None, False, reference_root)) # Linux specific options. if sys.platform.startswith('linux'): # look for a vivaldi instance versions = { 'system': ('vivaldi', '/opt/vivaldi'), 'stable': '/opt/vivaldi', 'beta': '/opt/vivaldi', 'dev': '/opt/vivaldi' } for version, root in versions.iteritems(): browser_path = os.path.join(root, 'chrome') if path_module.IsExecutable(browser_path): browsers.append( PossibleDesktopBrowser(version, finder_options, browser_path, None, False, root)) if reference_build and path_module.IsExecutable(reference_build): reference_root = os.path.dirname(reference_build) browsers.append( PossibleDesktopBrowser('reference', finder_options, reference_build, None, False, reference_root)) # Win32-specific options. if sys.platform.startswith('win'): app_paths = [ ('system', os.path.join('Vivaldi', 'Vivaldi', 'Application')), ('canary', os.path.join('Vivaldi', 'Vivaldi', 'Application')), ] if reference_build: app_paths.append(('reference', os.path.dirname(reference_build))) for browser_name, app_path in app_paths: for chromium_app_name in chromium_app_names: app_path = os.path.join(app_path, chromium_app_name) app_path = path_module.FindInstalledWindowsApplication( app_path) if app_path: browsers.append( PossibleDesktopBrowser(browser_name, finder_options, app_path, None, False, os.path.dirname(app_path))) has_ozone_platform = False for arg in finder_options.browser_options.extra_browser_args: if "--ozone-platform" in arg: has_ozone_platform = True if len(browsers) and not has_x11_display and not has_ozone_platform: logging.warning( 'Found (%s), but you do not have a DISPLAY environment set.' % ','.join([b.browser_type for b in browsers])) return [] return browsers
def _SetupPrebuiltTools(device): """Some of the android pylib scripts we depend on are lame and expect binaries to be in the out/ directory. So we copy any prebuilt binaries there as a prereq.""" # TODO(bulach): Build the targets for x86/mips. device_tools = [ 'file_poller', 'forwarder_dist/device_forwarder', 'memtrack_helper', 'md5sum_dist/md5sum_bin', 'purge_ashmem', 'run_pie', ] host_tools = [ 'bitmaptools', 'md5sum_bin_host', ] platform_name = platform.GetHostPlatform().GetOSName() if platform_name == 'linux': host_tools.append('host_forwarder') arch_name = device.product_cpu_abi has_device_prebuilt = (arch_name.startswith('armeabi') or arch_name.startswith('arm64')) if not has_device_prebuilt: logging.warning('Unknown architecture type: %s' % arch_name) return all([ binary_manager.LocalPath(t, platform_name, arch_name) for t in device_tools ]) build_type = None for t in device_tools + host_tools: executable = os.path.basename(t) locally_built_path = binary_manager.LocalPath(t, platform_name, arch_name) if not build_type: build_type = _GetBuildTypeOfPath(locally_built_path) or 'Release' constants.SetBuildType(build_type) dest = os.path.join(constants.GetOutDirectory(), t) if not locally_built_path: logging.info('Setting up prebuilt %s', dest) if not os.path.exists(os.path.dirname(dest)): os.makedirs(os.path.dirname(dest)) platform_name = ('android' if t in device_tools else platform.GetHostPlatform().GetOSName()) bin_arch_name = (arch_name if t in device_tools else platform.GetHostPlatform().GetArchName()) prebuilt_path = binary_manager.FetchPath(executable, bin_arch_name, platform_name) if not prebuilt_path or not os.path.exists(prebuilt_path): raise NotImplementedError(""" %s must be checked into cloud storage. Instructions: http://www.chromium.org/developers/telemetry/upload_to_cloud_storage """ % t) shutil.copyfile(prebuilt_path, dest) os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) return True
return [] browsers = [] if not CanFindAvailableBrowsers(): return [] has_x11_display = True if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None): has_x11_display = False os_name = platform_module.GetHostPlatform().GetOSName() arch_name = platform_module.GetHostPlatform().GetArchName() try: flash_path = binary_manager.LocalPath('flash', arch_name, os_name) except dependency_manager.NoPathFoundError: flash_path = None logging.warning( 'Chrome build location for %s_%s not found. Browser will be run ' 'without Flash.', os_name, arch_name) chromium_app_names = [] if sys.platform == 'darwin': chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium') chromium_app_names.append('Google Chrome.app/Contents/MacOS/Google Chrome') content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell' elif sys.platform.startswith('linux'): chromium_app_names.append('chrome') content_shell_app_name = 'content_shell' elif sys.platform.startswith('win'):