aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-05-02 16:01:05 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-11-14 15:57:37 -0800
commit3af4407a16e188bfee0dc91b171decee1b8966eb (patch)
treef1ba24d643a01e24857a07d3a3f444c4af88f1fd
parent95403cb61520978c52b3693a9bf0119e8348c20b (diff)
downloadmeson-3af4407a16e188bfee0dc91b171decee1b8966eb.zip
meson-3af4407a16e188bfee0dc91b171decee1b8966eb.tar.gz
meson-3af4407a16e188bfee0dc91b171decee1b8966eb.tar.bz2
Get basic native config file loading working
-rw-r--r--mesonbuild/coredata.py76
-rw-r--r--mesonbuild/environment.py6
-rw-r--r--mesonbuild/msetup.py4
-rwxr-xr-xrun_tests.py1
4 files changed, 87 insertions, 0 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 245741a..ae37576 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -183,6 +183,7 @@ class UserArrayOption(UserOption):
', '.join(bad), ', '.join(self.choices)))
return newvalue
+
class UserFeatureOption(UserComboOption):
static_choices = ['enabled', 'disabled', 'auto']
@@ -198,6 +199,72 @@ class UserFeatureOption(UserComboOption):
def is_auto(self):
return self.value == 'auto'
+
+def load_configs(filenames):
+ """Load native files."""
+ def gen():
+ for f in filenames:
+ f = os.path.expanduser(os.path.expandvars(f))
+ if os.path.exists(f):
+ yield f
+ continue
+ elif sys.platform != 'win32':
+ f = os.path.basename(f)
+ paths = [
+ os.environ.get('XDG_DATA_HOME', os.path.expanduser('~/.local/share')),
+ ] + os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':')
+ for path in paths:
+ path_to_try = os.path.join(path, 'meson', 'native', f)
+ if os.path.isfile(path_to_try):
+ yield path_to_try
+ break
+ else:
+ raise MesonException('Cannot find specified native file: ' + f)
+ continue
+
+ raise MesonException('Cannot find specified native file: ' + f)
+
+ config = configparser.SafeConfigParser()
+ config.read(gen())
+ return config
+
+
+def _get_section(config, section):
+ if config.has_section(section):
+ final = {}
+ for k, v in config.items(section):
+ # Windows paths...
+ v = v.replace('\\', '\\\\')
+ try:
+ final[k] = ast.literal_eval(v)
+ except SyntaxError:
+ raise MesonException(
+ 'Malformed value in native file variable: {}'.format(v))
+ return final
+ return {}
+
+
+class ConfigData:
+
+ """Contains configuration information provided by the user for the build."""
+
+ def __init__(self, config=None):
+ if config:
+ self.binaries = _get_section(config, 'binaries')
+ # global is a keyword and globals is a builtin, rather than mangle it,
+ # use a similar word
+ self.universal = _get_section(config, 'globals')
+ self.subprojects = {s: _get_section(config, s) for s in config.sections()
+ if s not in {'binaries', 'globals'}}
+ else:
+ self.binaries = {}
+ self.universal = {}
+ self.subprojects = {}
+
+ def get_binaries(self, name):
+ return self.binaries.get(name, None)
+
+
# This class contains all data that must persist over multiple
# invocations of Meson. It is roughly the same thing as
# cmakecache.
@@ -229,6 +296,15 @@ class CoreData:
self.deps = OrderedDict()
# Only to print a warning if it changes between Meson invocations.
self.pkgconf_envvar = os.environ.get('PKG_CONFIG_PATH', '')
+ self.config_files = self.__load_config_files(options.native_file)
+
+ @staticmethod
+ def __load_config_files(filenames):
+ if not filenames:
+ return []
+ filenames = [os.path.abspath(os.path.expanduser(os.path.expanduser(f)))
+ for f in filenames]
+ return filenames
@staticmethod
def __load_cross_file(filename):
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 073825a..72ca6a2 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -352,6 +352,12 @@ class Environment:
self.cross_info = None
self.machines.default_missing()
+ if self.coredata.config_files:
+ self.config_info = coredata.ConfigData(
+ coredata.load_configs(self.coredata.config_files))
+ else:
+ self.config_info = coredata.ConfigData()
+
self.cmd_line_options = options.cmd_line_options.copy()
# List of potential compilers.
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py
index ce03f43..f9a5e1c 100644
--- a/mesonbuild/msetup.py
+++ b/mesonbuild/msetup.py
@@ -29,6 +29,10 @@ def add_arguments(parser):
coredata.register_builtin_arguments(parser)
parser.add_argument('--cross-file', default=None,
help='File describing cross compilation environment.')
+ parser.add_argument('--native-file',
+ default=[],
+ action='append',
+ help='File containing overrides for native compilation environment.')
parser.add_argument('-v', '--version', action='version',
version=coredata.version)
parser.add_argument('--profile-self', action='store_true', dest='profile',
diff --git a/run_tests.py b/run_tests.py
index 3445e30..ebee602 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -73,6 +73,7 @@ def get_fake_options(prefix):
opts.wrap_mode = None
opts.prefix = prefix
opts.cmd_line_options = {}
+ opts.native_file = []
return opts
def get_fake_env(sdir, bdir, prefix):