def __init__(self, opts): """Performs setup for building with target build system. Args: opts: Options parsed from command line. Raises: RuntimeError: Some condition necessary for building was not met. """ if bisect_utils.IsWindowsHost(): if not opts.build_preference: opts.build_preference = 'msvs' if opts.build_preference == 'msvs': if not os.getenv('VS100COMNTOOLS'): raise RuntimeError( 'Path to visual studio could not be determined.') else: # Need to re-escape goma dir, see crbug.com/394990. if opts.goma_dir: opts.goma_dir = opts.goma_dir.encode('string_escape') SetBuildSystemDefault(opts.build_preference, opts.use_goma, opts.goma_dir) else: if not opts.build_preference: if 'ninja' in os.getenv('GYP_GENERATORS', default=''): opts.build_preference = 'ninja' else: opts.build_preference = 'make' SetBuildSystemDefault(opts.build_preference, opts.use_goma, opts.goma_dir) if not SetupPlatformBuildEnvironment(opts): raise RuntimeError('Failed to set platform environment.')
def SetBuildSystemDefault(build_system, use_goma, goma_dir): """Sets up any environment variables needed to build with the specified build system. Args: build_system: A string specifying build system. Currently only 'ninja' or 'make' are supported. """ if build_system == 'ninja': gyp_var = os.getenv('GYP_GENERATORS', default='') if not gyp_var or not 'ninja' in gyp_var: if gyp_var: os.environ['GYP_GENERATORS'] = gyp_var + ',ninja' else: os.environ['GYP_GENERATORS'] = 'ninja' if bisect_utils.IsWindowsHost(): os.environ['GYP_DEFINES'] = 'component=shared_library '\ 'incremental_chrome_dll=1 disable_nacl=1 fastbuild=1 '\ 'chromium_win_pch=0' elif build_system == 'make': os.environ['GYP_GENERATORS'] = 'make' else: raise RuntimeError('%s build not supported.' % build_system) if use_goma: os.environ['GYP_DEFINES'] = '%s %s' % (os.getenv( 'GYP_DEFINES', default=''), 'use_goma=1') if goma_dir: os.environ['GYP_DEFINES'] += ' gomadir=%s' % goma_dir
def Build(self, depot, opts): """Builds chromium_builder_perf target using options passed into the script. Args: depot: Name of current depot being bisected. opts: The options parsed from the command line. Returns: True if build was successful. """ targets = ['chromium_builder_perf'] threads = None if opts.use_goma: threads = opts.goma_threads build_success = False if opts.build_preference == 'make': build_success = BuildWithMake(threads, targets, opts.target_build_type) elif opts.build_preference == 'ninja': build_success = BuildWithNinja(threads, targets, opts.target_build_type) elif opts.build_preference == 'msvs': assert bisect_utils.IsWindowsHost( ), 'msvs is only supported on Windows.' build_success = BuildWithVisualStudio(targets, opts.target_build_type) else: assert False, 'No build system defined.' return build_success
def _UnzipUsingZipFile(file_path, output_dir, verbose=True): """Extracts a zip file using the Python zipfile module.""" assert bisect_utils.IsWindowsHost() or bisect_utils.IsMacHost() zf = zipfile.ZipFile(file_path) for name in zf.namelist(): if verbose: print 'Extracting %s' % name zf.extract(name, output_dir) if bisect_utils.IsMacHost(): # Restore file permission bits. mode = zf.getinfo(name).external_attr >> 16 os.chmod(os.path.join(output_dir, name), mode)
def __init__(self, target_arch='ia32', target_platform='chromium'): if bisect_utils.IsLinuxHost() and target_platform == 'android': self._platform = 'android' elif bisect_utils.IsLinuxHost(): self._platform = 'linux' elif bisect_utils.IsMacHost(): self._platform = 'mac' elif bisect_utils.Is64BitWindows() and target_arch == 'x64': self._platform = 'win64' elif bisect_utils.IsWindowsHost(): self._platform = 'win' else: raise NotImplementedError('Unknown platform "%s".' % sys.platform)
def SetBuildSystemDefault(build_system, use_goma, goma_dir, target_arch='ia32'): """Sets up any environment variables needed to build with the specified build system. Args: build_system: A string specifying build system. Currently only 'ninja' or 'make' are supported. use_goma: Determines whether to GOMA for compile. goma_dir: GOMA directory path. target_arch: The target build architecture, ia32 or x64. Default is ia32. """ if build_system == 'ninja': gyp_var = os.getenv('GYP_GENERATORS', default='') if not gyp_var or not 'ninja' in gyp_var: if gyp_var: os.environ['GYP_GENERATORS'] = gyp_var + ',ninja' else: os.environ['GYP_GENERATORS'] = 'ninja' if bisect_utils.IsWindowsHost(): os.environ['GYP_DEFINES'] = 'component=shared_library '\ 'incremental_chrome_dll=1 disable_nacl=1 fastbuild=1 '\ 'chromium_win_pch=0' elif build_system == 'make': os.environ['GYP_GENERATORS'] = 'make' else: raise RuntimeError('%s build not supported.' % build_system) if use_goma: os.environ['GYP_DEFINES'] = '%s %s' % (os.getenv( 'GYP_DEFINES', default=''), 'use_goma=1') if goma_dir: os.environ['GYP_DEFINES'] += ' gomadir=%s' % goma_dir # Produce 64 bit chromium binaries when target architecure is set to x64. if target_arch == 'x64': os.environ['GYP_DEFINES'] += ' target_arch=%s' % target_arch
def Unzip(file_path, output_dir, verbose=True): """Extracts a zip archive's contents into the given output directory. This was based on ExtractZip from build/scripts/common/chromium_utils.py. Args: file_path: Path of the zip file to extract. output_dir: Path to the destination directory. verbose: Whether to print out what is being extracted. Raises: IOError: The unzip command had a non-zero exit code. RuntimeError: Failed to create the output directory. """ _MakeDirectory(output_dir) # On Linux and Mac, we use the unzip command because it handles links and # file permissions bits, so achieving this behavior is easier than with # ZipInfo options. # # The Mac Version of unzip unfortunately does not support Zip64, whereas # the python module does, so we have to fall back to the python zip module # on Mac if the file size is greater than 4GB. mac_zip_size_limit = 2**32 # 4GB if (bisect_utils.IsLinuxHost() or (bisect_utils.IsMacHost() and os.path.getsize(file_path) < mac_zip_size_limit)): unzip_command = ['unzip', '-o'] _UnzipUsingCommand(unzip_command, file_path, output_dir) return # On Windows, try to use 7z if it is installed, otherwise fall back to the # Python zipfile module. If 7z is not installed, then this may fail if the # zip file is larger than 512MB. sevenzip_path = r'C:\Program Files\7-Zip\7z.exe' if bisect_utils.IsWindowsHost() and os.path.exists(sevenzip_path): unzip_command = [sevenzip_path, 'x', '-y'] _UnzipUsingCommand(unzip_command, file_path, output_dir) return _UnzipUsingZipFile(file_path, output_dir, verbose)
def GetBuildOutputDirectory(opts, src_dir=None): """Returns the path to the build directory, relative to the checkout root. Assumes that the current working directory is the checkout root. Args: opts: Command-line options. src_dir: Path to chromium/src directory. Returns: A path to the directory to use as build output directory. Raises: NotImplementedError: The platform according to sys.platform is unexpected. """ src_dir = src_dir or 'src' if opts.build_preference == 'ninja' or bisect_utils.IsLinuxHost(): return os.path.join(src_dir, 'out') if bisect_utils.IsMacHost(): return os.path.join(src_dir, 'xcodebuild') if bisect_utils.IsWindowsHost(): return os.path.join(src_dir, 'build') raise NotImplementedError('Unexpected platform %s' % sys.platform)