+# Load a section-less config file: maps parameter names to space-separated lists of strings (with shell quotation)
+# Lines starting with spaces are continuation lines
+def loadConfigFile(file):
+ # read config file
+ linenr = 0
+ with open(file) as file:
+ result = ConfigDict()
+ curKey = None
+ for line in file:
+ linenr += 1
+ isCont = len(line) and line[0].isspace() # remember if we were a continuation line
+ if isCont and curKey is None:
+ raise Exception("Invalid config, line %d: Starting with continuation line" % linenr)
+ line = line.strip()
+ if not len(line) or line.startswith("#"): continue # skip empty and comment lines
+ try:
+ if isCont:
+ # continuation line
+ result[curKey] += shlex.split(line)
+ else:
+ # option line
+ pos = line.index("=") # will raise exception when substring is not found
+ curKey = line[:pos].strip()
+ result[curKey] = shlex.split(line[pos+1:]) # shlex.split also strips
+ except Exception:
+ raise Exception("Invalid config, line %d: Error parsing line (quoting issue?)" % linenr)
+ # add some convencience get functions
+ return result
+
+# representation of a build system
+class BuildSystem:
+ def __init__(self, ruleMaker, buildDepends = [], binaryDepends = []):
+ self.ruleMaker = ruleMaker
+ self.buildDepends = buildDepends
+ self.binaryDepends = binaryDepends
+