From 4d986563dc3e9f850015619297dec92a102b6bbc Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Thu, 4 Oct 2018 21:57:27 +0300 Subject: [PATCH] Expose wrap_mode as an option. Closes #4266. --- mesonbuild/coredata.py | 12 +++++++++--- mesonbuild/interpreter.py | 8 ++++---- mesonbuild/msetup.py | 4 ---- mesonbuild/wrap/__init__.py | 14 ++++++++++++++ test cases/common/44 options/meson.build | 2 ++ 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 1ab7d72ea..819481b32 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -223,7 +223,6 @@ class CoreData: self.base_options = {} self.external_preprocess_args = {} # CPPFLAGS only self.cross_file = self.__load_cross_file(options.cross_file) - self.wrap_mode = options.wrap_mode if options.wrap_mode is not None else WrapMode.default self.compilers = OrderedDict() self.cross_compilers = OrderedDict() self.deps = OrderedDict() @@ -338,7 +337,10 @@ class CoreData: def get_builtin_option(self, optname): if optname in self.builtins: - return self.builtins[optname].value + v = self.builtins[optname] + if optname == 'wrap_mode': + return WrapMode.from_string(v.value) + return v.value raise RuntimeError('Tried to get unknown builtin option %s.' % optname) def set_builtin_option(self, optname, value): @@ -616,7 +618,11 @@ builtin_options = { 'install_umask': [UserUmaskOption, 'Default umask to apply on permissions of installed files', '022'], 'auto_features': [UserFeatureOption, "Override value of all 'auto' features", 'auto'], 'optimization': [UserComboOption, 'Optimization level', ['0', 'g', '1', '2', '3', 's'], '0'], - 'debug': [UserBooleanOption, 'Debug', True] + 'debug': [UserBooleanOption, 'Debug', True], + 'wrap_mode': [UserComboOption, 'Wrap mode', ['default', + 'nofallback', + 'nodownload', + 'forcefallback'], 'default'], } # Special prefix-dependent defaults for installation directories that reside in diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index f2b8f3407..2d5dd9245 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2265,7 +2265,7 @@ external dependencies (including libraries) must go to "dependencies".''') return subproject subproject_dir_abs = os.path.join(self.environment.get_source_dir(), self.subproject_dir) - r = wrap.Resolver(subproject_dir_abs, self.coredata.wrap_mode) + r = wrap.Resolver(subproject_dir_abs, self.coredata.get_builtin_option('wrap_mode')) try: resolved = r.resolve(dirname) except RuntimeError as e: @@ -2940,7 +2940,7 @@ external dependencies (including libraries) must go to "dependencies".''') dep = NotFoundDependency(self.environment) # Unless a fallback exists and is forced ... - if self.coredata.wrap_mode == WrapMode.forcefallback and 'fallback' in kwargs: + if self.coredata.get_builtin_option('wrap_mode') == WrapMode.forcefallback and 'fallback' in kwargs: pass # ... search for it outside the project elif name != '': @@ -3007,12 +3007,12 @@ root and issuing %s. def dependency_fallback(self, name, kwargs): display_name = name if name else '(anonymous)' - if self.coredata.wrap_mode in (WrapMode.nofallback, WrapMode.nodownload): + if self.coredata.get_builtin_option('wrap_mode') in (WrapMode.nofallback, WrapMode.nodownload): mlog.log('Not looking for a fallback subproject for the dependency', mlog.bold(display_name), 'because:\nUse of fallback' 'dependencies is disabled.') return None - elif self.coredata.wrap_mode == WrapMode.forcefallback: + elif self.coredata.get_builtin_option('wrap_mode') == WrapMode.forcefallback: mlog.log('Looking for a fallback subproject for the dependency', mlog.bold(display_name), 'because:\nUse of fallback dependencies is forced.') else: diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py index 157655657..95885554d 100644 --- a/mesonbuild/msetup.py +++ b/mesonbuild/msetup.py @@ -32,10 +32,6 @@ def add_arguments(parser): help='File describing cross compilation environment.') parser.add_argument('-v', '--version', action='version', version=coredata.version) - # See the mesonlib.WrapMode enum for documentation - parser.add_argument('--wrap-mode', default=None, - type=wrapmodetype, choices=WrapMode, - help='Special wrap mode to use') parser.add_argument('--profile-self', action='store_true', dest='profile', help=argparse.SUPPRESS) parser.add_argument('--fatal-meson-warnings', action='store_true', dest='fatal_warnings', diff --git a/mesonbuild/wrap/__init__.py b/mesonbuild/wrap/__init__.py index b792dfa74..6be2c4492 100644 --- a/mesonbuild/wrap/__init__.py +++ b/mesonbuild/wrap/__init__.py @@ -33,6 +33,15 @@ from enum import Enum # Note that these options do not affect subprojects that # are git submodules since those are only usable in git # repositories, and you almost always want to download them. + +# This did _not_ work when inside the WrapMode class. +# I don't know why. If you can fix this, patches welcome. +string_to_value = {'default': 1, + 'nofallback': 2, + 'nodownload': 3, + 'forcefallback': 4, + } + class WrapMode(Enum): default = 1 nofallback = 2 @@ -41,3 +50,8 @@ class WrapMode(Enum): def __str__(self): return self.name + + @staticmethod + def from_string(mode_name): + g = string_to_value[mode_name] + return WrapMode(g) diff --git a/test cases/common/44 options/meson.build b/test cases/common/44 options/meson.build index f177aa408..c6cf9c8cf 100644 --- a/test cases/common/44 options/meson.build +++ b/test cases/common/44 options/meson.build @@ -29,3 +29,5 @@ endif if get_option('integer_opt') != 3 error('Incorrect value in integer option.') endif + +assert(get_option('wrap_mode') == 'default', 'Wrap mode option is broken.')