Merge pull request #8912 from mensinda/fixBothLibraries

Fix `BothLibraries` processing
pull/8925/head
Jussi Pakkanen 3 years ago committed by GitHub
commit 0e5f88baf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .github/workflows/os_comp.yml
  2. 12
      mesonbuild/build.py
  3. 11
      mesonbuild/dependencies/base.py
  4. 10
      mesonbuild/interpreter/interpreter.py
  5. 3
      mesonbuild/interpreter/interpreterobjects.py
  6. 4
      mesonbuild/modules/gnome.py
  7. 2
      test cases/common/102 extract same name/meson.build
  8. 4
      test cases/common/126 generated llvm ir/meson.build
  9. 4
      test cases/common/127 generated assembly/meson.build
  10. 2
      test cases/common/146 library at root/meson.build
  11. 2
      test cases/common/153 wrap file should not failed/subprojects/zlib-1.2.8/meson.build
  12. 2
      test cases/common/155 subproject dir name collision/custom_subproject_dir/B/meson.build
  13. 2
      test cases/common/155 subproject dir name collision/custom_subproject_dir/C/meson.build
  14. 2
      test cases/common/155 subproject dir name collision/other_subdir/meson.build
  15. 2
      test cases/common/167 subproject nested subproject dirs/contrib/subprojects/alpha/meson.build
  16. 8
      test cases/common/178 bothlibraries/dummy.py
  17. 14
      test cases/common/178 bothlibraries/meson.build
  18. 4
      test cases/common/22 object extraction/meson.build
  19. 3
      test cases/common/223 persubproject options/meson.build
  20. 7
      test cases/common/223 persubproject options/test.json
  21. 2
      test cases/common/72 shared subproject/subprojects/B/meson.build
  22. 2
      test cases/common/72 shared subproject/subprojects/C/meson.build
  23. 2
      test cases/common/73 shared subproject 2/subprojects/B/meson.build
  24. 2
      test cases/common/73 shared subproject 2/subprojects/C/meson.build
  25. 2
      test cases/failing/16 extract from subproject/subprojects/sub_project/meson.build
  26. 2
      test cases/fortran/21 install static/meson.build
  27. 9
      test cases/fortran/21 install static/test.json
  28. 2
      test cases/frameworks/10 gtk-doc/meson.build
  29. 2
      test cases/linuxlike/5 dependency versions/subprojects/somelib/meson.build
  30. 2
      test cases/linuxlike/5 dependency versions/subprojects/somelibnover/meson.build
  31. 2
      test cases/linuxlike/5 dependency versions/subprojects/somelibver/meson.build
  32. 2
      test cases/rust/4 polyglot/meson.build

@ -54,7 +54,11 @@ jobs:
cfg:
- CC: 'gcc'
CXX: 'g++'
- MESON_ARGS: '--unity=on'
- MESON_ARGS: '--unity=on -Ddefault_library=static'
RUN_TESTS_ARGS: '--no-unittests'
CC: 'gcc'
CXX: 'g++'
- MESON_ARGS: '-Ddefault_library=both'
RUN_TESTS_ARGS: '--no-unittests'
CC: 'gcc'
CXX: 'g++'

