aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2021-05-01 15:15:00 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2021-05-02 22:27:40 +0300
commitd0325c898ad7f16dc9e22389d365a33097b80af8 (patch)
tree8793b3436654f12c56b98ca268df40dfd55f6856 /mesonbuild/compilers
parent9bbf2dd07c1adbb3fd129d1fac824c369d3286cf (diff)
downloadmeson-d0325c898ad7f16dc9e22389d365a33097b80af8.zip
meson-d0325c898ad7f16dc9e22389d365a33097b80af8.tar.gz
meson-d0325c898ad7f16dc9e22389d365a33097b80af8.tar.bz2
Use sanity_check_impl for objc/objpp
This gets rid of compile warnings, and simplifies the code. Note that `work_dir` in sanity_check_impl was incorrect, it was used both to prepend to file names and as cwd=work_dir argument to Popen. This is fixed here. Closes gh-7344
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/mixins/clike.py2
-rw-r--r--mesonbuild/compilers/objc.py25
-rw-r--r--mesonbuild/compilers/objcpp.py26
3 files changed, 5 insertions, 48 deletions
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index 70dde60..0637439 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -313,7 +313,7 @@ class CLikeCompiler(Compiler):
# Compile sanity check
# NOTE: extra_flags must be added at the end. On MSVC, it might contain a '/link' argument
# after which all further arguments will be passed directly to the linker
- cmdlist = self.exelist + [source_name] + self.get_output_args(binary_name) + extra_flags
+ cmdlist = self.exelist + [sname] + self.get_output_args(binname) + extra_flags
pc, stdo, stde = mesonlib.Popen_safe(cmdlist, cwd=work_dir)
mlog.debug('Sanity check compiler command line:', ' '.join(cmdlist))
mlog.debug('Sanity check compile stdout:')
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index ce9cf2d..7d19e52 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -48,29 +48,8 @@ class ObjCCompiler(CLikeCompiler, Compiler):
return 'Objective-C'
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- # TODO try to use sanity_check_impl instead of duplicated code
- source_name = os.path.join(work_dir, 'sanitycheckobjc.m')
- binary_name = os.path.join(work_dir, 'sanitycheckobjc')
- extra_flags: T.List[str] = []
- extra_flags += environment.coredata.get_external_args(self.for_machine, self.language)
- if self.is_cross:
- extra_flags += self.get_compile_only_args()
- else:
- extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
- with open(source_name, 'w') as ofile:
- ofile.write('#import<stddef.h>\n'
- 'int main(void) { return 0; }\n')
- pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
- pc.wait()
- if pc.returncode != 0:
- raise EnvironmentException('ObjC compiler %s can not compile programs.' % self.name_string())
- if self.is_cross:
- # Can't check if the binaries run so we have to assume they do
- return
- pe = subprocess.Popen(binary_name)
- pe.wait()
- if pe.returncode != 0:
- raise EnvironmentException('Executables created by ObjC compiler %s are not runnable.' % self.name_string())
+ code = '#import<stddef.h>\nint main(void) { return 0; }\n'
+ return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjc.m', code)
class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index 585a45e..fdd9762 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -47,30 +47,8 @@ class ObjCPPCompiler(CLikeCompiler, Compiler):
return 'Objective-C++'
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- # TODO try to use sanity_check_impl instead of duplicated code
- source_name = os.path.join(work_dir, 'sanitycheckobjcpp.mm')
- binary_name = os.path.join(work_dir, 'sanitycheckobjcpp')
- extra_flags: T.List[str] = []
- extra_flags += environment.coredata.get_external_args(self.for_machine, self.language)
- if self.is_cross:
- extra_flags += self.get_compile_only_args()
- else:
- extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
- with open(source_name, 'w') as ofile:
- ofile.write('#import<stdio.h>\n'
- 'class MyClass;'
- 'int main(void) { return 0; }\n')
- pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
- pc.wait()
- if pc.returncode != 0:
- raise EnvironmentException('ObjC++ compiler %s can not compile programs.' % self.name_string())
- if self.is_cross:
- # Can't check if the binaries run so we have to assume they do
- return
- pe = subprocess.Popen(binary_name)
- pe.wait()
- if pe.returncode != 0:
- raise EnvironmentException('Executables created by ObjC++ compiler %s are not runnable.' % self.name_string())
+ code = '#import<stdio.h>\nclass MyClass;int main(void) { return 0; }\n'
+ return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjcpp.mm', code)
class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):