diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2020-03-05 09:50:30 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-03-05 09:58:52 -0800 |
commit | 06b1a317d26cbe2a1bd7a232dd9726590d0c0a48 (patch) | |
tree | a2adf1f707779f18e226bf39c34447d229e71758 /mesonbuild/build.py | |
parent | 4d6ac91f950380d8262c13ce529ac0d6d8f6f4ba (diff) | |
download | meson-06b1a317d26cbe2a1bd7a232dd9726590d0c0a48.zip meson-06b1a317d26cbe2a1bd7a232dd9726590d0c0a48.tar.gz meson-06b1a317d26cbe2a1bd7a232dd9726590d0c0a48.tar.bz2 |
Make use of unholder
We have a lot of cases of code like:
```python
if hasattr(var, 'held_object'):
var = var.held_object`
```
replace that with the unholder function.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r-- | mesonbuild/build.py | 67 |
1 files changed, 17 insertions, 50 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index fcd1622..12fa6bd 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -534,9 +534,7 @@ class BuildTarget(Target): def process_objectlist(self, objects): assert(isinstance(objects, list)) - for s in objects: - if hasattr(s, 'held_object'): - s = s.held_object + for s in unholder(objects): if isinstance(s, (str, File, ExtractedObjects)): self.objects.append(s) elif isinstance(s, (GeneratedList, CustomTarget)): @@ -552,10 +550,7 @@ class BuildTarget(Target): def process_sourcelist(self, sources): sources = listify(sources) added_sources = {} # If the same source is defined multiple times, use it only once. - for s in sources: - # Holder unpacking. Ugly. - if hasattr(s, 'held_object'): - s = s.held_object + for s in unholder(sources): if isinstance(s, File): if s not in added_sources: self.sources.append(s) @@ -632,9 +627,7 @@ class BuildTarget(Target): # which is what we need. if not is_object(s): sources.append(s) - for d in self.external_deps: - if hasattr(d, 'held_object'): - d = d.held_object + for d in unholder(self.external_deps): for s in d.sources: if isinstance(s, (str, File)): sources.append(s) @@ -696,10 +689,7 @@ class BuildTarget(Target): link_depends. """ sources = listify(sources) - for s in sources: - if hasattr(s, 'held_object'): - s = s.held_object - + for s in unholder(sources): if isinstance(s, File): self.link_depends.append(s) elif isinstance(s, str): @@ -810,11 +800,7 @@ class BuildTarget(Target): kwargs.get('modules', []) self.need_install = kwargs.get('install', self.need_install) llist = extract_as_list(kwargs, 'link_with') - for linktarget in llist: - # Sorry for this hack. Keyword targets are kept in holders - # in kwargs. Unpack here without looking at the exact type. - if hasattr(linktarget, "held_object"): - linktarget = linktarget.held_object + for linktarget in unholder(llist): if isinstance(linktarget, dependencies.ExternalLibrary): raise MesonException('''An external library was used in link_with keyword argument, which is reserved for libraries built as part of this project. External @@ -1033,9 +1019,7 @@ This will become a hard error in a future Meson release.''') def add_deps(self, deps): deps = listify(deps) - for dep in deps: - if hasattr(dep, 'held_object'): - dep = dep.held_object + for dep in unholder(deps): if isinstance(dep, dependencies.InternalDependency): # Those parts that are internal. self.process_sourcelist(dep.sources) @@ -1170,10 +1154,7 @@ You probably should put it in link_with instead.''') def add_include_dirs(self, args, set_is_system: T.Optional[str] = None): ids = [] - for a in args: - # FIXME same hack, forcibly unpack from holder. - if hasattr(a, 'held_object'): - a = a.held_object + for a in unholder(args): if not isinstance(a, IncludeDirs): raise InvalidArguments('Include directory to be added is not an include directory object.') ids.append(a) @@ -1313,9 +1294,7 @@ class Generator: def __init__(self, args, kwargs): if len(args) != 1: raise InvalidArguments('Generator requires exactly one positional argument: the executable') - exe = args[0] - if hasattr(exe, 'held_object'): - exe = exe.held_object + exe = unholder(args[0]) if not isinstance(exe, (Executable, dependencies.ExternalProgram)): raise InvalidArguments('First generator argument must be an executable.') self.exe = exe @@ -1416,9 +1395,7 @@ class Generator: class GeneratedList: def __init__(self, generator, subdir, preserve_path_from=None, extra_args=None): - if hasattr(generator, 'held_object'): - generator = generator.held_object - self.generator = generator + self.generator = unholder(generator) self.name = self.generator.exe self.subdir = subdir self.infilelist = [] @@ -1428,10 +1405,10 @@ class GeneratedList: self.depend_files = [] self.preserve_path_from = preserve_path_from self.extra_args = extra_args if extra_args is not None else [] - if isinstance(generator.exe, dependencies.ExternalProgram): - if not generator.exe.found(): + if isinstance(self.generator.exe, dependencies.ExternalProgram): + if not self.generator.exe.found(): raise InvalidArguments('Tried to use not-found external program as generator') - path = generator.exe.get_path() + path = self.generator.exe.get_path() if os.path.isabs(path): # Can only add a dependency on an external program which we # know the absolute path of @@ -1873,9 +1850,7 @@ class SharedLibrary(BuildTarget): # Visual Studio module-definitions file if 'vs_module_defs' in kwargs: - path = kwargs['vs_module_defs'] - if hasattr(path, 'held_object'): - path = path.held_object + path = unholder(kwargs['vs_module_defs']) if isinstance(path, str): if os.path.isabs(path): self.vs_module_defs = File.from_absolute_file(path) @@ -2027,9 +2002,7 @@ class CustomTarget(Target): def get_target_dependencies(self): deps = self.dependencies[:] deps += self.extra_depends - for c in self.sources: - if hasattr(c, 'held_object'): - c = c.held_object + for c in unholder(self.sources): if isinstance(c, (BuildTarget, CustomTarget)): deps.append(c) return deps @@ -2161,9 +2134,7 @@ class CustomTarget(Target): if not isinstance(self.build_always_stale, bool): raise InvalidArguments('Argument build_always_stale must be a boolean.') extra_deps, depend_files = [extract_as_list(kwargs, c, pop=False) for c in ['depends', 'depend_files']] - for ed in extra_deps: - while hasattr(ed, 'held_object'): - ed = ed.held_object + for ed in unholder(extra_deps): if not isinstance(ed, (CustomTarget, BuildTarget)): raise InvalidArguments('Can only depend on toplevel targets: custom_target or build_target (executable or a library) got: {}({})' .format(type(ed), ed)) @@ -2198,9 +2169,7 @@ class CustomTarget(Target): def get_generated_lists(self): genlists = [] - for c in self.sources: - if hasattr(c, 'held_object'): - c = c.held_object + for c in unholder(self.sources): if isinstance(c, GeneratedList): genlists.append(c) return genlists @@ -2463,9 +2432,7 @@ def get_sources_string_names(sources, backend): get all the output basenames. ''' names = [] - for s in sources: - if hasattr(s, 'held_object'): - s = s.held_object + for s in unholder(sources): if isinstance(s, str): names.append(s) elif isinstance(s, (BuildTarget, CustomTarget, CustomTargetIndex, GeneratedList)): |