diff options
author | Alistair Thomas <astavale@yahoo.co.uk> | 2017-06-21 19:02:29 +0100 |
---|---|---|
committer | Alistair Thomas <astavale@yahoo.co.uk> | 2017-06-22 20:09:58 +0100 |
commit | e5559903b3857a333c6cbc88b44d6759c293e5df (patch) | |
tree | 140a008acba1b48631836456678bc1926babb684 | |
parent | 080307dd71d9b41a103369863137ed5b73eb131a (diff) | |
download | meson-e5559903b3857a333c6cbc88b44d6759c293e5df.zip meson-e5559903b3857a333c6cbc88b44d6759c293e5df.tar.gz meson-e5559903b3857a333c6cbc88b44d6759c293e5df.tar.bz2 |
Split linkers out from compilers.py
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 16 | ||||
-rw-r--r-- | mesonbuild/compilers.py | 110 | ||||
-rw-r--r-- | mesonbuild/environment.py | 8 | ||||
-rw-r--r-- | mesonbuild/linkers.py | 114 | ||||
-rwxr-xr-x | run_unittests.py | 6 |
5 files changed, 133 insertions, 121 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 761d508..0c3525c 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1,4 +1,4 @@ -# Copyright 2012-2016 The Meson development team +# Copyright 2012-2017 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. @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import shlex -import os, sys, pickle, re -import subprocess, shutil +import os, pickle, re, shlex, shutil, subprocess, sys from collections import OrderedDict from . import backends @@ -25,6 +23,7 @@ from .. import mlog from .. import dependencies from .. import compilers from ..compilers import CompilerArgs +from ..linkers import ArLinker from ..mesonlib import File, MesonException, OrderedSet from ..mesonlib import get_meson_script, get_compiler_for_source from .backends import CleanTrees, InstallData @@ -1363,7 +1362,7 @@ int dummy; # gcc-ar blindly pass the --plugin argument to `ar` and you cannot pass # options as arguments while using the @file.rsp syntax. # See: https://github.com/mesonbuild/meson/issues/1646 - if mesonlib.is_windows() and not isinstance(static_linker, compilers.ArLinker): + if mesonlib.is_windows() and not isinstance(static_linker, ArLinker): command_template = ''' command = {executable} @$out.rsp rspfile = $out.rsp rspfile_content = $LINK_ARGS {output_args} $in @@ -1375,7 +1374,7 @@ int dummy; # them out to fix this properly on Windows. See: # https://github.com/mesonbuild/meson/issues/1517 # https://github.com/mesonbuild/meson/issues/1526 - if isinstance(static_linker, compilers.ArLinker) and not mesonlib.is_windows(): + if isinstance(static_linker, ArLinker) and not mesonlib.is_windows(): # `ar` has no options to overwrite archives. It always appends, # which is never what we want. Delete an existing library first if # it exists. https://github.com/mesonbuild/meson/issues/1355 @@ -2361,8 +2360,9 @@ rule FORTRAN_DEP_HACK # Target names really should not have slashes in them, but # unfortunately we did not check for that and some downstream projects # now have them. Once slashes are forbidden, remove this bit. - target_slashname_workaround_dir = os.path.join(os.path.split(target.name)[0], - self.get_target_dir(target)) + target_slashname_workaround_dir = os.path.join( + os.path.split(target.name)[0], + self.get_target_dir(target)) else: target_slashname_workaround_dir = self.get_target_dir(target) commands += linker.build_rpath_args(self.environment.get_build_dir(), diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 979a5ac..a1b2af7 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1,4 +1,4 @@ -# Copyright 2012-2014 The Meson development team +# Copyright 2012-2017 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. @@ -12,15 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import re -import shutil -import contextlib -import subprocess, os.path -import tempfile -from .import mesonlib +import contextlib, os.path, re, shutil, subprocess, tempfile + +from .linkers import StaticLinker +from . import coredata from . import mlog +from . import mesonlib from .mesonlib import EnvironmentException, MesonException, version_compare, Popen_safe -from . import coredata """This file contains the data files of all compilers Meson knows about. To support a new compiler, add its information below. @@ -3213,99 +3211,3 @@ class NAGFortranCompiler(FortranCompiler): def get_warn_args(self, level): return NAGFortranCompiler.std_warn_args - -class StaticLinker: - pass - -class VisualStudioLinker(StaticLinker): - always_args = ['/NOLOGO'] - - def __init__(self, exelist): - self.exelist = exelist - - def get_exelist(self): - return self.exelist[:] - - def get_std_link_args(self): - return [] - - def get_buildtype_linker_args(self, buildtype): - return [] - - def get_output_args(self, target): - return ['/OUT:' + target] - - def get_coverage_link_args(self): - return [] - - def get_always_args(self): - return VisualStudioLinker.always_args - - def get_linker_always_args(self): - return VisualStudioLinker.always_args - - def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath): - return [] - - def thread_link_flags(self): - return [] - - def get_option_link_args(self, options): - return [] - - @classmethod - def unix_args_to_native(cls, args): - return VisualStudioCCompiler.unix_args_to_native(args) - - def get_link_debugfile_args(self, targetfile): - # Static libraries do not have PDB files - return [] - -class ArLinker(StaticLinker): - - def __init__(self, exelist): - self.exelist = exelist - self.id = 'ar' - pc, stdo = Popen_safe(self.exelist + ['-h'])[0:2] - # Enable deterministic builds if they are available. - if '[D]' in stdo: - self.std_args = ['csrD'] - else: - self.std_args = ['csr'] - - def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath): - return [] - - def get_exelist(self): - return self.exelist[:] - - def get_std_link_args(self): - return self.std_args - - def get_output_args(self, target): - return [target] - - def get_buildtype_linker_args(self, buildtype): - return [] - - def get_linker_always_args(self): - return [] - - def get_coverage_link_args(self): - return [] - - def get_always_args(self): - return [] - - def thread_link_flags(self): - return [] - - def get_option_link_args(self, options): - return [] - - @classmethod - def unix_args_to_native(cls, args): - return args[:] - - def get_link_debugfile_args(self, targetfile): - return [] diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index d21c6cc..d06436b 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -12,15 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os -import platform -import re +import configparser, os, platform, re, shlex, shutil from .compilers import * +from .linkers import ArLinker, VisualStudioLinker from .mesonlib import EnvironmentException, Popen_safe -import configparser -import shlex -import shutil build_filename = 'meson.build' diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py new file mode 100644 index 0000000..d0d5184 --- /dev/null +++ b/mesonbuild/linkers.py @@ -0,0 +1,114 @@ +# Copyright 2012-2017 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. + +from .mesonlib import Popen_safe + +class StaticLinker: + pass + + +class VisualStudioLinker(StaticLinker): + always_args = ['/NOLOGO'] + + def __init__(self, exelist): + self.exelist = exelist + + def get_exelist(self): + return self.exelist[:] + + def get_std_link_args(self): + return [] + + def get_buildtype_linker_args(self, buildtype): + return [] + + def get_output_args(self, target): + return ['/OUT:' + target] + + def get_coverage_link_args(self): + return [] + + def get_always_args(self): + return VisualStudioLinker.always_args + + def get_linker_always_args(self): + return VisualStudioLinker.always_args + + def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath): + return [] + + def thread_link_flags(self): + return [] + + def get_option_link_args(self, options): + return [] + + @classmethod + def unix_args_to_native(cls, args): + from .compilers import VisualStudioCCompiler + return VisualStudioCCompiler.unix_args_to_native(args) + + def get_link_debugfile_args(self, targetfile): + # Static libraries do not have PDB files + return [] + + +class ArLinker(StaticLinker): + + def __init__(self, exelist): + self.exelist = exelist + self.id = 'ar' + pc, stdo = Popen_safe(self.exelist + ['-h'])[0:2] + # Enable deterministic builds if they are available. + if '[D]' in stdo: + self.std_args = ['csrD'] + else: + self.std_args = ['csr'] + + def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath): + return [] + + def get_exelist(self): + return self.exelist[:] + + def get_std_link_args(self): + return self.std_args + + def get_output_args(self, target): + return [target] + + def get_buildtype_linker_args(self, buildtype): + return [] + + def get_linker_always_args(self): + return [] + + def get_coverage_link_args(self): + return [] + + def get_always_args(self): + return [] + + def thread_link_flags(self): + return [] + + def get_option_link_args(self, options): + return [] + + @classmethod + def unix_args_to_native(cls, args): + return args[:] + + def get_link_debugfile_args(self, targetfile): + return [] diff --git a/run_unittests.py b/run_unittests.py index 63462d8..93a43ae 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -701,7 +701,7 @@ class AllPlatformTests(BasePlatformTests): static_linker = env.detect_static_linker(cc) if is_windows(): raise unittest.SkipTest('https://github.com/mesonbuild/meson/issues/1526') - if not isinstance(static_linker, mesonbuild.compilers.ArLinker): + if not isinstance(static_linker, mesonbuild.linkers.ArLinker): raise unittest.SkipTest('static linker is not `ar`') # Configure self.init(testdir) @@ -936,8 +936,8 @@ class AllPlatformTests(BasePlatformTests): clang = mesonbuild.compilers.ClangCompiler intel = mesonbuild.compilers.IntelCompiler msvc = mesonbuild.compilers.VisualStudioCCompiler - ar = mesonbuild.compilers.ArLinker - lib = mesonbuild.compilers.VisualStudioLinker + ar = mesonbuild.linkers.ArLinker + lib = mesonbuild.linkers.VisualStudioLinker langs = [('c', 'CC'), ('cpp', 'CXX')] if not is_windows(): langs += [('objc', 'OBJC'), ('objcpp', 'OBJCXX')] |