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 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 GetNativeLibsDirname(other_inputs): """Check that native libs have a common directory and return the directory.""" dirname = None for f in other_inputs: if IsFlag(f): continue else: if not pathtools.exists(f): Log.Fatal("Unable to open '%s'", pathtools.touser(f)) if dirname is None: dirname = pathtools.dirname(f) else: if dirname != pathtools.dirname(f): Log.Fatal('Need a common directory for native libs: %s != %s', dirname, pathtools.dirname(f)) if not dirname: Log.Fatal('No native libraries found') return dirname + '/'
def FindBaseDir(function): Depth = 0 cur = env.getone('DRIVER_BIN') while not function(cur) and Depth < 16: cur = pathtools.dirname(cur) Depth += 1 if function(cur): return cur return None
def GetNativeLibsDirname(other_inputs): """Check that native libs have a common directory and return the directory.""" dirname = None for f in other_inputs: if IsFlag(f): continue else: if not pathtools.exists(f): Log.Fatal("Unable to open '%s'", pathtools.touser(f)) if dirname is None: dirname = pathtools.dirname(f) else: if dirname != pathtools.dirname(f): Log.Fatal( 'Need a common directory for native libs: %s != %s', dirname, pathtools.dirname(f)) if not dirname: Log.Fatal('No native libraries found') return dirname + '/'
def GetThinArchiveData(archive_filename, member, strtab_data): # Get member's filename (relative to the archive) and open the member # ourselves to check the data. member_filename = GetMemberFilename(member, strtab_data) member_filename = pathtools.join( pathtools.dirname(pathtools.abspath(archive_filename)), member_filename) member_fp = driver_log.DriverOpen(member_filename, 'rb') data = member_fp.read(member.size) member_fp.close() return data
def __init__(self, inputs, output): inputs = [ pathtools.abspath(i) for i in inputs ] output = pathtools.abspath(output) self.TempBase = output + '---linked' self.OutputDir = pathtools.dirname(output) # TODO(pdox): Figure out if there's a less confusing way # to simplify the intermediate filename in this case. #if len(inputs) == 1: # # There's only one input file, don't bother adding the source name. # TempMap[inputs[0]] = output + '---' # return # Build the initial mapping self.TempMap = dict() for f in inputs: if f.startswith('-'): continue path = PathSplit(f) self.TempMap[f] = [1, path] while True: # Find conflicts ConflictMap = dict() Conflicts = set() for (f, [n, path]) in self.TempMap.iteritems(): candidate = output + '---' + '_'.join(path[-n:]) + '---' 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 NewMap = dict() for (f, [n, path]) in self.TempMap.iteritems(): candidate = output + '---' + '_'.join(path[-n:]) + '---' NewMap[f] = candidate self.TempMap = NewMap return
def __init__(self, inputs, output): inputs = [pathtools.abspath(i) for i in inputs] output = pathtools.abspath(output) self.TempBase = output + '---linked' self.OutputDir = pathtools.dirname(output) # TODO(pdox): Figure out if there's a less confusing way # to simplify the intermediate filename in this case. #if len(inputs) == 1: # # There's only one input file, don't bother adding the source name. # TempMap[inputs[0]] = output + '---' # return # Build the initial mapping self.TempMap = dict() for f in inputs: if f.startswith('-'): continue path = PathSplit(f) self.TempMap[f] = [1, path] while True: # Find conflicts ConflictMap = dict() Conflicts = set() for (f, [n, path]) in self.TempMap.iteritems(): candidate = output + '---' + '_'.join(path[-n:]) + '---' 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 NewMap = dict() for (f, [n, path]) in self.TempMap.iteritems(): candidate = output + '---' + '_'.join(path[-n:]) + '---' NewMap[f] = candidate self.TempMap = NewMap return
def FindBasePNaCl(): """ Find the base directory of the PNaCl toolchain """ # The <base> directory is one level up from the <base>/bin: bindir = env.getone('DRIVER_BIN') basedir = pathtools.dirname(bindir) return shell.escape(basedir)