aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemi Thebault <remi.thebault@gmail.com>2020-12-29 18:56:35 +0100
committerGitHub <noreply@github.com>2020-12-29 09:56:35 -0800
commit7a9a9e4a99f107b4bc36b276d6e51f7e3f6e1a69 (patch)
treed89abb2327608d269f3d67dcd2e5dea44cbb8081
parent12cfd10e6a3638195b4c69c1b251327e338964cb (diff)
downloadmeson-7a9a9e4a99f107b4bc36b276d6e51f7e3f6e1a69.zip
meson-7a9a9e4a99f107b4bc36b276d6e51f7e3f6e1a69.tar.gz
meson-7a9a9e4a99f107b4bc36b276d6e51f7e3f6e1a69.tar.bz2
Implement support of dlang -makedeps switch (#8119)
* Implement support of dlang -makedeps switch Fix #8118 * resolve code review comments
-rw-r--r--mesonbuild/compilers/d.py33
-rw-r--r--mesonbuild/environment.py2
2 files changed, 32 insertions, 3 deletions
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 95850ea..ca6de38 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os.path, subprocess
+import os.path
+import re
+import subprocess
import typing as T
from ..mesonlib import (
@@ -80,6 +82,13 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
sharing between them as makes sense.
"""
+ def __init__(self, dmd_frontend_version: T.Optional[str]):
+ if dmd_frontend_version is None:
+ self._dmd_has_depfile = False
+ else:
+ # -makedeps switch introduced in 2.095 frontend
+ self._dmd_has_depfile = version_compare(dmd_frontend_version, ">=2.095.0")
+
if T.TYPE_CHECKING:
mscrt_args = {} # type: T.Dict[str, T.List[str]]
@@ -131,6 +140,11 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
def get_depfile_suffix(self) -> str:
return 'deps'
+ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
+ if self._dmd_has_depfile:
+ return [f'-makedeps={outfile}']
+ return []
+
def get_pic_args(self) -> T.List[str]:
if self.info.is_windows():
return []
@@ -683,6 +697,19 @@ class GnuDCompiler(GnuCompiler, DCompiler):
def get_disable_assert_args(self) -> T.List[str]:
return ['-frelease']
+# LDC uses the DMD frontend code to parse and analyse the code.
+# It then uses LLVM for the binary code generation and optimizations.
+# This function retrieves the dmd frontend version, which determines
+# the common features between LDC and DMD.
+# We need the complete version text because the match is not on first line
+# of version_output
+def find_ldc_dmd_frontend_version(version_output: T.Optional[str]) -> T.Optional[str]:
+ if version_output is None:
+ return None
+ version_regex = re.search(r'DMD v(\d+\.\d+\.\d+)', version_output)
+ if version_regex:
+ return version_regex.group(1)
+ return None
class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
@@ -691,10 +718,11 @@ class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None,
- is_cross: bool = False):
+ is_cross: bool = False, version_output: T.Optional[str] = None):
DCompiler.__init__(self, exelist, version, for_machine, info, arch,
exe_wrapper=exe_wrapper, linker=linker,
full_version=full_version, is_cross=is_cross)
+ DmdLikeCompilerMixin.__init__(self, dmd_frontend_version=find_ldc_dmd_frontend_version(version_output))
self.id = 'llvm'
self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']
@@ -752,6 +780,7 @@ class DmdDCompiler(DmdLikeCompilerMixin, DCompiler):
DCompiler.__init__(self, exelist, version, for_machine, info, arch,
exe_wrapper=exe_wrapper, linker=linker,
full_version=full_version, is_cross=is_cross)
+ DmdLikeCompilerMixin.__init__(self, version)
self.id = 'dmd'
self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index f7e7003..74d8bde 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -1798,7 +1798,7 @@ class Environment:
return compilers.LLVMDCompiler(
exelist, version, for_machine, info, arch,
- full_version=full_version, linker=linker)
+ full_version=full_version, linker=linker, version_output=out)
elif 'gdc' in out:
linker = self._guess_nix_linker(exelist, compilers.GnuDCompiler, for_machine)
return compilers.GnuDCompiler(