aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-01-07 13:47:27 -0800
committerDylan Baker <dylan@pnwbakers.com>2019-02-11 12:50:32 -0800
commit5b896ed70bbf18e633bbeca442c90610e3d66a22 (patch)
tree1205d983b474f4e97eb596769f410cc6ffc399d6
parentb50899419cb2de27af34e5a955695a61c2863c51 (diff)
downloadmeson-5b896ed70bbf18e633bbeca442c90610e3d66a22.zip
meson-5b896ed70bbf18e633bbeca442c90610e3d66a22.tar.gz
meson-5b896ed70bbf18e633bbeca442c90610e3d66a22.tar.bz2
allow setting directory locations in a native file
This allows the person running configure (either a developer, user, or distro maintainer) to keep a configuration of where various kinds of files should end up.
-rw-r--r--docs/markdown/Native-environments.md17
-rw-r--r--docs/markdown/snippets/native-file-paths.md4
-rw-r--r--mesonbuild/ast/introspection.py2
-rw-r--r--mesonbuild/coredata.py12
-rw-r--r--mesonbuild/environment.py30
-rw-r--r--mesonbuild/interpreter.py4
-rw-r--r--mesonbuild/mconf.py3
-rwxr-xr-xrun_unittests.py11
-rw-r--r--test cases/common/212 native file path override/installed_files.txt2
-rw-r--r--test cases/common/212 native file path override/main.cpp5
-rw-r--r--test cases/common/212 native file path override/meson.build7
-rw-r--r--test cases/common/212 native file path override/nativefile.ini2
-rw-r--r--test cases/unit/54 native file override/meson.build10
-rw-r--r--test cases/unit/54 native file override/meson_options.txt13
-rw-r--r--test cases/unit/54 native file override/nativefile16
15 files changed, 118 insertions, 20 deletions
diff --git a/docs/markdown/Native-environments.md b/docs/markdown/Native-environments.md
index a9719a7..f0d41eb 100644
--- a/docs/markdown/Native-environments.md
+++ b/docs/markdown/Native-environments.md
@@ -43,6 +43,23 @@ rust = '/usr/local/bin/rust'
llvm-config = '/usr/local/llvm-svn/bin/llvm-config'
```
+### Paths and Directories
+
+As of 0.50.0 paths and directories such as libdir can be defined in the native
+file in a paths section
+
+```ini
+[paths]
+libdir = 'mylibdir'
+prefix = '/my prefix'
+```
+
+These values will only be loaded when not cross compiling. Any arguments on the
+command line will override any options in the native file. For example, passing
+`--libdir=otherlibdir` would result in a prefix of `/my prefix` and a libdir of
+`otherlibdir`.
+
+
## Loading multiple native files
Unlike cross file, native files allow layering. More than one native file can be
diff --git a/docs/markdown/snippets/native-file-paths.md b/docs/markdown/snippets/native-file-paths.md
new file mode 100644
index 0000000..6979241
--- /dev/null
+++ b/docs/markdown/snippets/native-file-paths.md
@@ -0,0 +1,4 @@
+## Native File Paths and Directories
+
+A new `[paths]` section has been added to the native file. This can be used to
+set paths such a prefix and libdir in a persistent way.
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index 5d0ec5a..4a03e98 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -86,7 +86,7 @@ class IntrospectionInterpreter(AstInterpreter):
self.project_default_options = mesonlib.stringlistify(def_opts)
self.project_default_options = cdata.create_options_dict(self.project_default_options)
self.default_options.update(self.project_default_options)
- self.coredata.set_default_options(self.default_options, self.subproject, self.environment.cmd_line_options)
+ self.coredata.set_default_options(self.default_options, self.subproject, self.environment)
if not self.is_subproject() and 'subproject_dir' in kwargs:
spdirname = kwargs['subproject_dir']
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 3ce272e..139dd6e 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -525,7 +525,13 @@ class CoreData:
sub = 'In subproject {}: '.format(subproject) if subproject else ''
mlog.warning('{}Unknown options: "{}"'.format(sub, unknown_options))
- def set_default_options(self, default_options, subproject, cmd_line_options):
+ def set_default_options(self, default_options, subproject, env):
+ # Set defaults first from conf files (cross or native), then
+ # override them as nec as necessary.
+ for k, v in env.paths.host:
+ if v is not None:
+ env.cmd_line_options.setdefault(k, v)
+
# Set default options as if they were passed to the command line.
# Subprojects can only define default for user options.
from . import optinterpreter
@@ -534,7 +540,7 @@ class CoreData:
if optinterpreter.is_invalid_name(k):
continue
k = subproject + ':' + k
- cmd_line_options.setdefault(k, v)
+ env.cmd_line_options.setdefault(k, v)
# Create a subset of cmd_line_options, keeping only options for this
# subproject. Also take builtin options if it's the main project.
@@ -542,7 +548,7 @@ class CoreData:
# languages and setting the backend (builtin options must be set first
# to know which backend we'll use).
options = {}
- for k, v in cmd_line_options.items():
+ for k, v in env.cmd_line_options.items():
if subproject:
if not k.startswith(subproject + ':'):
continue
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 8ad65d7..afa6cd8 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -372,6 +372,7 @@ class Environment:
# Similar to coredata.compilers and build.compilers, but lower level in
# that there is no meta data, only names/paths.
self.binaries = PerMachineDefaultable()
+
# Just uses hard-coded defaults and environment variables. Might be
# overwritten by a native file.
self.binaries.build = BinaryTable({})
@@ -379,10 +380,16 @@ class Environment:
# Misc other properties about each machine.
self.properties = PerMachine(Properties(), Properties(), Properties())
+ # Store paths for native and cross build files. There is no target
+ # machine information here because nothing is installed for the target
+ # architecture, just the build and host architectures
+ self.paths = PerMachineDefaultable()
+
if self.coredata.config_files is not None:
config = MesonConfigFile.from_config_parser(
coredata.load_configs(self.coredata.config_files))
self.binaries.build = BinaryTable(config.get('binaries', {}))
+ self.paths.build = Directories(**config.get('paths', {}))
if self.coredata.cross_file is not None:
config = MesonConfigFile.parse_datafile(self.coredata.cross_file)
@@ -395,6 +402,7 @@ class Environment:
self.machines.default_missing()
self.binaries.default_missing()
+ self.paths.default_missing()
exe_wrapper = self.binaries.host.lookup_entry('exe_wrapper')
if exe_wrapper is not None:
@@ -1173,46 +1181,46 @@ class Environment:
def get_exe_suffix(self):
return self.exe_suffix
- def get_import_lib_dir(self):
+ def get_import_lib_dir(self) -> str:
"Install dir for the import library (library used for linking)"
return self.get_libdir()
- def get_shared_module_dir(self):
+ def get_shared_module_dir(self) -> str:
"Install dir for shared modules that are loaded at runtime"
return self.get_libdir()
- def get_shared_lib_dir(self):
+ def get_shared_lib_dir(self) -> str:
"Install dir for the shared library"
if self.win_libdir_layout:
return self.get_bindir()
return self.get_libdir()
- def get_static_lib_dir(self):
+ def get_static_lib_dir(self) -> str:
"Install dir for the static library"
return self.get_libdir()
def get_object_suffix(self):
return self.object_suffix
- def get_prefix(self):
+ def get_prefix(self) -> str:
return self.coredata.get_builtin_option('prefix')
- def get_libdir(self):
+ def get_libdir(self) -> str:
return self.coredata.get_builtin_option('libdir')
- def get_libexecdir(self):
+ def get_libexecdir(self) -> str:
return self.coredata.get_builtin_option('libexecdir')
- def get_bindir(self):
+ def get_bindir(self) -> str:
return self.coredata.get_builtin_option('bindir')
- def get_includedir(self):
+ def get_includedir(self) -> str:
return self.coredata.get_builtin_option('includedir')
- def get_mandir(self):
+ def get_mandir(self) -> str:
return self.coredata.get_builtin_option('mandir')
- def get_datadir(self):
+ def get_datadir(self) -> str:
return self.coredata.get_builtin_option('datadir')
def get_compiler_system_dirs(self):
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 2eb0720..c03bae1 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2458,8 +2458,6 @@ external dependencies (including libraries) must go to "dependencies".''')
return self.subprojects[dirname]
def get_option_internal(self, optname):
- # Some base options are not defined in some environments, return the
- # default value from compilers.base_options in that case.
for d in chain(
[self.coredata.base_options, compilers.base_options, self.coredata.builtins],
self.coredata.get_all_compiler_options()):
@@ -2576,7 +2574,7 @@ external dependencies (including libraries) must go to "dependencies".''')
default_options.update(self.default_project_options)
else:
default_options = {}
- self.coredata.set_default_options(default_options, self.subproject, self.environment.cmd_line_options)
+ self.coredata.set_default_options(default_options, self.subproject, self.environment)
self.set_backend()
if not self.is_subproject():
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index 48f88e8..a3feebe 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -102,8 +102,7 @@ class Conf:
if not options:
print(' No {}\n'.format(title.lower()))
arr = []
- for k in sorted(options):
- o = options[k]
+ for k, o in sorted(options.items()):
d = o.description
v = o.printable_value()
c = o.choices
diff --git a/run_unittests.py b/run_unittests.py
index a244bbd..2e2741f 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -5438,6 +5438,17 @@ class NativeFileTests(BasePlatformTests):
compiler = env.detect_swift_compiler()
self.assertEqual(compiler.version, '1.2345')
+ def test_native_file_dirs(self):
+ testcase = os.path.join(self.unit_test_dir, '54 native file override')
+ self.init(testcase, default_args=False,
+ extra_args=['--native-file', os.path.join(testcase, 'nativefile')])
+
+ def test_native_file_dirs_overriden(self):
+ testcase = os.path.join(self.unit_test_dir, '54 native file override')
+ self.init(testcase, default_args=False,
+ extra_args=['--native-file', os.path.join(testcase, 'nativefile'),
+ '-Ddef_libdir=liblib', '-Dlibdir=liblib'])
+
def unset_envs():
# For unit tests we must fully control all command lines
diff --git a/test cases/common/212 native file path override/installed_files.txt b/test cases/common/212 native file path override/installed_files.txt
new file mode 100644
index 0000000..0044d40
--- /dev/null
+++ b/test cases/common/212 native file path override/installed_files.txt
@@ -0,0 +1,2 @@
+usr/custom_bindir/main?exe
+?msvc:usr/custom_bindir/main.pdb
diff --git a/test cases/common/212 native file path override/main.cpp b/test cases/common/212 native file path override/main.cpp
new file mode 100644
index 0000000..d65cab2
--- /dev/null
+++ b/test cases/common/212 native file path override/main.cpp
@@ -0,0 +1,5 @@
+#include <iostream>
+
+int main() {
+ std::cout << "Hello world!" << std::endl;
+}
diff --git a/test cases/common/212 native file path override/meson.build b/test cases/common/212 native file path override/meson.build
new file mode 100644
index 0000000..142ca1c
--- /dev/null
+++ b/test cases/common/212 native file path override/meson.build
@@ -0,0 +1,7 @@
+project('native file install dir override', 'cpp')
+
+if meson.is_cross_build()
+ error('MESON_SKIP_TEST cannot test native build rules in cross build')
+endif
+
+executable('main', 'main.cpp', install : true)
diff --git a/test cases/common/212 native file path override/nativefile.ini b/test cases/common/212 native file path override/nativefile.ini
new file mode 100644
index 0000000..1c295c7
--- /dev/null
+++ b/test cases/common/212 native file path override/nativefile.ini
@@ -0,0 +1,2 @@
+[paths]
+bindir = 'custom_bindir'
diff --git a/test cases/unit/54 native file override/meson.build b/test cases/unit/54 native file override/meson.build
new file mode 100644
index 0000000..8318aba
--- /dev/null
+++ b/test cases/unit/54 native file override/meson.build
@@ -0,0 +1,10 @@
+project('native file overrides')
+
+foreach o : ['bindir', 'datadir', 'includedir', 'infodir', 'libdir',
+ 'libexecdir', 'localedir', 'localstatedir', 'mandir', 'prefix',
+ 'sbindir', 'sharedstatedir', 'sysconfdir']
+ expected = get_option('def_' + o)
+ actual = get_option(o)
+ assert(expected == actual,
+ '@0@ should have been @1@, but was @2@!'.format(o, expected, actual))
+endforeach
diff --git a/test cases/unit/54 native file override/meson_options.txt b/test cases/unit/54 native file override/meson_options.txt
new file mode 100644
index 0000000..4d2abf9
--- /dev/null
+++ b/test cases/unit/54 native file override/meson_options.txt
@@ -0,0 +1,13 @@
+option('def_bindir', type: 'string', value : 'binfoo',)
+option('def_datadir', type: 'string', value : 'datafoo',)
+option('def_includedir', type: 'string', value : 'includefoo',)
+option('def_infodir', type: 'string', value : 'infofoo',)
+option('def_libdir', type: 'string', value : 'libfoo',)
+option('def_libexecdir', type: 'string', value : 'libexecfoo',)
+option('def_localedir', type: 'string', value : 'localefoo',)
+option('def_localstatedir', type: 'string', value : 'localstatefoo',)
+option('def_mandir', type: 'string', value : 'manfoo',)
+option('def_prefix', type: 'string', value : '/prefix',)
+option('def_sbindir', type: 'string', value : 'sbinfoo',)
+option('def_sharedstatedir', type: 'string', value : 'sharedstatefoo',)
+option('def_sysconfdir', type: 'string', value : 'sysconffoo',)
diff --git a/test cases/unit/54 native file override/nativefile b/test cases/unit/54 native file override/nativefile
new file mode 100644
index 0000000..a390725
--- /dev/null
+++ b/test cases/unit/54 native file override/nativefile
@@ -0,0 +1,16 @@
+[paths]
+bindir = 'binfoo'
+datadir = 'datafoo'
+includedir = 'includefoo'
+infodir = 'infofoo'
+libdir = 'libfoo'
+libexecdir = 'libexecfoo'
+localedir = 'localefoo'
+localstatedir = 'localstatefoo'
+mandir = 'manfoo'
+prefix = '/prefix'
+sbindir = 'sbinfoo'
+sharedstatedir = 'sharedstatefoo'
+sysconfdir = 'sysconffoo'
+
+; vim: ft=dosini