def _ProcessBinutilsConfig(target, output_dir): """Do what binutils-config would have done""" binpath = os.path.join('/bin', target + '-') # Locate the bin dir holding the gold linker. binutils_bin_path = os.path.join(output_dir, 'usr', toolchain.GetHostTuple(), target, 'binutils-bin') globpath = os.path.join(binutils_bin_path, '*-gold') srcpath = glob.glob(globpath) if not srcpath: # Maybe this target doesn't support gold. globpath = os.path.join(binutils_bin_path, '*') srcpath = glob.glob(globpath) assert len(srcpath) == 1, ( '%s: matched more than one path (but not *-gold)' % globpath) srcpath = srcpath[0] ld_path = os.path.join(srcpath, 'ld') assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path ld_path = os.path.join(srcpath, 'ld.bfd') assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path ld_path = os.path.join(srcpath, 'ld.gold') assert not os.path.exists(ld_path), ( '%s: exists, but gold dir does not!' % ld_path) # Nope, no gold support to be found. gold_supported = False logging.warning('%s: binutils lacks support for the gold linker', target) else: assert len(srcpath) == 1, '%s: did not match exactly 1 path' % globpath gold_supported = True srcpath = srcpath[0] srcpath = srcpath[len(output_dir):] gccpath = os.path.join('/usr', 'libexec', 'gcc') for prog in os.listdir(output_dir + srcpath): # Skip binaries already wrapped. if not prog.endswith('.real'): GeneratePathWrapper(output_dir, binpath + prog, os.path.join(srcpath, prog)) GeneratePathWrapper(output_dir, os.path.join(gccpath, prog), os.path.join(srcpath, prog)) libpath = os.path.join('/usr', toolchain.GetHostTuple(), target, 'lib') envd = os.path.join(output_dir, 'etc', 'env.d', 'binutils', '*') if gold_supported: envd += '-gold' srcpath = _EnvdGetVar(envd, 'LIBPATH') os.symlink(os.path.relpath(srcpath, os.path.dirname(libpath)), output_dir + libpath)
def GetConfig(cls, target): """Returns a map of crossdev provided variables about a tuple.""" CACHE_ATTR = '_target_tuple_map' val = cls._CACHE.setdefault(CACHE_ATTR, {}) if not target in val: # Find out the crossdev tuple. target_tuple = target if target == 'host': target_tuple = toolchain.GetHostTuple() # Build the crossdev command. cmd = ['crossdev', '--show-target-cfg', '--ex-gdb'] if target in TARGET_GO_ENABLED: cmd.extend(CROSSDEV_GO_ARGS) cmd.extend(['-t', target_tuple]) # Catch output of crossdev. out = cros_build_lib.RunCommand(cmd, print_cmd=False, redirect_stdout=True).output.splitlines() # List of tuples split at the first '=', converted into dict. conf = dict((k, cros_build_lib.ShellUnquote(v)) for k, v in (x.split('=', 1) for x in out)) conf['crosspkgs'] = conf['crosspkgs'].split() for pkg, cat in cls.MANUAL_PKGS.iteritems(): conf[pkg + '_pn'] = pkg conf[pkg + '_category'] = cat if pkg not in conf['crosspkgs']: conf['crosspkgs'].append(pkg) val[target] = conf return val[target]
def _ProcessBinutilsConfig(target, output_dir): """Do what binutils-config would have done""" binpath = os.path.join('/bin', target + '-') globpath = os.path.join(output_dir, 'usr', toolchain.GetHostTuple(), target, 'binutils-bin', '*-gold') srcpath = glob.glob(globpath) assert len(srcpath) == 1, '%s: did not match 1 path' % globpath srcpath = srcpath[0][len(output_dir):] gccpath = os.path.join('/usr', 'libexec', 'gcc') for prog in os.listdir(output_dir + srcpath): # Skip binaries already wrapped. if not prog.endswith('.real'): GeneratePathWrapper(output_dir, binpath + prog, os.path.join(srcpath, prog)) GeneratePathWrapper(output_dir, os.path.join(gccpath, prog), os.path.join(srcpath, prog)) libpath = os.path.join('/usr', toolchain.GetHostTuple(), target, 'lib') envd = os.path.join(output_dir, 'etc', 'env.d', 'binutils', '*-gold') srcpath = _EnvdGetVar(envd, 'LIBPATH') os.symlink(os.path.relpath(srcpath, os.path.dirname(libpath)), output_dir + libpath)
def SelectActiveToolchains(targets, suffixes, root='/'): """Runs gcc-config and binutils-config to select the desired. Args: targets: The targets to select suffixes: Optional target-specific hacks root: The root where we want to select toolchain versions. """ for package in ['gcc', 'binutils']: for target in targets: # Pick the first version in the numbered list as the selected one. desired = GetDesiredPackageVersions(target, package) desired_num = VersionListToNumeric(target, package, desired, True, root=root) desired = desired_num[0] # *-config does not play revisions, strip them, keep just PV. desired = portage.versions.pkgsplit('%s-%s' % (package, desired))[1] if target == 'host': # *-config is the only tool treating host identically (by tuple). target = toolchain.GetHostTuple() # And finally, attach target to it. desired = '%s-%s' % (target, desired) # Target specific hacks if package in suffixes: if target in suffixes[package]: desired += suffixes[package][target] extra_env = {'CHOST': target} if root != '/': extra_env['ROOT'] = root cmd = ['%s-config' % package, '-c', target] result = cros_build_lib.RunCommand(cmd, print_cmd=False, redirect_stdout=True, extra_env=extra_env) current = result.output.splitlines()[0] # Do not reconfig when the current is live or nothing needs to be done. extra_env = {'ROOT': root} if root != '/' else None if current != desired and current != '9999': cmd = [package + '-config', desired] cros_build_lib.RunCommand(cmd, print_cmd=False, extra_env=extra_env)
def GetConfig(cls, target): """Returns a map of crossdev provided variables about a tuple.""" CACHE_ATTR = '_target_tuple_map' val = cls._CACHE.setdefault(CACHE_ATTR, {}) if not target in val: if target.startswith('host'): conf = { 'crosspkgs': [], 'target': toolchain.GetHostTuple(), } if target == 'host': packages_list = HOST_PACKAGES else: packages_list = HOST_POST_CROSS_PACKAGES manual_pkgs = dict((pkg, cat) for cat, pkg in [x.split('/') for x in packages_list]) else: # Build the crossdev command. cmd = ['crossdev', '--show-target-cfg', '--ex-gdb'] if target in TARGET_COMPILER_RT_ENABLED: cmd.extend(CROSSDEV_COMPILER_RT_ARGS) if target in TARGET_GO_ENABLED: cmd.extend(CROSSDEV_GO_ARGS) if target in TARGET_LLVM_PKGS_ENABLED: for pkg in LLVM_PKGS_TABLE: cmd.extend(LLVM_PKGS_TABLE[pkg]) cmd.extend(['-t', target]) # Catch output of crossdev. out = cros_build_lib.run( cmd, print_cmd=False, redirect_stdout=True, encoding='utf-8').stdout.splitlines() # List of tuples split at the first '=', converted into dict. conf = dict((k, cros_build_lib.ShellUnquote(v)) for k, v in (x.split('=', 1) for x in out)) conf['crosspkgs'] = conf['crosspkgs'].split() manual_pkgs = cls.MANUAL_PKGS for pkg, cat in manual_pkgs.items(): conf[pkg + '_pn'] = pkg conf[pkg + '_category'] = cat if pkg not in conf['crosspkgs']: conf['crosspkgs'].append(pkg) val[target] = conf return val[target]
def SelectActiveToolchains(targets, suffixes): """Runs gcc-config and binutils-config to select the desired. args: targets - the targets to select """ for package in ['gcc', 'binutils']: for target in targets: # Pick the first version in the numbered list as the selected one. desired = GetDesiredPackageVersions(target, package) desired_num = VersionListToNumeric(target, package, desired, True) desired = desired_num[0] # *-config does not play revisions, strip them, keep just PV. desired = portage.versions.pkgsplit('%s-%s' % (package, desired))[1] if target == 'host': # *-config is the only tool treating host identically (by tuple). target = toolchain.GetHostTuple() # And finally, attach target to it. desired = '%s-%s' % (target, desired) # Target specific hacks if package in suffixes: if target in suffixes[package]: desired += suffixes[package][target] extra_env = {'CHOST': target} cmd = ['%s-config' % package, '-c', target] current = cros_build_lib.RunCommand( cmd, print_cmd=False, redirect_stdout=True, extra_env=extra_env).output.splitlines()[0] # Do not gcc-config when the current is live or nothing needs to be done. if current != desired and current != '9999': cmd = [package + '-config', desired] cros_build_lib.RunCommand(cmd, print_cmd=False) # run sysroot-config to update links to gcc wrappers for cross targets for target in targets: if target == 'host': continue cmd = ['sysroot-config', '--install-links', target] cros_build_lib.RunCommand(cmd, print_cmd=False)
def GetConfig(cls, target): """Returns a map of crossdev provided variables about a tuple.""" CACHE_ATTR = '_target_tuple_map' val = cls._CACHE.setdefault(CACHE_ATTR, {}) if not target in val: # Find out the crossdev tuple. target_tuple = target if target == 'host': target_tuple = toolchain.GetHostTuple() # Catch output of crossdev. out = cros_build_lib.RunCommand( ['crossdev', '--show-target-cfg', '--ex-gdb', target_tuple], print_cmd=False, redirect_stdout=True).output.splitlines() # List of tuples split at the first '=', converted into dict. val[target] = dict([x.split('=', 1) for x in out]) return val[target]
def _ProcessBinutilsConfig(target, output_dir): """Do what binutils-config would have done""" binpath = os.path.join('/bin', target + '-') # Locate the bin dir holding the gold linker. binutils_bin_path = os.path.join(output_dir, 'usr', toolchain.GetHostTuple(), target, 'binutils-bin') globpath = os.path.join(binutils_bin_path, '*-gold') srcpath = glob.glob(globpath) if not srcpath: # Maybe this target doesn't support gold. globpath = os.path.join(binutils_bin_path, '*') srcpath = glob.glob(globpath) assert len(srcpath) == 1, ('%s: matched more than one path (but not *-gold)' % globpath) srcpath = srcpath[0] ld_path = os.path.join(srcpath, 'ld') assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path ld_path = os.path.join(srcpath, 'ld.bfd') assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path ld_path = os.path.join(srcpath, 'ld.gold') assert not os.path.exists(ld_path), ('%s: exists, but gold dir does not!' % ld_path) # Nope, no gold support to be found. gold_supported = False logging.warning('%s: binutils lacks support for the gold linker', target) else: assert len(srcpath) == 1, '%s: did not match exactly 1 path' % globpath srcpath = srcpath[0] # Package the binutils-bin directory without the '-gold' suffix # if gold is not enabled as the default linker for this target. gold_supported = CONFIG_TARGET_SUFFIXES['binutils'].get(target) == '-gold' if not gold_supported: srcpath = srcpath[:-len('-gold')] ld_path = os.path.join(srcpath, 'ld') assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path srcpath = srcpath[len(output_dir):] gccpath = os.path.join('/usr', 'libexec', 'gcc') for prog in os.listdir(output_dir + srcpath): # Skip binaries already wrapped. if not prog.endswith('.real'): GeneratePathWrapper(output_dir, binpath + prog, os.path.join(srcpath, prog)) GeneratePathWrapper(output_dir, os.path.join(gccpath, prog), os.path.join(srcpath, prog)) libpath = os.path.join('/usr', toolchain.GetHostTuple(), target, 'lib') envd = os.path.join(output_dir, 'etc', 'env.d', 'binutils', '*') if gold_supported: envd += '-gold' else: # If gold is not enabled as the default linker and 2 env.d # files exist, pick the one without the '-gold' suffix. envds = sorted(glob.glob(envd)) if len(envds) == 2 and envds[1] == envds[0] + '-gold': envd = envds[0] srcpath = _EnvdGetVar(envd, 'LIBPATH') os.symlink(os.path.relpath(srcpath, os.path.dirname(libpath)), output_dir + libpath)