def DriverMain(module, argv): # TODO(robertm): this is ugly - try to get rid of this if '--pnacl-driver-verbose' in argv: Log.IncreaseVerbosity() env.set('LOG_VERBOSE', '1') # driver_path has the form: /foo/bar/pnacl_root/newlib/bin/pnacl-clang driver_path = pathtools.abspath(pathtools.normalize(argv[0])) driver_bin = pathtools.dirname(driver_path) script_name = pathtools.basename(driver_path) env.set('SCRIPT_NAME', script_name) env.set('DRIVER_PATH', driver_path) env.set('DRIVER_BIN', driver_bin) Log.SetScriptName(script_name) ReadConfig() if IsWindowsPython(): SetupCygwinLibs() # skip tool name argv = argv[1:] # Handle help info if ('--help' in argv or '-h' in argv or '-help' in argv or '--help-full' in argv): help_func = getattr(module, 'get_help', None) if not help_func: Log.Fatal(HelpNotAvailable()) helpstr = help_func(argv) print helpstr return 0 return module.main(argv)
def MakeSelUniversalScriptForLD(ld_flags, llc_outputs, files, outfile): """ Return sel_universal script text for invoking LD.nexe with the given ld_flags, llc_outputs (which are treated specially), and other input files (for native libraries). The output will be written to outfile. """ script = [] # Open the output file. script.append('readwrite_file nexefile %s' % outfile) files_to_map = list(files) # Create a reverse-service mapping for each input file and add it to # the sel universal script. for f in files_to_map: basename = pathtools.basename(f) # If we are using the dummy shim, map it with the filename of the real # shim, so the baked-in commandline will work. if basename == 'libpnacl_irt_shim_dummy.a': basename = 'libpnacl_irt_shim.a' script.append('reverse_service_add_manifest_mapping files/%s %s' % (basename, f)) modules = len(llc_outputs) script.extend([ 'readonly_file objfile%d %s' % (i, f) for i, f in zip(range(modules), llc_outputs) ]) script.append('rpc RunWithSplit i(%d) ' % modules + ' '.join(['h(objfile%s)' % m for m in range(modules)] + ['h(invalid)' for x in range(modules, 16)]) + ' h(nexefile) *') script.append('echo "ld complete"') script.append('') return '\n'.join(script)
def MakeSelUniversalScriptForLD(ld_flags, llc_outputs, files, outfile): """ Return sel_universal script text for invoking LD.nexe with the given ld_flags, llc_outputs (which are treated specially), and other input files (for native libraries). The output will be written to outfile. """ script = [] # Open the output file. script.append('readwrite_file nexefile %s' % outfile) files_to_map = list(files) # Create a reverse-service mapping for each input file and add it to # the sel universal script. for f in files_to_map: basename = pathtools.basename(f) # If we are using the dummy shim, map it with the filename of the real # shim, so the baked-in commandline will work. if basename == 'libpnacl_irt_shim_dummy.a': basename = 'libpnacl_irt_shim.a' script.append('reverse_service_add_manifest_mapping files/%s %s' % (basename, f)) modules = len(llc_outputs) script.extend(['readonly_file objfile%d %s' % (i, f) for i, f in zip(range(modules), llc_outputs)]) script.append('rpc RunWithSplit i(%d) ' % modules + ' '.join(['h(objfile%s)' % m for m in range(modules)] + ['h(invalid)' for x in range(modules, 16)]) + ' h(nexefile) *') script.append('echo "ld complete"') script.append('') return '\n'.join(script)
def FindBaseToolchain(): """ Find toolchain/OS_ARCH directory """ base_dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain') if base_dir is None: Log.Fatal("Unable to find 'toolchain' directory") toolchain_dir = os.path.join(base_dir, '%s_%s' % (GetOSName(), GetArchNameShort())) return shell.escape(toolchain_dir)
def FindBaseToolchain(): """ Find toolchain/OS_ARCH directory """ base_dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain') if base_dir is None: Log.Fatal("Unable to find 'toolchain' directory") toolchain_dir = os.path.join( base_dir, '%s_%s' % (GetOSName(), GetArchNameShort()) ) return shell.escape(toolchain_dir)
def DefaultOutputName(filename, outtype): if outtype in ('pp', 'dis'): return '-' # stdout base = pathtools.basename(filename) base = RemoveExtension(base) if outtype in ('po'): return base + '.o' assert (outtype in ExtensionMap.values()) assert (not IsSourceType(outtype)) return base + '.' + outtype
def DefaultOutputName(filename, outtype): if outtype in ('pp','dis'): return '-' # stdout base = pathtools.basename(filename) base = RemoveExtension(base) if outtype in ('po'): return base + '.o' assert(outtype in ExtensionMap.values()) assert(not IsSourceType(outtype)) return base + '.' + outtype
def DefaultOutputName(filename, outtype): # For pre-processor mode, just print to stdout. if outtype in ('pp'): return '-' base = pathtools.basename(filename) base = RemoveExtension(base) if outtype in ('po'): return base + '.o' assert(outtype in filetype.ExtensionMap.values()) assert(not filetype.IsSourceType(outtype)) return base + '.' + outtype
def __init__(self, inputs, output): self.TempBase = tempfile.mkdtemp() inputs = [ pathtools.abspath(i) for i in inputs ] output = pathtools.basename(output) TempFiles.add(self.TempBase) self.Output = output + '---linked' # Build the initial mapping self.TempMap = dict() for f in inputs: if f.startswith('-'): continue path = PathSplit(f) self.TempMap[f] = [1, path] def MangledName(path): return output + '---' + '_'.join(path[-n:]) + '---' while True: # Find conflicts ConflictMap = dict() Conflicts = set() for (f, [n, path]) in self.TempMap.iteritems(): candidate = pathtools.abspath(MangledName(path)) if candidate in ConflictMap: Conflicts.add(ConflictMap[candidate]) Conflicts.add(f) else: ConflictMap[candidate] = f if len(Conflicts) == 0: break # Resolve conflicts for f in Conflicts: n = self.TempMap[f][0] if n+1 > len(self.TempMap[f][1]): Log.Fatal('Unable to resolve naming conflicts') self.TempMap[f][0] = n+1 # Clean up the map and put the paths in tempdir NewMap = dict() for (f, [n, path]) in self.TempMap.iteritems(): NewMap[f] = os.path.join(self.TempBase, MangledName(path)) self.TempMap = NewMap return
def FindBasePNaCl(): """ Find the base directory of the PNaCl toolchain """ # The bin/ directory is one of: # <base>/bin if <base> is /path/to/pnacl_translator # <base>/newlib/bin or <base>/glibc/bin otherwise bindir = env.getone('DRIVER_BIN') # If this is a translator dir, use pnacl_translator translator_dir = FindBaseDir( lambda cur: pathtools.basename(cur) == 'pnacl_translator') if translator_dir is not None: return shell.escape(translator_dir) # Else use ../.. basedir = pathtools.dirname(pathtools.dirname(bindir)) return shell.escape(basedir)
def __init__(self, inputs, output): self.TempBase = tempfile.mkdtemp() inputs = [pathtools.abspath(i) for i in inputs] output = pathtools.basename(output) TempFiles.add(self.TempBase) self.Output = output + '---linked' # Build the initial mapping self.TempMap = dict() for f in inputs: if f.startswith('-'): continue path = PathSplit(f) self.TempMap[f] = [1, path] def MangledName(path): return output + '---' + '_'.join(path[-n:]) + '---' while True: # Find conflicts ConflictMap = dict() Conflicts = set() for (f, [n, path]) in self.TempMap.iteritems(): candidate = pathtools.abspath(MangledName(path)) if candidate in ConflictMap: Conflicts.add(ConflictMap[candidate]) Conflicts.add(f) else: ConflictMap[candidate] = f if len(Conflicts) == 0: break # Resolve conflicts for f in Conflicts: n = self.TempMap[f][0] if n + 1 > len(self.TempMap[f][1]): Log.Fatal('Unable to resolve naming conflicts') self.TempMap[f][0] = n + 1 # Clean up the map and put the paths in tempdir NewMap = dict() for (f, [n, path]) in self.TempMap.iteritems(): NewMap[f] = os.path.join(self.TempBase, MangledName(path)) self.TempMap = NewMap return
def FindBaseNaCl(): """ Find native_client/ directory """ dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'native_client') if dir is None: Log.Fatal("Unable to find 'native_client' directory") return shell.escape(dir)
def FindBaseToolchain(): """ Find toolchain/ directory """ dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain') if dir is None: Log.Fatal("Unable to find 'toolchain' directory") return shell.escape(dir)