summaryrefslogtreecommitdiffstats
path: root/scripts/configure_helper.py
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2017-11-09 23:02:54 +0100
committerMichael Olbrich <m.olbrich@pengutronix.de>2017-11-10 19:19:41 +0100
commit3829a75eab0871b1466589d93f57874355a94406 (patch)
tree33a7aaa4365534258215ce3eaa99911e1fdbcde2 /scripts/configure_helper.py
parentd00d8a830d505dc5eaf9bc988c897f22a14ae11f (diff)
downloadptxdist-3829a75eab0871b1466589d93f57874355a94406.tar.gz
ptxdist-3829a75eab0871b1466589d93f57874355a94406.tar.xz
configure_helper.py: add meson support
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts/configure_helper.py')
-rwxr-xr-xscripts/configure_helper.py143
1 files changed, 135 insertions, 8 deletions
diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
index 48e2a284e..fa6bdbd93 100755
--- a/scripts/configure_helper.py
+++ b/scripts/configure_helper.py
@@ -15,6 +15,8 @@ import re
import difflib
import argparse
import shlex
+import json
+import io
configure_blacklist = [
"help",
@@ -93,6 +95,43 @@ configure_blacklist = [
"static",
]
+meson_blacklist = [
+ "c_std",
+ "cpp_debugstl",
+ "cpp_std",
+ "b_asneeded",
+ "b_colorout",
+ "b_coverage",
+ "b_lto",
+ "b_lundef",
+ "b_ndebug",
+ "b_pch",
+ "b_pgo",
+ "b_sanitize",
+ "b_staticpic",
+ "bindir",
+ "datadir",
+ "default_library",
+ "errorlogs",
+ "includedir",
+ "infodir",
+ "layout",
+ "libexecdir",
+ "localedir",
+ "localstatedir",
+ "mandir",
+ "sbindir",
+ "sharedstatedir",
+ "stdsplit",
+ "strip",
+ "sysconfdir",
+ "unity",
+ "warning_level",
+ "werror",
+
+ "bashcompletiondir",
+]
+
def abort(message):
print(message)
print("\nSee '%s --help' for more details." % cmd)
@@ -106,6 +145,7 @@ def ask_ptxdist(pkg):
"/print-%s_CONF_OPT" % pkg,
"/print-%s_AUTOCONF" % pkg,
"/print-%s_CONF_TOOL" %pkg,
+ "/print-CROSS_MESON_USR",
"/print-CROSS_AUTOCONF_USR"],
stdout=subprocess.PIPE,
universal_newlines=True)
@@ -114,14 +154,17 @@ def ask_ptxdist(pkg):
subdir = p.stdout.readline().strip()
opt = shlex.split(p.stdout.readline().strip()) + shlex.split(p.stdout.readline().strip())
tool = p.stdout.readline().strip()
- default = shlex.split(p.stdout.readline().strip())
+ meson_default = shlex.split(p.stdout.readline().strip())
+ autoconf_default = shlex.split(p.stdout.readline().strip())
+ if tool == "meson" and not opt:
+ opt = meson_default
if tool == "autoconf" and not opt:
- opt = default
+ opt = autoconf_default
if not d:
abort("'%s' is not a valid package: %s_DIR is undefined" % (pkg, pkg))
if not opt:
- abort("'%s' is not a autoconf package: %s_CONF_OPT and %s_AUTOCONF are undefined" % (pkg, pkg, pkg))
- return (d, subdir, opt)
+ abort("'%s' is not a autoconf/meson package: %s_CONF_OPT and %s_AUTOCONF are undefined" % (pkg, pkg, pkg))
+ return (tool, d, subdir, opt)
def blacklist_hit(name, blacklist):
for e in blacklist:
@@ -148,6 +191,49 @@ def parse_configure_args(args, blacklist):
"blacklist": blacklist_hit(groups[2], blacklist)})
return ret
+meson_parse_args_re = re.compile("-D(.*)=(.*)")
+def parse_meson_args(args, blacklist):
+ ret = []
+ new_args = []
+ last_args = []
+ last = None
+ for arg in args:
+ if last != None:
+ name = last
+ value = arg
+ # Most --* args show up as generic arguments at the end
+ if name != "cross-file":
+ last_args.append("-D%s=%s" % (name, value))
+ last = None
+ else:
+ if arg.startswith("--"):
+ last = arg[2:]
+ continue
+ else:
+ last = None
+ r = meson_parse_args_re.match(arg)
+ if not r:
+ continue
+ groups = r.groups()
+ name = groups[0]
+ value = groups[1]
+ new_args.append(arg)
+
+ found = False
+ for e in ret:
+ if name == e["name"]:
+ found = True
+ break
+ if found:
+ continue
+ try:
+ value = json.load(io.StringIO(value))
+ except:
+ pass
+ ret.append({"name": name, "value": value,
+ "blacklist": blacklist_hit(name, blacklist)})
+ return (ret, new_args + sorted(last_args))
+
def build_args(parsed):
build = []
for arg in parsed:
@@ -181,10 +267,17 @@ def handle_dir(d, subdir):
abort("'%s' does not exist" % d)
configure = d + "/configure"
- if not os.path.exists(configure):
- abort("not a autoconf package: configure script not found in '%s'" % d)
+ meson_build = d + "/meson.build"
+ if not os.path.exists(configure) and not os.path.exists(meson_build):
+ abort("not a autoconf/meson package: configure script / meson.build file not found in '%s'" % d)
exit(1)
+ if os.path.exists(configure) and tool != "meson":
+ return handle_dir_configure(d, configure)
+ if os.path.exists(meson_build):
+ return handle_dir_meson(d)
+
+def handle_dir_configure(d, configure):
configure_args = []
p = subprocess.Popen([ configure, "--help" ], stdout=subprocess.PIPE, universal_newlines=True)
lines = p.stdout.read().splitlines()
@@ -205,6 +298,36 @@ def handle_dir(d, subdir):
label = os.path.basename(d)
return (parsed, args, label)
+def handle_dir_meson(d):
+ meson_builddir = d + "-build"
+ if not os.path.exists(meson_builddir):
+ abort("package must be configured")
+ exit(1)
+ args = []
+ p = subprocess.Popen([ "meson", "introspect", meson_builddir, "--buildoptions" ], stdout=subprocess.PIPE, universal_newlines=True)
+ options = json.load(p.stdout)
+ for option in options:
+ try:
+ i = next(index for (index, d) in enumerate(parsed_pkg_conf_opt) if d["name"] == option["name"])
+ option["blacklist"] = False
+ option["value"] = parsed_pkg_conf_opt[i]["value"]
+ except:
+ pass
+ option["blacklist"] = blacklist_hit(option["name"], meson_blacklist)
+ if option["blacklist"]:
+ continue
+
+ value = option["value"]
+ if not isinstance(value, str) or value.count(" ") > 0:
+ i = io.StringIO()
+ json.dump(value, i)
+ value = i.getvalue()
+
+ args.append("\t-D%s=%s\n" % (option["name"], value))
+
+ label = os.path.basename(d)
+ return (options, args, label)
+
def show_diff(old_opt, old_label, new_opt, new_label):
if args.sort:
sys.stdout.writelines(difflib.unified_diff(
@@ -281,10 +404,14 @@ else:
ptx_pkg_conf_opt = []
pkg_subdir = ""
+tool = None
if args.pkg:
- (d, pkg_subdir, pkg_conf_opt) = ask_ptxdist(ptx_PKG)
+ (tool, d, pkg_subdir, pkg_conf_opt) = ask_ptxdist(ptx_PKG)
ptx_pkg_label = "rules/%s.make" % ptx_pkg
- parsed_pkg_conf_opt = parse_configure_args(pkg_conf_opt, [])
+ if tool == "autoconf":
+ parsed_pkg_conf_opt = parse_configure_args(pkg_conf_opt, [])
+ if tool == "meson":
+ (parsed_pkg_conf_opt, pkg_conf_opt) = parse_meson_args(pkg_conf_opt, [])
if args.only:
pass