diff --git a/tools/ade b/tools/ade index 103bccd5676eb4c519b4452a4041756bbf1a30ef..1d24e57e6924d3a266f53d7ab84fa744efb5aa26 100755 --- a/tools/ade +++ b/tools/ade @@ -174,7 +174,14 @@ class TargetTriplet: class Simulator: def __init__(self): - pass + try: + with open('/etc/image_version') as f: + self.version = SysrootVersion.from_string(f.read()) + with open('/usr/lib/pkg-config.multiarch') as f: + self.version.arch = TargetTriplet(f.read().strip()).arch + except FileNotFoundError: + # Missing file means we can't use the simulator + raise NotInstalledError def _exec(self, *args): r = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -696,9 +703,9 @@ class Project: p = subprocess.Popen(args, cwd=self.root, env=env) p.wait() - def configure(self, sysroot, debug=False, force=False, cflags=[], ldflags=[], args=[]): + def configure(self, target, debug=False, force=False, cflags=[], ldflags=[], args=[]): + triplet = TargetTriplet(target.version.arch) env = os.environ.copy() - triplet = TargetTriplet(sysroot.version.arch) args = ["./configure"] args += ["--prefix=/Applications/" + self.bundle_id] args += ["--localstatedir=/var/Applications/" + self.bundle_id + "/var"] @@ -707,21 +714,22 @@ class Project: cflags += ["-g"] cflags += ["-O0"] - if sysroot: - cflags += ["--sysroot=" + sysroot.path] - cflags += ["-I" + os.path.join(sysroot.path, 'usr', 'include')] - ldflags += ["--sysroot=" + sysroot.path] + # Extra configure options are needed if configuring for a sysroot + if isinstance(target, Sysroot): + cflags += ["--sysroot=" + target.path] + cflags += ["-I" + os.path.join(target.path, 'usr', 'include')] + ldflags += ["--sysroot=" + target.path] args += ["--host=" + triplet.triplet] - args += ["--with-sysroot=" + sysroot.path] - self.set_pkg_config_vars(env, sysroot) + args += ["--with-sysroot=" + target.path] + self.set_pkg_config_vars(env, target) if not os.path.exists(os.path.join(self.root, "configure")): self.autoreconf() - env['CC'] = "{}-{}".format(triplet.triplet, "gcc") - env['LD'] = "{}-{}".format(triplet.triplet, "ld") env['CFLAGS'] = ' '.join(cflags) env['LDFLAGS'] = ' '.join(ldflags) + env['CC'] = "{}-{}".format(triplet.triplet, "gcc") + env['LD'] = "{}-{}".format(triplet.triplet, "ld") p = subprocess.Popen(args, cwd=self.root, env=env) p.wait() @@ -921,7 +929,10 @@ class Ade: except Exception as e: self.die("Invalid SDK installation: {0}".format(e)) elif self.simulator and Simulator in classes: - obj = Simulator() + try: + obj = Simulator() + except NotInstalledError: + self.die("Couldn't use simulator; not running in a SDK distribution") elif self.sysroot and Sysroot in classes: try: version = SysrootVersion.from_id(self.sysroot) @@ -1182,24 +1193,21 @@ class Ade: def do_configure(self): target = self.get_target() - sysroot = None - if isinstance(target, Sysroot): - sysroot = target - elif isinstance(target, Device): + if isinstance(target, Device): sdk = self.get_sdk() version = target.version if sdk and version.is_compatible(sdk.version): - sysroot = None # Native compilation; SDK version matches device image version + target = sdk # Native compilation; SDK version matches device image version else: - sysroot = self.get_sysroot_manager().get_installed(version) - if not sysroot: + target = self.get_sysroot_manager().get_installed(version) + if not target: self.die("No sysroot currently installed for {0}{1}{2}" .format(Colors.OKBLUE, version.get_name(), Colors.ENDC)) try: project = Project(bundle_id=self.bundle_id) - project.configure(sysroot, debug=self.debug, force=self.force, args=self.args) + project.configure(target, debug=self.debug, force=self.force, args=self.args) except Exception as e: self.die("Couldn't configure project: {0}".format(e))