diff options
Diffstat (limited to 'bitbake/lib/bb/parse/parse_py/ConfHandler.py')
| -rw-r--r-- | bitbake/lib/bb/parse/parse_py/ConfHandler.py | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py deleted file mode 100644 index 9ddbae123d..0000000000 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ /dev/null | |||
| @@ -1,221 +0,0 @@ | |||
| 1 | """ | ||
| 2 | class for handling configuration data files | ||
| 3 | |||
| 4 | Reads a .conf file and obtains its metadata | ||
| 5 | |||
| 6 | """ | ||
| 7 | |||
| 8 | # Copyright (C) 2003, 2004 Chris Larson | ||
| 9 | # Copyright (C) 2003, 2004 Phil Blundell | ||
| 10 | # | ||
| 11 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 12 | # | ||
| 13 | |||
| 14 | import errno | ||
| 15 | import re | ||
| 16 | import os | ||
| 17 | import bb.utils | ||
| 18 | from bb.parse import ParseError, resolve_file, ast, logger, handle | ||
| 19 | |||
| 20 | __config_regexp__ = re.compile( r""" | ||
| 21 | ^ | ||
| 22 | (?P<exp>export\s+)? | ||
| 23 | (?P<var>[a-zA-Z0-9\-_+.${}/~:]*?) | ||
| 24 | (\[(?P<flag>[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@/]*)\])? | ||
| 25 | |||
| 26 | (?P<whitespace>\s*) ( | ||
| 27 | (?P<colon>:=) | | ||
| 28 | (?P<lazyques>\?\?=) | | ||
| 29 | (?P<ques>\?=) | | ||
| 30 | (?P<append>\+=) | | ||
| 31 | (?P<prepend>=\+) | | ||
| 32 | (?P<predot>=\.) | | ||
| 33 | (?P<postdot>\.=) | | ||
| 34 | = | ||
| 35 | ) (?P<whitespace2>\s*) | ||
| 36 | |||
| 37 | (?!'[^']*'[^']*'$) | ||
| 38 | (?!\"[^\"]*\"[^\"]*\"$) | ||
| 39 | (?P<apo>['\"]) | ||
| 40 | (?P<value>.*) | ||
| 41 | (?P=apo) | ||
| 42 | $ | ||
| 43 | """, re.X) | ||
| 44 | __include_regexp__ = re.compile( r"include\s+(.+)" ) | ||
| 45 | __require_regexp__ = re.compile( r"require\s+(.+)" ) | ||
| 46 | __includeall_regexp__ = re.compile( r"include_all\s+(.+)" ) | ||
| 47 | __export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) | ||
| 48 | __unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) | ||
| 49 | __unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\]$" ) | ||
| 50 | __addpylib_regexp__ = re.compile(r"addpylib\s+(.+)\s+(.+)" ) | ||
| 51 | __addfragments_regexp__ = re.compile(r"addfragments\s+(.+)\s+(.+)\s+(.+)\s+(.+)" ) | ||
| 52 | |||
| 53 | def init(data): | ||
| 54 | return | ||
| 55 | |||
| 56 | def supports(fn, d): | ||
| 57 | return fn[-5:] == ".conf" | ||
| 58 | |||
| 59 | def include(parentfn, fns, lineno, data, error_out): | ||
| 60 | """ | ||
| 61 | error_out: A string indicating the verb (e.g. "include", "inherit") to be | ||
| 62 | used in a ParseError that will be raised if the file to be included could | ||
| 63 | not be included. Specify False to avoid raising an error in this case. | ||
| 64 | """ | ||
| 65 | fns = data.expand(fns) | ||
| 66 | parentfn = data.expand(parentfn) | ||
| 67 | |||
| 68 | # "include" or "require" accept zero to n space-separated file names to include. | ||
| 69 | for fn in fns.split(): | ||
| 70 | include_single_file(parentfn, fn, lineno, data, error_out) | ||
| 71 | |||
| 72 | def include_single_file(parentfn, fn, lineno, data, error_out): | ||
| 73 | """ | ||
| 74 | Helper function for include() which does not expand or split its parameters. | ||
| 75 | """ | ||
| 76 | if parentfn == fn: # prevent infinite recursion | ||
| 77 | return None | ||
| 78 | |||
| 79 | if not os.path.isabs(fn): | ||
| 80 | dname = os.path.dirname(parentfn) | ||
| 81 | bbpath = "%s:%s" % (dname, data.getVar("BBPATH")) | ||
| 82 | abs_fn, attempts = bb.utils.which(bbpath, fn, history=True) | ||
| 83 | if abs_fn and bb.parse.check_dependency(data, abs_fn): | ||
| 84 | logger.warning("Duplicate inclusion for %s in %s" % (abs_fn, data.getVar('FILE'))) | ||
| 85 | for af in attempts: | ||
| 86 | bb.parse.mark_dependency(data, af) | ||
| 87 | if abs_fn: | ||
| 88 | fn = abs_fn | ||
| 89 | elif bb.parse.check_dependency(data, fn): | ||
| 90 | logger.warning("Duplicate inclusion for %s in %s" % (fn, data.getVar('FILE'))) | ||
| 91 | |||
| 92 | try: | ||
| 93 | bb.parse.handle(fn, data, True) | ||
| 94 | except (IOError, OSError) as exc: | ||
| 95 | if exc.errno == errno.ENOENT: | ||
| 96 | if error_out: | ||
| 97 | raise ParseError("Could not %s file %s" % (error_out, fn), parentfn, lineno) | ||
| 98 | logger.debug2("CONF file '%s' not found", fn) | ||
| 99 | else: | ||
| 100 | if error_out: | ||
| 101 | raise ParseError("Could not %s file %s: %s" % (error_out, fn, exc.strerror), parentfn, lineno) | ||
| 102 | else: | ||
| 103 | raise ParseError("Error parsing %s: %s" % (fn, exc.strerror), parentfn, lineno) | ||
| 104 | |||
| 105 | # We have an issue where a UI might want to enforce particular settings such as | ||
| 106 | # an empty DISTRO variable. If configuration files do something like assigning | ||
| 107 | # a weak default, it turns out to be very difficult to filter out these changes, | ||
| 108 | # particularly when the weak default might appear half way though parsing a chain | ||
| 109 | # of configuration files. We therefore let the UIs hook into configuration file | ||
| 110 | # parsing. This turns out to be a hard problem to solve any other way. | ||
| 111 | confFilters = [] | ||
| 112 | |||
| 113 | def handle(fn, data, include, baseconfig=False): | ||
| 114 | init(data) | ||
| 115 | |||
| 116 | if include == 0: | ||
| 117 | oldfile = None | ||
| 118 | else: | ||
| 119 | oldfile = data.getVar('FILE', False) | ||
| 120 | |||
| 121 | abs_fn = resolve_file(fn, data) | ||
| 122 | with open(abs_fn, 'r') as f: | ||
| 123 | |||
| 124 | statements = ast.StatementGroup() | ||
| 125 | lineno = 0 | ||
| 126 | while True: | ||
| 127 | lineno = lineno + 1 | ||
| 128 | s = f.readline() | ||
| 129 | if not s: | ||
| 130 | break | ||
| 131 | origlineno = lineno | ||
| 132 | origline = s | ||
| 133 | w = s.strip() | ||
| 134 | # skip empty lines | ||
| 135 | if not w: | ||
| 136 | continue | ||
| 137 | s = s.rstrip() | ||
| 138 | while s[-1] == '\\': | ||
| 139 | line = f.readline() | ||
| 140 | origline += line | ||
| 141 | s2 = line.rstrip() | ||
| 142 | lineno = lineno + 1 | ||
| 143 | if (not s2 or s2 and s2[0] != "#") and s[0] == "#" : | ||
| 144 | bb.fatal("There is a confusing multiline, partially commented expression starting on line %s of file %s:\n%s\nPlease clarify whether this is all a comment or should be parsed." % (origlineno, fn, origline)) | ||
| 145 | |||
| 146 | s = s[:-1] + s2 | ||
| 147 | # skip comments | ||
| 148 | if s[0] == '#': | ||
| 149 | continue | ||
| 150 | feeder(lineno, s, abs_fn, statements, baseconfig=baseconfig) | ||
| 151 | |||
| 152 | # DONE WITH PARSING... time to evaluate | ||
| 153 | data.setVar('FILE', abs_fn) | ||
| 154 | statements.eval(data) | ||
| 155 | if oldfile: | ||
| 156 | data.setVar('FILE', oldfile) | ||
| 157 | |||
| 158 | for f in confFilters: | ||
| 159 | f(fn, data) | ||
| 160 | |||
| 161 | return data | ||
| 162 | |||
| 163 | # baseconfig is set for the bblayers/layer.conf cookerdata config parsing | ||
| 164 | # The function is also used by BBHandler, conffile would be False | ||
| 165 | def feeder(lineno, s, fn, statements, baseconfig=False, conffile=True): | ||
| 166 | m = __config_regexp__.match(s) | ||
| 167 | if m: | ||
| 168 | groupd = m.groupdict() | ||
| 169 | if groupd['var'] == "": | ||
| 170 | raise ParseError("Empty variable name in assignment: '%s'" % s, fn, lineno); | ||
| 171 | if not groupd['whitespace'] or not groupd['whitespace2']: | ||
| 172 | logger.warning("%s:%s has a lack of whitespace around the assignment: '%s'" % (fn, lineno, s)) | ||
| 173 | ast.handleData(statements, fn, lineno, groupd) | ||
| 174 | return | ||
| 175 | |||
| 176 | m = __include_regexp__.match(s) | ||
| 177 | if m: | ||
| 178 | ast.handleInclude(statements, fn, lineno, m, False) | ||
| 179 | return | ||
| 180 | |||
| 181 | m = __require_regexp__.match(s) | ||
| 182 | if m: | ||
| 183 | ast.handleInclude(statements, fn, lineno, m, True) | ||
| 184 | return | ||
| 185 | |||
| 186 | m = __includeall_regexp__.match(s) | ||
| 187 | if m: | ||
| 188 | ast.handleIncludeAll(statements, fn, lineno, m) | ||
| 189 | return | ||
| 190 | |||
| 191 | m = __export_regexp__.match(s) | ||
| 192 | if m: | ||
| 193 | ast.handleExport(statements, fn, lineno, m) | ||
| 194 | return | ||
| 195 | |||
| 196 | m = __unset_regexp__.match(s) | ||
| 197 | if m: | ||
| 198 | ast.handleUnset(statements, fn, lineno, m) | ||
| 199 | return | ||
| 200 | |||
| 201 | m = __unset_flag_regexp__.match(s) | ||
| 202 | if m: | ||
| 203 | ast.handleUnsetFlag(statements, fn, lineno, m) | ||
| 204 | return | ||
| 205 | |||
| 206 | m = __addpylib_regexp__.match(s) | ||
| 207 | if baseconfig and conffile and m: | ||
| 208 | ast.handlePyLib(statements, fn, lineno, m) | ||
| 209 | return | ||
| 210 | |||
| 211 | m = __addfragments_regexp__.match(s) | ||
| 212 | if m: | ||
| 213 | ast.handleAddFragments(statements, fn, lineno, m) | ||
| 214 | return | ||
| 215 | |||
| 216 | raise ParseError("unparsed line: '%s'" % s, fn, lineno); | ||
| 217 | |||
| 218 | # Add us to the handlers list | ||
| 219 | from bb.parse import handlers | ||
| 220 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
| 221 | del handlers | ||
