summaryrefslogtreecommitdiff
path: root/python/build/cmdline.py
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-07-19 20:47:17 +0200
committerMax Kellermann <max@musicpd.org>2017-07-19 20:53:52 +0200
commit07b06d76be716fa82f18c7949c00f92208962d6a (patch)
tree128ed7f50168abb20c22bf99a2022dd99e340db1 /python/build/cmdline.py
parent856fe2da1571c7286b36065d4b846a90232f31cb (diff)
{android,win32}/build.py: concatenate variables from the command line
Diffstat (limited to 'python/build/cmdline.py')
-rw-r--r--python/build/cmdline.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/python/build/cmdline.py b/python/build/cmdline.py
new file mode 100644
index 000000000..50245f597
--- /dev/null
+++ b/python/build/cmdline.py
@@ -0,0 +1,29 @@
+def concatenate_cmdline_variables(src, names):
+ """Find duplicate variable declarations on the given source list, and
+ concatenate the values of those in the 'names' list."""
+
+ # the result list being constructed
+ dest = []
+
+ # a map of variable name to destination list index
+ positions = {}
+
+ for item in src:
+ i = item.find('=')
+ if i > 0:
+ # it's a variable
+ name = item[:i]
+ if name in names:
+ # it's a known variable
+ if name in positions:
+ # already specified: concatenate instead of
+ # appending it
+ dest[positions[name]] += ' ' + item[i + 1:]
+ continue
+ else:
+ # not yet seen: append it and remember the list
+ # index
+ positions[name] = len(dest)
+ dest.append(item)
+
+ return dest