aboutsummaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-04-01 01:29:51 +0300
committerGitHub <noreply@github.com>2019-04-01 01:29:51 +0300
commit5905533fcd7fb9663023e6cf98d95667620d2f12 (patch)
tree49ed83ebd7c34cfe1a676ac9607c609283349db3 /test cases
parente3e83e2acdec877c527b36542fc64867c5943f77 (diff)
parent2259db2683d9e60c727ce847d1da7a759b190006 (diff)
downloadmeson-5905533fcd7fb9663023e6cf98d95667620d2f12.zip
meson-5905533fcd7fb9663023e6cf98d95667620d2f12.tar.gz
meson-5905533fcd7fb9663023e6cf98d95667620d2f12.tar.bz2
Merge pull request #5103 from mesonbuild/linkcustom
Can link against custom targets
Diffstat (limited to 'test cases')
-rwxr-xr-xtest cases/common/216 link custom/custom_stlib.py73
-rw-r--r--test cases/common/216 link custom/meson.build35
-rw-r--r--test cases/common/216 link custom/prog.c6
-rw-r--r--test cases/failing/89 link_with custom target/demo.c5
-rw-r--r--test cases/failing/89 link_with custom target/foo.c3
-rwxr-xr-xtest cases/failing/89 link_with custom target/lib_generator.py24
-rw-r--r--test cases/failing/89 link_with custom target/meson.build23
7 files changed, 114 insertions, 55 deletions
diff --git a/test cases/common/216 link custom/custom_stlib.py b/test cases/common/216 link custom/custom_stlib.py
new file mode 100755
index 0000000..80334ed
--- /dev/null
+++ b/test cases/common/216 link custom/custom_stlib.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+
+import shutil, sys, subprocess, argparse, pathlib
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument('--private-dir', required=True)
+parser.add_argument('-o', required=True)
+parser.add_argument('cmparr', nargs='+')
+
+contents = '''#include<stdio.h>
+
+void flob() {
+ printf("Now flobbing.\\n");
+}
+'''
+
+def generate_lib_gnulike(outfile, c_file, private_dir, compiler_array):
+ if shutil.which('ar'):
+ static_linker = 'ar'
+ elif shutil.which('llvm-ar'):
+ static_linker = 'llvm-ar'
+ elif shutil.which('gcc-ar'):
+ static_linker = 'gcc-ar'
+ else:
+ sys.exit('Could not detect a static linker.')
+ o_file = c_file.with_suffix('.o')
+ compile_cmd = compiler_array + ['-c', '-g', '-O2', '-o', str(o_file), str(c_file)]
+ subprocess.check_call(compile_cmd)
+ out_file = pathlib.Path(outfile)
+ if out_file.exists():
+ out_file.unlink()
+ link_cmd = [static_linker, 'csr', outfile, str(o_file)]
+ subprocess.check_call(link_cmd)
+ return 0
+
+
+def generate_lib_msvc(outfile, c_file, private_dir, compiler_array):
+ static_linker = 'lib'
+ o_file = c_file.with_suffix('.obj')
+ compile_cmd = compiler_array + ['/MDd',
+ '/nologo',
+ '/ZI',
+ '/Ob0',
+ '/Od',
+ '/c',
+ '/Fo' + str(o_file),
+ str(c_file)]
+ subprocess.check_call(compile_cmd)
+ out_file = pathlib.Path(outfile)
+ if out_file.exists():
+ out_file.unlink()
+ link_cmd = [static_linker,
+ '/nologo',
+ '/OUT:' + str(outfile),
+ str(o_file)]
+ subprocess.check_call(link_cmd)
+ return 0
+
+def generate_lib(outfile, private_dir, compiler_array):
+ private_dir = pathlib.Path(private_dir)
+ if not private_dir.exists():
+ private_dir.mkdir()
+ c_file = private_dir / 'flob.c'
+ c_file.write_text(contents)
+ for i in compiler_array:
+ if (i.endswith('cl') or i.endswith('cl.exe')) and 'clang-cl' not in i:
+ return generate_lib_msvc(outfile, c_file, private_dir, compiler_array)
+ return generate_lib_gnulike(outfile, c_file, private_dir, compiler_array)
+
+if __name__ == '__main__':
+ options = parser.parse_args()
+ sys.exit(generate_lib(options.o, options.private_dir, options.cmparr))
diff --git a/test cases/common/216 link custom/meson.build b/test cases/common/216 link custom/meson.build
new file mode 100644
index 0000000..5af27cd
--- /dev/null
+++ b/test cases/common/216 link custom/meson.build
@@ -0,0 +1,35 @@
+project('linkcustom', 'c')
+
+# This would require passing the static linker to the build script or having
+# it detect it by itself. I'm too lazy to implement it now and it is not
+# really needed for testing that custom targets work. It is the responsibility
+# of the custom target to produce things in the correct format.
+assert(not meson.is_cross_build(),
+ 'MESON_SKIP_TEST cross checking not implemented.')
+
+cc = meson.get_compiler('c')
+genprog = find_program('custom_stlib.py')
+
+clib = custom_target('linkcustom',
+ output: 'libflob.a',
+ command: [genprog,
+ '-o', '@OUTPUT@',
+ '--private-dir', '@PRIVATE_DIR@'] + cc.cmd_array())
+
+exe = executable('prog', 'prog.c', link_with: clib)
+test('linkcustom', exe)
+
+d = declare_dependency(link_with: clib)
+
+exe2 = executable('prog2', 'prog.c', dependencies: d)
+test('linkcustom2', exe2)
+
+# Link whole tests
+
+exe3 = executable('prog3', 'prog.c', link_whole: clib)
+test('linkwhole', exe)
+
+d2 = declare_dependency(link_whole: clib)
+
+exe4 = executable('prog4', 'prog.c', dependencies: d2)
+test('linkwhole2', exe2)
diff --git a/test cases/common/216 link custom/prog.c b/test cases/common/216 link custom/prog.c
new file mode 100644
index 0000000..eaede6d
--- /dev/null
+++ b/test cases/common/216 link custom/prog.c
@@ -0,0 +1,6 @@
+void flob();
+
+int main(int argc, char **argv) {
+ flob();
+ return 0;
+}
diff --git a/test cases/failing/89 link_with custom target/demo.c b/test cases/failing/89 link_with custom target/demo.c
deleted file mode 100644
index b6feaca..0000000
--- a/test cases/failing/89 link_with custom target/demo.c
+++ /dev/null
@@ -1,5 +0,0 @@
-int func_in_foo();
-
-int main(int argc, char **argv) {
- return func_in_foo();
-}
diff --git a/test cases/failing/89 link_with custom target/foo.c b/test cases/failing/89 link_with custom target/foo.c
deleted file mode 100644
index 2c71422..0000000
--- a/test cases/failing/89 link_with custom target/foo.c
+++ /dev/null
@@ -1,3 +0,0 @@
-int func_in_foo() {
- return 0;
-}
diff --git a/test cases/failing/89 link_with custom target/lib_generator.py b/test cases/failing/89 link_with custom target/lib_generator.py
deleted file mode 100755
index 98ed5a8..0000000
--- a/test cases/failing/89 link_with custom target/lib_generator.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python3
-
-# Mimic a binary that generates a static library
-
-import os
-import subprocess
-import sys
-
-if __name__ == '__main__':
- if len(sys.argv) != 4:
- print(sys.argv[0], 'compiler input_file output_file')
- sys.exit(1)
- compiler = sys.argv[1]
- ifile = sys.argv[2]
- ofile = sys.argv[3]
- tmp = ifile + '.o'
- if compiler.endswith('cl'):
- subprocess.check_call([compiler, '/nologo', '/MDd', '/Fo' + tmp, '/c', ifile])
- subprocess.check_call(['lib', '/nologo', '/OUT:' + ofile, tmp])
- else:
- subprocess.check_call([compiler, '-c', ifile, '-o', tmp])
- subprocess.check_call(['ar', 'csr', ofile, tmp])
-
-os.unlink(tmp)
diff --git a/test cases/failing/89 link_with custom target/meson.build b/test cases/failing/89 link_with custom target/meson.build
deleted file mode 100644
index 6977ca1..0000000
--- a/test cases/failing/89 link_with custom target/meson.build
+++ /dev/null
@@ -1,23 +0,0 @@
-project('link_with custom target', ['c'])
-
-#
-# libraries created by a custom_target currently can be used in sources: (see
-# common/100 manygen/ for an example of that), but not in link_with:
-#
-
-lib_generator = find_program('lib_generator.py')
-
-cc = meson.get_compiler('c').cmd_array().get(-1)
-
-libfoo_target = custom_target(
- 'libfoo',
- input: ['foo.c'],
- output: ['libfoo.a'],
- command: [lib_generator, cc, '@INPUT@', '@OUTPUT@']
-)
-
-libfoo = declare_dependency(
- link_with: libfoo_target,
-)
-
-executable('demo', ['demo.c'], dependencies: [libfoo])