Skip to content

Commit

Permalink
Fix a problem when anyone actually tries to use a non-found dependency
Browse files Browse the repository at this point in the history
Make not-found dependency object identically to prior to PR mesonbuild#2615
Extend test case to cover uses of the not-found dependency object

Fixes mesonbuild#2872

Also, prevent direct instantation of class Dependency, since
BuildTarget.add_deps() rejects that.

It might be better to fix BuildTarget.add_deps() and look for any other
similar problems...
  • Loading branch information
jon-turney committed Jan 4, 2018
1 parent 65f78a7 commit cafd77b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mesonbuild/dependencies/__init__.py
Expand Up @@ -15,7 +15,8 @@
from .base import ( # noqa: F401
Dependency, DependencyException, DependencyMethods, ExternalProgram,
ExternalDependency, ExternalLibrary, ExtraFrameworkDependency, InternalDependency,
PkgConfigDependency, find_external_dependency, get_dep_identifier, packages, _packages_accept_language)
PkgConfigDependency, find_external_dependency, get_dep_identifier, packages,
_packages_accept_language, NotFoundDependency)
from .dev import GMockDependency, GTestDependency, LLVMDependency, ValgrindDependency
from .misc import (BoostDependency, MPIDependency, Python3Dependency, ThreadDependency, PcapDependency, CupsDependency, LibWmfDependency)
from .platform import AppleFrameworks
Expand Down
8 changes: 8 additions & 0 deletions mesonbuild/dependencies/base.py
Expand Up @@ -62,6 +62,9 @@ class DependencyMethods(Enum):

class Dependency:
def __init__(self, type_name, kwargs):
if type(self) == Dependency.__class__:
raise MesonException('The class Dependency() should not be directly instantiated')

self.name = "null"
self.version = 'none'
self.language = None # None means C-like
Expand Down Expand Up @@ -201,6 +204,11 @@ def get_compiler(self):
return self.compiler


class NotFoundDependency(ExternalDependency):
def __init__(self, environment):
super().__init__('not-found', environment, None, {})


class ConfigToolDependency(ExternalDependency):

"""Class representing dependencies found using a config tool."""
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/interpreter.py
Expand Up @@ -23,7 +23,7 @@
from . import mesonlib
from .mesonlib import FileMode, Popen_safe, listify, extract_as_list
from .dependencies import ExternalProgram
from .dependencies import InternalDependency, Dependency, DependencyException
from .dependencies import InternalDependency, Dependency, DependencyException, NotFoundDependency
from .interpreterbase import InterpreterBase
from .interpreterbase import check_stringlist, noPosargs, noKwargs, stringArgs, permittedKwargs
from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode
Expand Down Expand Up @@ -2212,7 +2212,7 @@ def func_dependency(self, node, args, kwargs):
if name == '':
if required:
raise InvalidArguments('Dependency is both required and not-found')
return DependencyHolder(Dependency('not-found', {}))
return DependencyHolder(NotFoundDependency(self.environment))

if '<' in name or '>' in name or '=' in name:
raise InvalidArguments('Characters <, > and = are forbidden in dependency names. To specify'
Expand Down
5 changes: 4 additions & 1 deletion test cases/common/171 not-found dependency/meson.build
@@ -1,8 +1,11 @@
project('dep-test')
project('dep-test', 'c')

dep = dependency('', required:false)
if dep.found()
error('not-found dependency was found')
endif

assert(dep.type_name() == 'not-found', 'dependency should be of type "not-found" not ' + dep.type_name())

library('testlib', 'testlib.c', dependencies: [dep])
subdir('sub', if_found: dep)
1 change: 1 addition & 0 deletions test cases/common/171 not-found dependency/sub/meson.build
@@ -0,0 +1 @@
error('should be disabled by subdir(if_found:)')
Empty file.

0 comments on commit cafd77b

Please sign in to comment.