@ -1715,6 +1715,9 @@ class Executable(BuildTarget):
# Only linkwithable if using export_dynamic
self.is_linkwithable = self.export_dynamic
# Remember that this exe was returned by `find_program()` through an override
self.was_returned_by_find_program = False
def get_default_install_dir(self, environment: environment.Environment) -> str:
return environment.get_bindir()
@ -2154,6 +2157,10 @@ class BothLibraries(HoldableObject):
self._preferred_library = 'shared'
self.shared = shared
self.static = static
self.subproject = self.shared.subproject
def __repr__(self) -> str:
return f'<BothLibraries: static={repr(self.static)}; shared={repr(self.shared)}>'
def get_preferred_library(self) -> BuildTarget:
if self._preferred_library == 'shared':
@ -2167,6 +2174,8 @@ class CommandBase:
cmd = listify(cmd)
final_cmd = []
for c in cmd:
if isinstance(c, BothLibraries):
c = c.get_preferred_library()
if isinstance(c, str):
final_cmd.append(c)
elif isinstance(c, File):
@ -2265,6 +2274,7 @@ class CustomTarget(Target, CommandBase):
def process_kwargs(self, kwargs, backend):
self.process_kwargs_base(kwargs)
self.sources = extract_as_list(kwargs, 'input')
self.sources = [x.get_preferred_library() if isinstance(x, BothLibraries) else x for x in self.sources]
if 'output' not in kwargs:
raise InvalidArguments('Missing keyword argument "output".')
self.outputs = listify(kwargs['output'])
@ -2641,6 +2651,8 @@ def get_sources_string_names(sources, backend):
'''
names = []
for s in sources:
if isinstance(s, BothLibraries):
s = s.get_preferred_library()
if isinstance(s, str):
names.append(s)
elif isinstance(s, (BuildTarget, CustomTarget, CustomTargetIndex, GeneratedList)):

@ -29,7 +29,7 @@ from ..interpreterbase import FeatureDeprecated
if T.TYPE_CHECKING:
from ..compilers.compilers import Compiler
from ..environment import Environment
from ..build import BuildTarget
from ..build import BuildTarget, BothLibraries
from ..mesonlib import FileOrString
@ -222,8 +222,8 @@ class Dependency(HoldableObject):
class InternalDependency(Dependency):
def __init__(self, version: str, incdirs: T.List[str], compile_args: T.List[str],
link_args: T.List[str], libraries: T.List['BuildTarget'],
whole_libraries: T.List['BuildTarget'], sources: T.List['FileOrString'],
link_args: T.List[str], libraries: T.List[T.Union['BuildTarget', 'BothLibraries']],
whole_libraries: T.List[T.Union['BuildTarget', 'BothLibraries']], sources: T.List['FileOrString'],
ext_deps: T.List[Dependency], variables: T.Dict[str, T.Any]):
super().__init__(DependencyTypeName('internal'), {})
self.version = version
@ -237,6 +237,11 @@ class InternalDependency(Dependency):
self.ext_deps = ext_deps
self.variables = variables
# Deal with BothLibraries
from ..build import BothLibraries
self.libraries = [x.get_preferred_library() if isinstance(x, BothLibraries) else x for x in self.libraries]
self.whole_libraries = [x.static if isinstance(x, BothLibraries) else x for x in self.whole_libraries]
def __deepcopy__(self, memo: T.Dict[int, 'InternalDependency']) -> 'InternalDependency':
result = self.__class__.__new__(self.__class__)
assert isinstance(result, InternalDependency)

@ -28,7 +28,7 @@ from ..depfile import DepFile
from ..interpreterbase import ContainerTypeInfo, InterpreterBase, KwargInfo, typed_kwargs, typed_pos_args
from ..interpreterbase import noPosargs, noKwargs, stringArgs, permittedKwargs, noArgsFlattening, unholder_return
from ..interpreterbase import InterpreterException, InvalidArguments, InvalidCode, SubdirDoneRequest
from ..interpreterbase import InterpreterObject, Disabler, disablerIfNotFound
from ..interpreterbase import Disabler, disablerIfNotFound
from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs, FeatureDeprecatedKwargs
from ..interpreterbase import ObjectHolder, RangeHolder
from ..interpreterbase import TYPE_nkwargs, TYPE_nvar, TYPE_var
@ -66,7 +66,7 @@ if T.TYPE_CHECKING:
from . import kwargs
# Input source types passed to Targets
SourceInputs = T.Union[mesonlib.File, build.GeneratedList, build.BuildTarget,
SourceInputs = T.Union[mesonlib.File, build.GeneratedList, build.BuildTarget, build.BothLibraries,
build.CustomTargetIndex, build.CustomTarget, build.GeneratedList, str]
# Input source types passed to the build.Target5 classes
SourceOutputs = T.Union[mesonlib.File, build.GeneratedList,
@ -1404,6 +1404,8 @@ external dependencies (including libraries) must go to "dependencies".''')
# Only store successful lookups
self.store_name_lookups(args)
mlog.log('Program', mlog.bold(progobj.name), 'found:', mlog.green('YES'), *extra_info)
if isinstance(progobj, build.Executable):
progobj.was_returned_by_find_program = True
return progobj
def program_lookup(self, args, for_machine, required, search_dirs, extra_info):
@ -2490,6 +2492,8 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey
sources = [sources]
results: T.List['SourceOutputs'] = []
for s in sources:
if isinstance(s, build.BothLibraries):
s = s.get_preferred_library()
if isinstance(s, str):
self.validate_within_subproject(self.subdir, s)
results.append(mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s))
@ -2655,7 +2659,7 @@ This will become a hard error in the future.''', location=self.current_node)
raise InterpreterException('Tried to add non-existing source file %s.' % s)
# Only permit object extraction from the same subproject
def validate_extraction(self, buildtarget: InterpreterObject) -> None:
def validate_extraction(self, buildtarget: mesonlib.HoldableObject) -> None:
if self.subproject != buildtarget.subproject:
raise InterpreterException('Tried to extract objects from a different subproject.')

@ -807,8 +807,9 @@ class BuildTargetHolder(ObjectHolder[_BuildTarget]):
@noPosargs
@noKwargs
@FeatureNew('BuildTarget.found', '0.59.0')
def found_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> bool:
if not (isinstance(self.held_object, build.Executable) and self.held_object.was_returned_by_find_program):
FeatureNew.single_use('BuildTarget.found', '0.59.0', subproject=self.held_object.subproject)
return True
@noPosargs

@ -480,9 +480,11 @@ class GnomeModule(ExtensionModule):
return cflags, internal_ldflags, external_ldflags, external_ldflags_nodedup, gi_includes
def _unwrap_gir_target(self, girtarget, state):
if isinstance(girtarget, build.BothLibraries):
girtarget = girtarget.get_preferred_library()
if not isinstance(girtarget, (build.Executable, build.SharedLibrary,
build.StaticLibrary)):
raise MesonException('Gir target must be an executable or library')
raise MesonException(f'Gir target must be an executable or library but is "{girtarget}" of type {type(girtarget).__name__}')
STATIC_BUILD_REQUIRED_VERSION = ">=1.58.1"
if isinstance(girtarget, (build.StaticLibrary)) and \

@ -12,7 +12,7 @@ if meson.backend() == 'xcode'
error('MESON_SKIP_TEST, Xcode can not extract objs when they would have the same filename.')
endif
lib = shared_library('somelib', ['lib.c', 'src/lib.c'])
lib = library('somelib', ['lib.c', 'src/lib.c'])
# Also tests that the object list is flattened properly
obj = lib.extract_objects(['lib.c', ['src/lib.c']])
exe = executable('main', 'main.c', objects: obj)

@ -14,7 +14,7 @@ copygen = generator(copy,
arguments : ['@INPUT@', '@OUTPUT@'],
output : '@BASENAME@')
l = shared_library('square-gen', copygen.process('square.ll.in'))
l = library('square-gen', copygen.process('square.ll.in'))
test('square-gen-test', executable('square-gen-test', 'main.c', link_with : l))
@ -23,6 +23,6 @@ copyct = custom_target('square',
output : 'square.ll',
command : [copy, '@INPUT@', '@OUTPUT@'])
l = shared_library('square-ct', copyct)
l = library('square-ct', copyct)
test('square-ct-test', executable('square-ct-test', 'main.c', link_with : l))

@ -50,7 +50,7 @@ copygen = generator(copy,
arguments : ['@INPUT@', '@OUTPUT@'],
output : '@BASENAME@')
l = shared_library('square-gen', crt_workaround + [copygen.process(input)],
l = library('square-gen', crt_workaround + [copygen.process(input)],
vs_module_defs: 'square.def')
test('square-gen-test', executable('square-gen-test', 'main.c', link_with : l))
@ -60,7 +60,7 @@ copyct = custom_target('square',
output : output,
command : [copy, '@INPUT@', '@OUTPUT@'])
l = shared_library('square-ct', crt_workaround + [copyct],
l = library('square-ct', crt_workaround + [copyct],
vs_module_defs: 'square.def')
test('square-ct-test', executable('square-ct-test', 'main.c', link_with : l))

@ -1,3 +1,3 @@
project('lib@root', 'c')
lib = shared_library('lib', 'lib.c')
lib = library('lib', 'lib.c')
subdir('main')

@ -1,2 +1,2 @@
project('shared lib', 'c')
shared_library('foo', 'foo.c')
library('foo', 'foo.c')

@ -1,4 +1,4 @@
project('B', 'c')
C = subproject('C')
c = C.get_variable('c')
b = shared_library('b', 'b.c', link_with : c)
b = library('b', 'b.c', link_with : c)

@ -1,2 +1,2 @@
project('C', 'c')
c = shared_library('c', 'c.c')
c = library('c', 'c.c')

@ -1 +1 @@
other = shared_library('other', 'custom_subproject_dir/other.c')
other = library('other', 'custom_subproject_dir/other.c')

@ -1,4 +1,4 @@
project('alpha project', 'c', subproject_dir: 'var/subprojects')
b = subproject('beta')
l = shared_library('a', 'a.c', link_with : b.get_variable('lb'))
l = library('a', 'a.c', link_with : b.get_variable('lb'))

@ -0,0 +1,8 @@
#!/usr/bin/env python3
from pathlib import Path
import sys
if __name__ == '__main__':
Path(sys.argv[1]).write_text('Hello World\n')
raise SystemExit(0)

@ -1,15 +1,29 @@
project('both libraries linking test', 'c')
both_libs = both_libraries('mylib', 'libfile.c')
dep = declare_dependency(link_with: both_libs)
exe_shared = executable('prog-shared', 'main.c', link_with : both_libs.get_shared_lib())
exe_static = executable('prog-static', 'main.c',
c_args : ['-DSTATIC_COMPILATION'],
link_with : both_libs.get_static_lib())
exe_both = executable('prog-both', 'main.c', link_with : both_libs)
exe_dep = executable('prog-dep', 'main.c', dependencies : [dep])
# Try using it in a custom_target
custom_target('tgt_a',
command: [
find_program('./dummy.py'),
'@OUTPUT@',
both_libs,
],
output: ['hello1.txt'],
input: [both_libs],
)
test('runtest-shared', exe_shared)
test('runtest-static', exe_static)
test('runtest-both', exe_both)
test('runtest-dep', exe_dep)
# Same as above, but using build_target()
both_libs2 = build_target('mylib2', 'libfile.c', target_type: 'both_libraries')

@ -3,8 +3,8 @@ project('object extraction', 'c')
if meson.is_unity()
message('Skipping extraction test because this is a Unity build.')
else
lib1 = shared_library('somelib', 'src/lib.c')
lib2 = shared_library('somelib2', 'lib.c', 'header.h', 'lib2.c')
lib1 = library('somelib', 'src/lib.c')
lib2 = library('somelib2', 'lib.c', 'header.h', 'lib2.c')
obj1 = lib1.extract_objects('src/lib.c')
obj2 = lib2.extract_objects(['lib.c'])

@ -1,6 +1,5 @@
project('persubproject options', 'c',
default_options : ['default_library=both',
'werror=true',
default_options : ['werror=true',
'warning_level=3'])
assert(get_option('default_library') == 'both', 'Parent default_library should be "both"')

@ -0,0 +1,7 @@
{
"matrix": {
"options": {
"default_library": [ { "val": "both" } ]
}
}
}

@ -1,4 +1,4 @@
project('B', 'c')
C = subproject('C')
c = C.get_variable('c')
b = shared_library('b', 'b.c', link_with : c)
b = library('b', 'b.c', link_with : c)

@ -1,2 +1,2 @@
project('C', 'c')
c = shared_library('c', 'c.c')
c = library('c', 'c.c')

@ -1,4 +1,4 @@
project('B', 'c')
C = subproject('C')
c = C.get_variable('c')
b = shared_library('b', 'b.c', link_with : c)
b = library('b', 'b.c', link_with : c)

@ -1,2 +1,2 @@
project('C', 'c')
c = shared_library('c', 'c.c')
c = library('c', 'c.c')

@ -1,3 +1,3 @@
project('extract subproject object -- subproject', 'c')
lib = shared_library('sub_lib', 'sub_lib.c')
lib = library('sub_lib', 'sub_lib.c')

@ -3,7 +3,7 @@
# - Is an install:true static library to trigger certain codepath (promotion to link_whole)
# - Does fortran code 'generation' with configure_file
# - Uses .F90 ext (capital F typically denotes a dependence on preprocessor treatment, which however is not used)
project('try-static-subproject-dependency', 'fortran', default_options: ['default_library=static'])
project('try-static-subproject-dependency', 'fortran')
static_dep = dependency('static_hello', fallback: ['static_hello', 'static_hello_dep'])

@ -1,5 +1,10 @@
{
"installed": [
{"file": "usr/lib/libmainstatic.a", "type": "file"}
]
}
],
"matrix": {
"options": {
"default_library": [ { "val": "static" } ]
}
}
}

@ -26,7 +26,7 @@ endif
gobject = dependency('gobject-2.0')
libfoo = library('foo', 'foo.c',
libfoo = shared_library('foo', 'foo.c',
include_directories: inc,
dependencies: gobject,
)

@ -1,7 +1,7 @@
# Define version only in project, should get inherited by declare_dependency
project('some', 'c', version : '0.1')
somelib = shared_library('some', 'lib.c')
somelib = library('some', 'lib.c')
someinc = include_directories('.')
some_dep = declare_dependency(link_with : somelib,

@ -1,6 +1,6 @@
project('some', 'c')
somelib = shared_library('some', 'lib.c')
somelib = library('some', 'lib.c')
someinc = include_directories('.')
# Define version only in declare_dependency

@ -1,6 +1,6 @@
project('some', 'c')
somelib = shared_library('some', 'lib.c')
somelib = library('some', 'lib.c')
someinc = include_directories('.')
# Define version only in declare_dependency

@ -4,6 +4,6 @@ if host_machine.system() == 'darwin'
error('MESON_SKIP_TEST: doesnt work right on macos, please fix!')
endif
l = library('stuff', 'stuff.rs', rust_crate_type: 'cdylib', install : true)
l = shared_library('stuff', 'stuff.rs', rust_crate_type: 'cdylib', install : true)
e = executable('prog', 'prog.c', link_with : l, install : true)
test('polyglottest', e)

Loading…
Cancel
Save