def main(argv): env.update(EXTRA_ENV) driver_tools.ParseArgs(argv, DISPatterns) inputs = env.get('INPUTS') output = env.getone('OUTPUT') if len(inputs) == 0: Log.Fatal("No input files given") if len(inputs) > 1 and output != '': Log.Fatal("Cannot have -o with multiple inputs") for infile in inputs: env.push() env.set('input', infile) env.set('output', output) # When we output to stdout, set redirect_stdout and set log_stdout # to False to bypass the driver's line-by-line handling of stdout # which is extremely slow when you have a lot of output if (filetype.IsLLVMBitcode(infile) or filetype.IsPNaClBitcode(infile)): bitcodetype = 'PNaCl' if filetype.IsPNaClBitcode( infile) else 'LLVM' format = bitcodetype.lower() if env.has('FILE_TYPE'): sys.stdout.write('%s: %s bitcode\n' % (infile, bitcodetype)) continue env.append('FLAGS', '-bitcode-format=' + format) if output == '': # LLVM by default outputs to a file if -o is missing # Let's instead output to stdout env.set('output', '-') env.append('FLAGS', '-f') driver_tools.Run('${LLVM_DIS} ${FLAGS} ${input} -o ${output}') elif filetype.IsELF(infile): if env.has('FILE_TYPE'): sys.stdout.write('%s: ELF\n' % infile) continue flags = env.get('FLAGS') if len(flags) == 0: env.append('FLAGS', '-d') if output == '': # objdump to stdout driver_tools.Run('"${OBJDUMP}" ${FLAGS} ${input}') else: # objdump always outputs to stdout, and doesn't recognize -o # Let's add this feature to be consistent. fp = DriverOpen(output, 'w') driver_tools.Run('${OBJDUMP} ${FLAGS} ${input}', redirect_stdout=fp) DriverClose(fp) else: Log.Fatal('Unknown file type') env.pop() # only reached in case of no errors return 0
def main(argv): env.update(EXTRA_ENV) driver_tools.ParseArgs(argv, DISPatterns) inputs = env.get('INPUTS') output = env.getone('OUTPUT') if len(inputs) == 0: Log.Fatal("No input files given") if len(inputs) > 1 and output != '': Log.Fatal("Cannot have -o with multiple inputs") for infile in inputs: env.push() env.set('input', infile) env.set('output', output) # When we output to stdout, set redirect_stdout and set log_stdout # to False to bypass the driver's line-by-line handling of stdout # which is extremely slow when you have a lot of output if (filetype.IsLLVMBitcode(infile) or filetype.IsPNaClBitcode(infile)): bitcodetype = 'PNaCl' if filetype.IsPNaClBitcode(infile) else 'LLVM' format = bitcodetype.lower() if env.has('FILE_TYPE'): sys.stdout.write('%s: %s bitcode\n' % (infile, bitcodetype)) continue env.append('FLAGS', '-bitcode-format=' + format) if output == '': # LLVM by default outputs to a file if -o is missing # Let's instead output to stdout env.set('output', '-') env.append('FLAGS', '-f') driver_tools.Run('${LLVM_DIS} ${FLAGS} ${input} -o ${output}') elif filetype.IsELF(infile): if env.has('FILE_TYPE'): sys.stdout.write('%s: ELF\n' % infile) continue flags = env.get('FLAGS') if len(flags) == 0: env.append('FLAGS', '-d') if output == '': # objdump to stdout driver_tools.Run('"${OBJDUMP}" ${FLAGS} ${input}') else: # objdump always outputs to stdout, and doesn't recognize -o # Let's add this feature to be consistent. fp = DriverOpen(output, 'w') driver_tools.Run('${OBJDUMP} ${FLAGS} ${input}', redirect_stdout=fp) DriverClose(fp) else: Log.Fatal('Unknown file type') env.pop() # only reached in case of no errors return 0
def ReadConfig(): # Mock out ReadConfig if running unittests. Settings are applied directly # by DriverTestEnv rather than reading this configuration file. if env.has('PNACL_RUNNING_UNITTESTS'): return driver_bin = env.getone('DRIVER_BIN') driver_conf = pathtools.join(driver_bin, 'driver.conf') fp = DriverOpen(driver_conf, 'r') linecount = 0 for line in fp: linecount += 1 line = line.strip() if line == '' or line.startswith('#'): continue sep = line.find('=') if sep < 0: Log.Fatal("%s: Parse error, missing '=' on line %d", pathtools.touser(driver_conf), linecount) keyname = line[:sep].strip() value = line[sep + 1:].strip() env.setraw(keyname, value) DriverClose(fp) if env.getone('LIBMODE') not in ('newlib', 'glibc'): Log.Fatal('Invalid LIBMODE in %s', pathtools.touser(driver_conf))
def ReadConfig(): # Mock out ReadConfig if running unittests. Settings are applied directly # by DriverTestEnv rather than reading this configuration file. if env.has('PNACL_RUNNING_UNITTESTS'): return driver_bin = env.getone('DRIVER_BIN') driver_conf = pathtools.join(driver_bin, 'driver.conf') fp = DriverOpen(driver_conf, 'r') linecount = 0 for line in fp: linecount += 1 line = line.strip() if line == '' or line.startswith('#'): continue sep = line.find('=') if sep < 0: Log.Fatal("%s: Parse error, missing '=' on line %d", pathtools.touser(driver_conf), linecount) keyname = line[:sep].strip() value = line[sep+1:].strip() env.setraw(keyname, value) DriverClose(fp) if env.getone('LIBMODE') not in ('newlib', 'glibc'): Log.Fatal('Invalid LIBMODE in %s', pathtools.touser(driver_conf))
def FindBaseHost(tool): """ Find the base directory for host binaries (i.e. llvm/binutils) """ if env.has('BPREFIXES'): for prefix in env.get('BPREFIXES'): if os.path.exists(pathtools.join(prefix, 'bin', tool + env.getone('EXEC_EXT'))): return prefix base_pnacl = FindBasePNaCl() if not pathtools.exists(pathtools.join(base_pnacl, 'bin', tool + env.getone('EXEC_EXT'))): Log.Fatal('Could not find PNaCl host directory for ' + tool) return base_pnacl
def CheckPathLength(filename, exit_on_failure=True): '''Check that the length of the path is short enough for Windows. On Windows, MAX_PATH is ~260 and applies to absolute paths, and to relative paths and the absolute paths they expand to (except for specific uses of some APIs; see link below). Most applications don't bother to support long paths properly (including LLVM, GNU binutils, and ninja). If a path is too long, ERROR_PATH_NOT_FOUND is returned, which isn't very useful or clear for users. In addition the Chrome build has deep directory hierarchies with long names. This function checks that the path is valid, so we can throw meaningful errors. http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx ''' if not IsWindowsPython() and not env.has('PNACL_RUNNING_UNITTESTS'): return True # First check the name as-is (it's usually a relative path) if len(filename) > 255: if exit_on_failure: Log.Fatal('Path name %s is too long (%d characters)' % (filename, len(filename))) return False if os.path.isabs(filename): return True # Don't assume that the underlying tools or windows APIs will normalize # the path before using it. Conservatively count the length of CWD + filename appended_name = os.path.join(os.getcwd(), filename) if len(appended_name) > 255: if exit_on_failure: Log.Fatal( 'Path name %s (expanded from %s) is too long (%d characters)' % (appended_name, filename, len(appended_name))) return False return True
def CheckPathLength(filename, exit_on_failure=True): '''Check that the length of the path is short enough for Windows. On Windows, MAX_PATH is ~260 and applies to absolute paths, and to relative paths and the absolute paths they expand to (except for specific uses of some APIs; see link below). Most applications don't bother to support long paths properly (including LLVM, GNU binutils, and ninja). If a path is too long, ERROR_PATH_NOT_FOUND is returned, which isn't very useful or clear for users. In addition the Chrome build has deep directory hierarchies with long names. This function checks that the path is valid, so we can throw meaningful errors. http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx ''' if not IsWindowsPython() and not env.has('PNACL_RUNNING_UNITTESTS'): return True # First check the name as-is (it's usually a relative path) if len(filename) > 255: if exit_on_failure: Log.Fatal('Path name %s is too long (%d characters)' % (filename, len(filename))) return False if os.path.isabs(filename): return True # Don't assume that the underlying tools or windows APIs will normalize # the path before using it. Conservatively count the length of CWD + filename appended_name = os.path.join(os.getcwd(), filename) if len(appended_name) > 255: if exit_on_failure: Log.Fatal('Path name %s (expanded from %s) is too long (%d characters)' % (appended_name, filename, len(appended_name))) return False return True
def CheckSetup(): if not env.has('IS_CXX'): Log.Fatal('"pnacl-driver" cannot be used directly. ' 'Use pnacl-clang or pnacl-clang++.')