commit
ed5992a10d
16 changed files with 207 additions and 0 deletions
@ -0,0 +1,5 @@ |
||||
## New module to parse kconfig output files |
||||
|
||||
The new module `unstable-kconfig` adds the ability to parse and use kconfig output |
||||
files from `meson.build`. |
||||
|
@ -0,0 +1,72 @@ |
||||
# Copyright 2017, 2019 The Meson development team |
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
from . import ExtensionModule |
||||
|
||||
from .. import mesonlib |
||||
from ..mesonlib import typeslistify |
||||
from ..interpreterbase import FeatureNew, noKwargs |
||||
from ..interpreter import InvalidCode |
||||
|
||||
import os |
||||
|
||||
class KconfigModule(ExtensionModule): |
||||
|
||||
@FeatureNew('Kconfig Module', '0.51.0') |
||||
def __init__(self, *args, **kwargs): |
||||
super().__init__(*args, **kwargs) |
||||
self.snippets.add('load') |
||||
|
||||
def _load_file(self, path_to_config): |
||||
result = dict() |
||||
try: |
||||
with open(path_to_config) as f: |
||||
for line in f: |
||||
if '#' in line: |
||||
comment_idx = line.index('#') |
||||
line = line[:comment_idx] |
||||
line = line.strip() |
||||
try: |
||||
name, val = line.split('=', 1) |
||||
except ValueError: |
||||
continue |
||||
result[name.strip()] = val.strip() |
||||
except IOError as e: |
||||
raise mesonlib.MesonException('Failed to load {}: {}'.format(path_to_config, e)) |
||||
|
||||
return result |
||||
|
||||
@noKwargs |
||||
def load(self, interpreter, state, args, kwargs): |
||||
sources = typeslistify(args, (str, mesonlib.File)) |
||||
if len(sources) != 1: |
||||
raise InvalidCode('load takes only one file input.') |
||||
|
||||
s = sources[0] |
||||
if isinstance(s, mesonlib.File): |
||||
# kconfig input is processed at "meson setup" time, not during |
||||
# the build, so it cannot reside in the build directory. |
||||
if s.is_built: |
||||
raise InvalidCode('kconfig input must be a source file.') |
||||
s = s.relative_name() |
||||
|
||||
s = os.path.join(interpreter.environment.source_dir, s) |
||||
if s not in interpreter.build_def_files: |
||||
interpreter.build_def_files.append(s) |
||||
|
||||
return self._load_file(s) |
||||
|
||||
|
||||
def initialize(*args, **kwargs): |
||||
return KconfigModule(*args, **kwargs) |
@ -0,0 +1,3 @@ |
||||
CONFIG_VAL1=y |
||||
# CONFIG_VAL2 is not set |
||||
CONFIG_VAL_VAL=4 |
@ -0,0 +1,16 @@ |
||||
project('kconfig basic test') |
||||
|
||||
k = import('unstable-kconfig') |
||||
conf = k.load('.config') |
||||
|
||||
if not conf.has_key('CONFIG_VAL1') |
||||
error('Expected CONFIG_VAL1 to be set, but it wasn\'t') |
||||
endif |
||||
|
||||
if conf.has_key('CONFIG_VAL2') |
||||
error('Expected CONFIG_VAL2 not be set, but it was') |
||||
endif |
||||
|
||||
if conf.get('CONFIG_VAL_VAL').to_int() != 4 |
||||
error('Expected CONFIG_VAL_VAL to be 4') |
||||
endif |
@ -0,0 +1,2 @@ |
||||
CONFIG_IS_SET=y |
||||
# CONFIG_NOT_IS_SET is not set |
@ -0,0 +1,13 @@ |
||||
|
||||
k = import('unstable-kconfig') |
||||
|
||||
conf = k.load(meson.source_root() / '.config') |
||||
|
||||
if not conf.has_key('CONFIG_IS_SET') |
||||
error('Expected CONFIG_IS_SET to be set, but it wasn\'t') |
||||
endif |
||||
|
||||
if conf.has_key('CONFIG_NOT_IS_SET') |
||||
error('Expected CONFIG_NOT_IS_SET not be set, but it was') |
||||
endif |
||||
|
@ -0,0 +1,4 @@ |
||||
project('kconfig subdir test') |
||||
|
||||
# Test into sub directory |
||||
subdir('dir') |
@ -0,0 +1,2 @@ |
||||
CONFIG_IS_SET=y |
||||
# CONFIG_NOT_IS_SET is not set |
@ -0,0 +1,13 @@ |
||||
|
||||
k = import('unstable-kconfig') |
||||
|
||||
conf = k.load(files('config')) |
||||
|
||||
if not conf.has_key('CONFIG_IS_SET') |
||||
error('Expected CONFIG_IS_SET to be set, but it wasn\'t') |
||||
endif |
||||
|
||||
if conf.has_key('CONFIG_NOT_IS_SET') |
||||
error('Expected CONFIG_NOT_IS_SET not be set, but it was') |
||||
endif |
||||
|
@ -0,0 +1,4 @@ |
||||
project('kconfig subdir test') |
||||
|
||||
# Test into sub directory |
||||
subdir('dir') |
@ -0,0 +1,2 @@ |
||||
CONFIG_IS_SET=y |
||||
# CONFIG_NOT_IS_SET is not set |
@ -0,0 +1,14 @@ |
||||
project('kconfig builddir test') |
||||
|
||||
k = import('unstable-kconfig') |
||||
|
||||
configure_file(input: 'config', output: 'out-config', copy: true) |
||||
conf = k.load(meson.build_root() / 'out-config') |
||||
|
||||
if not conf.has_key('CONFIG_IS_SET') |
||||
error('Expected CONFIG_IS_SET to be set, but it wasn\'t') |
||||
endif |
||||
|
||||
if conf.has_key('CONFIG_NOT_IS_SET') |
||||
error('Expected CONFIG_NOT_IS_SET not be set, but it was') |
||||
endif |
Loading…
Reference in new issue