import shlex
import signal
import subprocess
-import struct
import sys
import tempfile
-import artools
import elftools
-import ldtools
# filetype needs to be imported here because pnacl-driver injects calls to
# filetype.ForceFileType into argument parse actions.
# TODO(dschuff): That's ugly. Find a better way.
from driver_env import env
# TODO: import driver_log and change these references from 'foo' to
# 'driver_log.foo', or split driver_log further
-from driver_log import Log, DriverOpen, DriverClose, StringifyCommand, TempFiles, DriverExit, FixArch
+from driver_log import Log, DriverOpen, DriverClose, StringifyCommand, DriverExit, FixArch
+from driver_temps import TempFiles
from shelltools import shell
def ParseError(s, leftpos, rightpos, msg):
Log.Fatal('machine/os ' + '-'.join(tokens[1:]) + ' not supported.')
+def GetOSName():
+ if sys.platform == 'darwin':
+ os_name = 'mac'
+ elif sys.platform.startswith('linux'):
+ os_name = 'linux'
+ elif sys.platform in ('cygwin', 'win32'):
+ os_name = 'win'
+ else:
+ Log.Fatal('Machine: %s not supported.' % sys.platform)
+
+ return os_name
+
+def GetArchNameShort():
+ machine = platform.machine().lower()
+ if machine.startswith('arm'):
+ return 'arm'
+ elif machine.startswith('mips'):
+ return 'mips'
+ elif (machine.startswith('x86')
+ or machine in ('amd32', 'i386', 'i686', 'ia32', '32', 'amd64', '64')):
+ return 'x86'
+
+ Log.Fatal('Architecture: %s not supported.' % machine)
+ return 'unknown'
+
def RunDriver(invocation, args, suppress_inherited_arch_args=False):
"""
RunDriver() is used to invoke "driver" tools, e.g.
@env.register
@memoize
def FindBaseToolchain():
- """ Find toolchain/ directory """
- dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain')
- if dir is None:
+ """ 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")
- return shell.escape(dir)
+ toolchain_dir = os.path.join(
+ base_dir,
+ '%s_%s' % (GetOSName(), GetArchNameShort())
+ )
+ return shell.escape(toolchain_dir)
@env.register
@memoize
""" 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)):
+ if os.path.exists(pathtools.join(prefix, 'bin',
+ tool + env.getone('EXEC_EXT'))):
return prefix
base_pnacl = FindBasePNaCl()
( '--pnacl-i686-bias', "env.set('BIAS', 'X8632')"),
( '--pnacl-x86_64-bias', "env.set('BIAS', 'X8664')"),
( '--pnacl-bias=(.+)', "env.set('BIAS', FixArch($0))"),
- ( '--pnacl-default-command-line', "env.set('USE_DEFAULT_CMD_LINE', '1')"),
( '-save-temps', "env.set('SAVE_TEMPS', '1')"),
( '-no-save-temps', "env.set('SAVE_TEMPS', '0')"),
( ('-B', '(.*)'), AddHostBinarySearchPath),
# add parent directories. Rinse, repeat.
class TempNameGen(object):
def __init__(self, inputs, output):
+ self.TempBase = tempfile.mkdtemp()
inputs = [ pathtools.abspath(i) for i in inputs ]
- output = pathtools.abspath(output)
+ output = pathtools.basename(output)
+
+ TempFiles.add(self.TempBase)
- self.TempBase = output + '---linked'
+ self.Output = output + '---linked'
- # 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()
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 = output + '---' + '_'.join(path[-n:]) + '---'
+ candidate = pathtools.abspath(MangledName(path))
if candidate in ConflictMap:
Conflicts.add(ConflictMap[candidate])
Conflicts.add(f)
Log.Fatal('Unable to resolve naming conflicts')
self.TempMap[f][0] = n+1
- # Clean up the map
+ # Clean up the map and put the paths in tempdir
NewMap = dict()
for (f, [n, path]) in self.TempMap.iteritems():
- candidate = output + '---' + '_'.join(path[-n:]) + '---'
- NewMap[f] = candidate
+ NewMap[f] = os.path.join(self.TempBase, MangledName(path))
self.TempMap = NewMap
return
def TempNameForOutput(self, imtype):
- temp = self.TempBase + '.' + imtype
- if not env.getbool('SAVE_TEMPS'):
- TempFiles.add(temp)
+ temp = os.path.join(self.TempBase, self.Output + '.' + imtype)
+ TempFiles.add(temp)
return temp
def TempNameForInput(self, input, imtype):
fullpath = pathtools.abspath(input)
- # If input is already a temporary name, just change the extension
+ # If input is already a temporary name, just add an extension
if fullpath.startswith(self.TempBase):
- temp = self.TempBase + '.' + imtype
+ temp = fullpath + '.' + imtype
else:
# Source file
temp = self.TempMap[fullpath] + '.' + imtype
-
- if not env.getbool('SAVE_TEMPS'):
- TempFiles.add(temp)
+ TempFiles.add(temp)
return temp
# (Invoked from loader.py)
def SetArch(arch):
- env.set('ARCH', FixArch(arch))
+ arch = FixArch(arch)
+ env.set('ARCH', arch)
+
+ nonsfi_nacl = False
+ if arch.endswith('_NONSFI'):
+ arch = arch[:-len('_NONSFI')]
+ nonsfi_nacl = True
+ env.set('BASE_ARCH', arch)
+ env.setbool('NONSFI_NACL', nonsfi_nacl)
+
def GetArch(required = False):
arch = env.getone('ARCH')