From b3a3f6da6b8dc0345db8b3d17e0f81db9adc99b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= <lfrb@collabora.com> Date: Wed, 14 Dec 2016 14:35:24 -0500 Subject: [PATCH] Only give compiler hint if not compiling natively MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If sysroot is None, it means we want to compile natively (e.g. for the simulator or for a target device with the same arch) Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com> Reviewed-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk> Differential Revision: https://phabricator.apertis.org/D5286 --- tools/ade | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/tools/ade b/tools/ade index 103bccd..1d24e57 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)) -- GitLab