Merge branch 'master' into perf/env-setitem
[scons.git] / test / D / SharedObjects / Common / common.py
blobe9611a1d272e202e6d1d70d6d4fc85a49c28fe58
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 """
24 Support functions for all the tests.
25 """
28 import TestSCons
30 from SCons.Environment import Base
32 import re
33 import subprocess
34 from os.path import abspath, dirname
36 import sys
37 sys.path.insert(1, abspath(dirname(__file__) + '/../../Support'))
39 from executablesSearch import isExecutableOfToolAvailable
41 def testForTool(tool):
43 test = TestSCons.TestSCons()
45 if not isExecutableOfToolAvailable(test, tool) :
46 test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
48 if tool == 'gdc':
49 cp = subprocess.run(('gdc', '--version'), stdout=subprocess.PIPE)
50 # different version strings possible, i.e.:
51 # gdc (GCC) 11.1.1 20210531 (Red Hat 11.1.1-3)\nCopyright (C)...
52 # gdc (Ubuntu 10.2.0-5ubuntu1~20.04) 10.20.0\nCopyright (C)...
53 vstr = cp.stdout.decode().splitlines()[0]
54 match = re.search(r'[0-9]+(\.[0-9]+)+', vstr)
55 if match:
56 version = match.group(0)
57 major, minor, debug = (int(x) for x in version.split('.'))
58 else:
59 major = 0
60 if (major < 6) or (major == 6 and minor < 3):
61 test.skip_test('gdc prior to version 6.0.0 does not support shared libraries.\n')
63 if tool == 'dmd' and Base()['DC'] == 'gdmd':
64 test.skip_test('gdmd does not recognize the -shared option so cannot support linking of shared objects.\n')
66 code_root = 'code'
67 library_root = 'answer'
69 platform = Base()['PLATFORM']
70 if platform == 'posix':
71 code_name = code_root + '.o'
72 library_name = 'lib' + library_root + '.so'
73 elif platform == 'darwin':
74 code_name = code_root + '.o'
75 library_name = 'lib' + library_root + '.dylib'
76 # As at 2017-08-22, DMD 2.075.1, LDC 1.2.0 (D 2.072.2), and GDC 7.2.0 (D 2.068.2)
77 # it is not clear if shared libraries are supported on macOS.
78 # test.skip_test('Dynamic libraries not yet supported on macOS.\n')
79 elif platform == 'win32':
80 code_name = code_root + '.obj'
81 library_name = library_root + '.dll'
82 else:
83 test.fail_test()
85 test.dir_fixture('Image')
86 with open('SConstruct_template') as f:
87 config = f.read().format(tool)
88 test.write('SConstruct', config)
90 if Base()['DC'] == 'gdmd':
91 # The gdmd executable in Debian Unstable as at 2012-05-12, version 4.6.3 puts out messages on stderr
92 # that cause inappropriate failure of the tests, so simply ignore them.
93 test.run(stderr=None)
94 else:
95 test.run()
97 test.must_exist(test.workpath(code_name))
98 test.must_exist(test.workpath(library_name))
101 test.pass_test()
103 # Local Variables:
104 # tab-width:4
105 # indent-tabs-mode:nil
106 # End:
107 # vim: set expandtab tabstop=4 shiftwidth=4: