|
|
|
# Copyright 2015 The Meson development team
|
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import os
|
|
|
|
from pathlib import PurePath
|
|
|
|
|
tree-wide: remove unused imports
./setup.py:17:1: F401 'os' imported but unused
import os
^
./setup.py:37:1: F401 'stat.ST_MODE' imported but unused
from stat import ST_MODE
^
./run_tests.py:17:1: F401 'os' imported but unused
import subprocess, sys, os
^
./run_tests.py:18:1: F401 'shutil' imported but unused
import shutil
^
./run_unittests.py:23:1: F401 'mesonbuild.dependencies.Qt5Dependency' imported but unused
from mesonbuild.dependencies import PkgConfigDependency, Qt5Dependency
^
./mesonbuild/build.py:15:1: F401 '.coredata' imported but unused
from . import coredata
^
./mesonbuild/interpreter.py:32:1: F401 'subprocess' imported but unused
import os, sys, subprocess, shutil, uuid, re
^
./mesonbuild/interpreter.py:32:1: F401 're' imported but unused
import os, sys, subprocess, shutil, uuid, re
^
./mesonbuild/dependencies.py:23:1: F401 'subprocess' imported but unused
import os, stat, glob, subprocess, shutil
^
./mesonbuild/mesonlib.py:17:1: F401 'sys' imported but unused
import platform, subprocess, operator, os, shutil, re, sys
^
./mesonbuild/modules/qt5.py:15:1: F401 'subprocess' imported but unused
import os, subprocess
^
./mesonbuild/modules/pkgconfig.py:15:1: F401 '..coredata' imported but unused
from .. import coredata, build
^
./mesonbuild/scripts/scanbuild.py:15:1: F401 'sys' imported but unused
import sys, os
^
./mesonbuild/scripts/meson_exe.py:20:1: F401 'subprocess' imported but unused
import subprocess
^
./mesonbuild/scripts/meson_exe.py:22:1: F401 '..mesonlib.MesonException' imported but unused
from ..mesonlib import MesonException, Popen_safe
^
./mesonbuild/scripts/symbolextractor.py:23:1: F401 'subprocess' imported but unused
import os, sys, subprocess
^
./mesonbuild/scripts/symbolextractor.py:25:1: F401 '..mesonlib.MesonException' imported but unused
from ..mesonlib import MesonException, Popen_safe
^
./mesonbuild/scripts/meson_install.py:19:1: F401 '..mesonlib.MesonException' imported but unused
from ..mesonlib import MesonException, Popen_safe
^
./mesonbuild/scripts/yelphelper.py:15:1: F401 'sys' imported but unused
import sys, os
^
./mesonbuild/scripts/yelphelper.py:20:1: F401 '..mesonlib.MesonException' imported but unused
from ..mesonlib import MesonException
^
./mesonbuild/backend/vs2010backend.py:17:1: F401 're' imported but unused
import re
^
./test cases/vala/8 generated sources/src/copy_file.py:3:1: F401 'os' imported but unused
import os
^
./test cases/common/107 postconf/postconf.py:3:1: F401 'sys' imported but unused
import sys, os
^
./test cases/common/129 object only target/obj_generator.py:5:1: F401 'shutil' imported but unused
import sys, shutil, subprocess
^
./test cases/common/57 custom target chain/usetarget/subcomp.py:3:1: F401 'os' imported but unused
import sys, os
^
./test cases/common/95 dep fallback/subprojects/boblib/genbob.py:3:1: F401 'os' imported but unused
import os
^
./test cases/common/98 gen extra/srcgen.py:4:1: F401 'os' imported but unused
import os
^
./test cases/common/113 generatorcustom/gen.py:3:1: F401 'os' imported but unused
import sys, os
^
./test cases/common/113 generatorcustom/catter.py:3:1: F401 'os' imported but unused
import sys, os
^
./test cases/common/59 object generator/obj_generator.py:5:1: F401 'shutil' imported but unused
import sys, shutil, subprocess
^
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
8 years ago
|
|
|
from .. import build
|
|
|
|
from .. import dependencies
|
|
|
|
from .. import mesonlib
|
|
|
|
from .. import mlog
|
|
|
|
from . import ModuleReturnValue
|
|
|
|
from . import ExtensionModule
|
|
|
|
from ..interpreterbase import permittedKwargs
|
|
|
|
|
|
|
|
class DependenciesHelper:
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.pub_libs = []
|
|
|
|
self.pub_reqs = []
|
|
|
|
self.priv_libs = []
|
|
|
|
self.priv_reqs = []
|
|
|
|
self.cflags = []
|
|
|
|
self.version_reqs = {}
|
|
|
|
|
|
|
|
def add_pub_libs(self, libs):
|
|
|
|
libs, reqs, cflags = self._process_libs(libs, True)
|
|
|
|
self.pub_libs += libs
|
|
|
|
self.pub_reqs += reqs
|
|
|
|
self.cflags += cflags
|
|
|
|
|
|
|
|
def add_priv_libs(self, libs):
|
|
|
|
libs, reqs, _ = self._process_libs(libs, False)
|
|
|
|
self.priv_libs += libs
|
|
|
|
self.priv_reqs += reqs
|
|
|
|
|
|
|
|
def add_pub_reqs(self, reqs):
|
|
|
|
self.pub_reqs += self._process_reqs(reqs)
|
|
|
|
|
|
|
|
def add_priv_reqs(self, reqs):
|
|
|
|
self.priv_reqs += self._process_reqs(reqs)
|
|
|
|
|
|
|
|
def _process_reqs(self, reqs):
|
|
|
|
'''Returns string names of requirements'''
|
|
|
|
processed_reqs = []
|
|
|
|
for obj in mesonlib.listify(reqs, unholder=True):
|
|
|
|
if hasattr(obj, 'generated_pc'):
|
|
|
|
processed_reqs.append(obj.generated_pc)
|
|
|
|
elif hasattr(obj, 'pcdep'):
|
|
|
|
pcdeps = mesonlib.listify(obj.pcdep)
|
|
|
|
for d in pcdeps:
|
|
|
|
processed_reqs += d.name
|
|
|
|
self.add_version_reqs(d.name, obj.version_reqs)
|
|
|
|
elif isinstance(obj, dependencies.PkgConfigDependency):
|
|
|
|
if obj.found():
|
|
|
|
processed_reqs.append(obj.name)
|
|
|
|
self.add_version_reqs(obj.name, obj.version_reqs)
|
|
|
|
elif isinstance(obj, str):
|
|
|
|
name, version_req = self.split_version_req(obj)
|
|
|
|
processed_reqs.append(name)
|
|
|
|
self.add_version_reqs(name, version_req)
|
|
|
|
elif isinstance(obj, dependencies.Dependency) and not obj.found():
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise mesonlib.MesonException('requires argument not a string, '
|
|
|
|
'library with pkgconfig-generated file '
|
|
|
|
'or pkgconfig-dependency object, '
|
|
|
|
'got {!r}'.format(obj))
|
|
|
|
return processed_reqs
|
|
|
|
|
|
|
|
def add_cflags(self, cflags):
|
|
|
|
self.cflags += mesonlib.stringlistify(cflags)
|
|
|
|
|
|
|
|
def _process_libs(self, libs, public):
|
|
|
|
libs = mesonlib.listify(libs, unholder=True)
|
|
|
|
processed_libs = []
|
|
|
|
processed_reqs = []
|
|
|
|
processed_cflags = []
|
|
|
|
for obj in libs:
|
|
|
|
if hasattr(obj, 'pcdep'):
|
|
|
|
pcdeps = mesonlib.listify(obj.pcdep)
|
|
|
|
for d in pcdeps:
|
|
|
|
processed_reqs += d.name
|
|
|
|
self.add_version_reqs(d.name, obj.version_reqs)
|
|
|
|
elif hasattr(obj, 'generated_pc'):
|
|
|
|
processed_reqs.append(obj.generated_pc)
|
|
|
|
elif isinstance(obj, dependencies.PkgConfigDependency):
|
|
|
|
if obj.found():
|
|
|
|
processed_reqs.append(obj.name)
|
|
|
|
self.add_version_reqs(obj.name, obj.version_reqs)
|
|
|
|
elif isinstance(obj, dependencies.ThreadDependency):
|
|
|
|
processed_libs += obj.get_compiler().thread_link_flags(obj.env)
|
|
|
|
processed_cflags += obj.get_compiler().thread_flags(obj.env)
|
|
|
|
elif isinstance(obj, dependencies.Dependency):
|
|
|
|
if obj.found():
|
|
|
|
processed_libs += obj.get_link_args()
|
|
|
|
processed_cflags += obj.get_compile_args()
|
|
|
|
elif isinstance(obj, build.SharedLibrary) and obj.shared_library_only:
|
|
|
|
# Do not pull dependencies for shared libraries because they are
|
|
|
|
# only required for static linking. Adding private requires has
|
|
|
|
# the side effect of exposing their cflags, which is the
|
|
|
|
# intended behaviour of pkg-config but force Debian to add more
|
|
|
|
# than needed build deps.
|
|
|
|
# See https://bugs.freedesktop.org/show_bug.cgi?id=105572
|
|
|
|
processed_libs.append(obj)
|
|
|
|
if public:
|
|
|
|
if not hasattr(obj, 'generated_pc'):
|
|
|
|
obj.generated_pc = self.name
|
|
|
|
elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)):
|
|
|
|
processed_libs.append(obj)
|
|
|
|
self.add_priv_libs(obj.get_dependencies())
|
|
|
|
self.add_priv_libs(obj.get_external_deps())
|
|
|
|
if public:
|
|
|
|
if not hasattr(obj, 'generated_pc'):
|
|
|
|
obj.generated_pc = self.name
|
|
|
|
elif isinstance(obj, str):
|
|
|
|
processed_libs.append(obj)
|
|
|
|
else:
|
|
|
|
raise mesonlib.MesonException('library argument not a string, library or dependency object.')
|
|
|
|
|
|
|
|
return processed_libs, processed_reqs, processed_cflags
|
|
|
|
|
|
|
|
def add_version_reqs(self, name, version_reqs):
|
|
|
|
if version_reqs:
|
|
|
|
vreqs = self.version_reqs.get(name, [])
|
|
|
|
vreqs += mesonlib.stringlistify(version_reqs)
|
|
|
|
self.version_reqs[name] = vreqs
|
|
|
|
|
|
|
|
def split_version_req(self, s):
|
|
|
|
for op in ['>=', '<=', '!=', '==', '=', '>', '<']:
|
|
|
|
pos = s.find(op)
|
|
|
|
if pos > 0:
|
|
|
|
return s[0:pos].strip(), s[pos:].strip()
|
|
|
|
return s, None
|
|
|
|
|
|
|
|
def format_vreq(self, vreq):
|
|
|
|
# vreq are '>=1.0' and pkgconfig wants '>= 1.0'
|
|
|
|
for op in ['>=', '<=', '!=', '==', '=', '>', '<']:
|
|
|
|
if vreq.startswith(op):
|
|
|
|
return op + ' ' + vreq[len(op):]
|
|
|
|
return vreq
|
|
|
|
|
|
|
|
def format_reqs(self, reqs):
|
|
|
|
result = []
|
|
|
|
for name in reqs:
|
|
|
|
vreqs = self.version_reqs.get(name, None)
|
|
|
|
if vreqs:
|
|
|
|
result += [name + ' ' + self.format_vreq(vreq) for vreq in vreqs]
|
|
|
|
else:
|
|
|
|
result += [name]
|
|
|
|
return ', '.join(result)
|
|
|
|
|
|
|
|
def remove_dups(self):
|
|
|
|
def _fn(xs):
|
|
|
|
# Remove duplicates whilst preserving original order
|
|
|
|
result = []
|
|
|
|
for x in xs:
|
|
|
|
if x not in result:
|
|
|
|
result.append(x)
|
|
|
|
return result
|
|
|
|
self.pub_libs = _fn(self.pub_libs)
|
|
|
|
self.pub_reqs = _fn(self.pub_reqs)
|
|
|
|
self.priv_libs = _fn(self.priv_libs)
|
|
|
|
self.priv_reqs = _fn(self.priv_reqs)
|
|
|
|
self.cflags = _fn(self.cflags)
|
|
|
|
|
|
|
|
# Remove from private libs/reqs if they are in public already
|
|
|
|
self.priv_libs = [i for i in self.priv_libs if i not in self.pub_libs]
|
|
|
|
self.priv_reqs = [i for i in self.priv_reqs if i not in self.pub_reqs]
|
|
|
|
|
|
|
|
class PkgConfigModule(ExtensionModule):
|
|
|
|
|
|
|
|
def _get_lname(self, l, msg, pcfile):
|
|
|
|
# Nothing special
|
|
|
|
if not l.name_prefix_set:
|
|
|
|
return l.name
|
|
|
|
# Sometimes people want the library to start with 'lib' everywhere,
|
|
|
|
# which is achieved by setting name_prefix to '' and the target name to
|
|
|
|
# 'libfoo'. In that case, try to get the pkg-config '-lfoo' arg correct.
|
|
|
|
if l.prefix == '' and l.name.startswith('lib'):
|
|
|
|
return l.name[3:]
|
|
|
|
# If the library is imported via an import library which is always
|
|
|
|
# named after the target name, '-lfoo' is correct.
|
|
|
|
if l.import_filename:
|
|
|
|
return l.name
|
|
|
|
# In other cases, we can't guarantee that the compiler will be able to
|
|
|
|
# find the library via '-lfoo', so tell the user that.
|
|
|
|
mlog.warning(msg.format(l.name, 'name_prefix', l.name, pcfile))
|
|
|
|
return l.name
|
|
|
|
|
|
|
|
def _escape(self, value):
|
|
|
|
'''
|
|
|
|
We cannot use shlex.quote because it quotes with ' and " which does not
|
|
|
|
work with pkg-config and pkgconf at all.
|
|
|
|
'''
|
|
|
|
# We should always write out paths with / because pkg-config requires
|
|
|
|
# spaces to be quoted with \ and that messes up on Windows:
|
|
|
|
# https://bugs.freedesktop.org/show_bug.cgi?id=103203
|
|
|
|
if isinstance(value, PurePath):
|
|
|
|
value = value.as_posix()
|
|
|
|
return value.replace(' ', '\ ')
|
|
|
|
|
|
|
|
def _make_relative(self, prefix, subdir):
|
|
|
|
if isinstance(prefix, PurePath):
|
|
|
|
prefix = prefix.as_posix()
|
|
|
|
if isinstance(subdir, PurePath):
|
|
|
|
subdir = subdir.as_posix()
|
|
|
|
if subdir.startswith(prefix):
|
|
|
|
subdir = subdir.replace(prefix, '')
|
|
|
|
return subdir
|
|
|
|
|
|
|
|
def generate_pkgconfig_file(self, state, deps, subdirs, name, description,
|
|
|
|
url, version, pcfile, conflicts, variables):
|
|
|
|
deps.remove_dups()
|
|
|
|
coredata = state.environment.get_coredata()
|
|
|
|
outdir = state.environment.scratch_dir
|
|
|
|
fname = os.path.join(outdir, pcfile)
|
|
|
|
prefix = PurePath(coredata.get_builtin_option('prefix'))
|
|
|
|
# These always return paths relative to prefix
|
|
|
|
libdir = PurePath(coredata.get_builtin_option('libdir'))
|
|
|
|
incdir = PurePath(coredata.get_builtin_option('includedir'))
|
|
|
|
with open(fname, 'w') as ofile:
|
|
|
|
ofile.write('prefix={}\n'.format(self._escape(prefix)))
|
|
|
|
ofile.write('libdir={}\n'.format(self._escape('${prefix}' / libdir)))
|
|
|
|
ofile.write('includedir={}\n'.format(self._escape('${prefix}' / incdir)))
|
|
|
|
if variables:
|
|
|
|
ofile.write('\n')
|
|
|
|
for k, v in variables:
|
|
|
|
ofile.write('{}={}\n'.format(k, self._escape(v)))
|
|
|
|
ofile.write('\n')
|
|
|
|
ofile.write('Name: %s\n' % name)
|
|
|
|
if len(description) > 0:
|
|
|
|
ofile.write('Description: %s\n' % description)
|
|
|
|
if len(url) > 0:
|
|
|
|
ofile.write('URL: %s\n' % url)
|
|
|
|
ofile.write('Version: %s\n' % version)
|
|
|
|
reqs_str = deps.format_reqs(deps.pub_reqs)
|
|
|
|
if len(reqs_str) > 0:
|
|
|
|
ofile.write('Requires: {}\n'.format(reqs_str))
|
|
|
|
reqs_str = deps.format_reqs(deps.priv_reqs)
|
|
|
|
if len(reqs_str) > 0:
|
|
|
|
ofile.write('Requires.private: {}\n'.format(reqs_str))
|
|
|
|
if len(conflicts) > 0:
|
|
|
|
ofile.write('Conflicts: {}\n'.format(' '.join(conflicts)))
|
|
|
|
|
|
|
|
def generate_libs_flags(libs):
|
|
|
|
msg = 'Library target {0!r} has {1!r} set. Compilers ' \
|
|
|
|
'may not find it from its \'-l{2}\' linker flag in the ' \
|
|
|
|
'{3!r} pkg-config file.'
|
|
|
|
Lflags = []
|
|
|
|
for l in libs:
|
|
|
|
if isinstance(l, str):
|
|
|
|
yield l
|
|
|
|
else:
|
Support multiple install dirs for built/custom targets
You can now pass a list of strings to the install_dir: kwarg to
build_target and custom_target.
Custom Targets:
===============
Allows you to specify the installation directory for each
corresponding output. For example:
custom_target('different-install-dirs',
output : ['first.file', 'second.file'],
...
install : true,
install_dir : ['somedir', 'otherdir])
This would install first.file to somedir and second.file to otherdir.
If only one install_dir is provided, all outputs are installed there
(same behaviour as before).
To only install some outputs, pass `false` for the outputs that you
don't want installed. For example:
custom_target('only-install-second',
output : ['first.file', 'second.file'],
...
install : true,
install_dir : [false, 'otherdir])
This would install second.file to otherdir and not install first.file.
Build Targets:
==============
With build_target() (which includes executable(), library(), etc),
usually there is only one primary output. However some types of
targets have multiple outputs.
For example, while generating Vala libraries, valac also generates
a header and a .vapi file both of which often need to be installed.
This allows you to specify installation directories for those too.
# This will only install the library (same as before)
shared_library('somevalalib', 'somesource.vala',
...
install : true)
# This will install the library, the header, and the vapi into the
# respective directories
shared_library('somevalalib', 'somesource.vala',
...
install : true,
install_dir : ['libdir', 'incdir', 'vapidir'])
# This will install the library into the default libdir and
# everything else into the specified directories
shared_library('somevalalib', 'somesource.vala',
...
install : true,
install_dir : [true, 'incdir', 'vapidir'])
# This will NOT install the library, and will install everything
# else into the specified directories
shared_library('somevalalib', 'somesource.vala',
...
install : true,
install_dir : [false, 'incdir', 'vapidir'])
true/false can also be used for secondary outputs in the same way.
Valac can also generate a GIR file for libraries when the `vala_gir:`
keyword argument is passed to library(). In that case, `install_dir:`
must be given a list with four elements, one for each output.
Includes tests for all these.
Closes https://github.com/mesonbuild/meson/issues/705
Closes https://github.com/mesonbuild/meson/issues/891
Closes https://github.com/mesonbuild/meson/issues/892
Closes https://github.com/mesonbuild/meson/issues/1178
Closes https://github.com/mesonbuild/meson/issues/1193
8 years ago
|
|
|
install_dir = l.get_custom_install_dir()[0]
|
|
|
|
if install_dir is False:
|
|
|
|
continue
|
|
|
|
if isinstance(install_dir, str):
|
|
|
|
Lflag = '-L${prefix}/%s ' % self._escape(self._make_relative(prefix, install_dir))
|
|
|
|
else: # install_dir is True
|
|
|
|
Lflag = '-L${libdir}'
|
|
|
|
if Lflag not in Lflags:
|
|
|
|
Lflags.append(Lflag)
|
|
|
|
yield Lflag
|
|
|
|
lname = self._get_lname(l, msg, pcfile)
|
|
|
|
# If using a custom suffix, the compiler may not be able to
|
|
|
|
# find the library
|
|
|
|
if l.name_suffix_set:
|
|
|
|
mlog.warning(msg.format(l.name, 'name_suffix', lname, pcfile))
|
|
|
|
yield '-l%s' % lname
|
|
|
|
|
|
|
|
if len(deps.pub_libs) > 0:
|
|
|
|
ofile.write('Libs: {}\n'.format(' '.join(generate_libs_flags(deps.pub_libs))))
|
|
|
|
if len(deps.priv_libs) > 0:
|
|
|
|
ofile.write('Libs.private: {}\n'.format(' '.join(generate_libs_flags(deps.priv_libs))))
|
|
|
|
ofile.write('Cflags:')
|
|
|
|
for h in subdirs:
|
|
|
|
ofile.write(' ')
|
|
|
|
if h == '.':
|
|
|
|
ofile.write('-I${includedir}')
|
|
|
|
else:
|
|
|
|
ofile.write(self._escape(PurePath('-I${includedir}') / h))
|
|
|
|
for f in deps.cflags:
|
|
|
|
ofile.write(' ')
|
|
|
|
ofile.write(self._escape(f))
|
|
|
|
ofile.write('\n')
|
|
|
|
|
|
|
|
@permittedKwargs({'libraries', 'version', 'name', 'description', 'filebase',
|
|
|
|
'subdirs', 'requires', 'requires_private', 'libraries_private',
|
|
|
|
'install_dir', 'extra_cflags', 'variables', 'url', 'd_module_versions'})
|
|
|
|
def generate(self, state, args, kwargs):
|
|
|
|
default_version = state.project_version['version']
|
|
|
|
default_install_dir = None
|
|
|
|
default_description = None
|
|
|
|
default_name = None
|
|
|
|
mainlib = None
|
|
|
|
if len(args) == 1:
|
|
|
|
mainlib = getattr(args[0], 'held_object', args[0])
|
|
|
|
if not isinstance(mainlib, (build.StaticLibrary, build.SharedLibrary)):
|
|
|
|
raise mesonlib.MesonException('Pkgconfig_gen first positional argument must be a library object')
|
|
|
|
default_name = mainlib.name
|
|
|
|
default_description = state.project_name + ': ' + mainlib.name
|
|
|
|
install_dir = mainlib.get_custom_install_dir()[0]
|
|
|
|
if isinstance(install_dir, str):
|
|
|
|
default_install_dir = os.path.join(install_dir, 'pkgconfig')
|
|
|
|
elif len(args) > 1:
|
|
|
|
raise mesonlib.MesonException('Too many positional arguments passed to Pkgconfig_gen.')
|
|
|
|
|
|
|
|
subdirs = mesonlib.stringlistify(kwargs.get('subdirs', ['.']))
|
|
|
|
version = kwargs.get('version', default_version)
|
|
|
|
if not isinstance(version, str):
|
|
|
|
raise mesonlib.MesonException('Version must be specified.')
|
|
|
|
name = kwargs.get('name', default_name)
|
|
|
|
if not isinstance(name, str):
|
|
|
|
raise mesonlib.MesonException('Name not specified.')
|
|
|
|
filebase = kwargs.get('filebase', name)
|
|
|
|
if not isinstance(filebase, str):
|
|
|
|
raise mesonlib.MesonException('Filebase must be a string.')
|
|
|
|
description = kwargs.get('description', default_description)
|
|
|
|
if not isinstance(description, str):
|
|
|
|
raise mesonlib.MesonException('Description is not a string.')
|
|
|
|
url = kwargs.get('url', '')
|
|
|
|
if not isinstance(url, str):
|
|
|
|
raise mesonlib.MesonException('URL is not a string.')
|
|
|
|
conflicts = mesonlib.stringlistify(kwargs.get('conflicts', []))
|
|
|
|
|
|
|
|
deps = DependenciesHelper(filebase)
|
|
|
|
if mainlib:
|
|
|
|
deps.add_pub_libs(mainlib)
|
|
|
|
deps.add_pub_libs(kwargs.get('libraries', []))
|
|
|
|
deps.add_priv_libs(kwargs.get('libraries_private', []))
|
|
|
|
deps.add_pub_reqs(kwargs.get('requires', []))
|
|
|
|
deps.add_priv_reqs(kwargs.get('requires_private', []))
|
|
|
|
deps.add_cflags(kwargs.get('extra_cflags', []))
|
|
|
|
|
|
|
|
dversions = kwargs.get('d_module_versions', None)
|
|
|
|
if dversions:
|
|
|
|
compiler = state.environment.coredata.compilers.get('d')
|
|
|
|
if compiler:
|
|
|
|
deps.add_cflags(compiler.get_feature_args({'versions': dversions}, None))
|
|
|
|
|
|
|
|
def parse_variable_list(stringlist):
|
|
|
|
reserved = ['prefix', 'libdir', 'includedir']
|
|
|
|
variables = []
|
|
|
|
for var in stringlist:
|
|
|
|
# foo=bar=baz is ('foo', 'bar=baz')
|
|
|
|
l = var.split('=', 1)
|
|
|
|
if len(l) < 2:
|
|
|
|
raise mesonlib.MesonException('Invalid variable "{}". Variables must be in \'name=value\' format'.format(var))
|
|
|
|
|
|
|
|
name, value = l[0].strip(), l[1].strip()
|
|
|
|
if not name or not value:
|
|
|
|
raise mesonlib.MesonException('Invalid variable "{}". Variables must be in \'name=value\' format'.format(var))
|
|
|
|
|
|
|
|
# Variable names must not contain whitespaces
|
|
|
|
if any(c.isspace() for c in name):
|
|
|
|
raise mesonlib.MesonException('Invalid whitespace in assignment "{}"'.format(var))
|
|
|
|
|
|
|
|
if name in reserved:
|
|
|
|
raise mesonlib.MesonException('Variable "{}" is reserved'.format(name))
|
|
|
|
|
|
|
|
variables.append((name, value))
|
|
|
|
|
|
|
|
return variables
|
|
|
|
|
|
|
|
variables = parse_variable_list(mesonlib.stringlistify(kwargs.get('variables', [])))
|
|
|
|
|
|
|
|
pcfile = filebase + '.pc'
|
|
|
|
pkgroot = kwargs.get('install_dir', default_install_dir)
|
|
|
|
if pkgroot is None:
|
|
|
|
pkgroot = os.path.join(state.environment.coredata.get_builtin_option('libdir'), 'pkgconfig')
|
|
|
|
if not isinstance(pkgroot, str):
|
|
|
|
raise mesonlib.MesonException('Install_dir must be a string.')
|
|
|
|
self.generate_pkgconfig_file(state, deps, subdirs, name, description, url,
|
|
|
|
version, pcfile, conflicts, variables)
|
|
|
|
res = build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), pcfile), pkgroot)
|
|
|
|
return ModuleReturnValue(res, [res])
|
|
|
|
|
|
|
|
def initialize():
|
|
|
|
return PkgConfigModule()
|