1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 This file is part of the LibreOffice project.
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
20 # these contortions seem unavoidable for windows
21 def getgbuildtesttools(testcase
):
22 with
open(os
.path
.join(os
.environ
['WORKDIR'], 'CustomTarget', 'solenv', 'gbuildtesttools.done'), 'r') as f
:
23 gbuildtesttools
= json
.load(f
)
24 testcase
.make
= gbuildtesttools
['MAKE']
25 testcase
.bash
= gbuildtesttools
['BASH']
26 testcase
.gbuildtojson
= gbuildtesttools
['GBUILDTOJSON']
28 makeenvvars
= ['MAKEOVERRIDES', 'MAKEFLAGS', 'MAKE_TERMERR', 'MAKE_TERMOUT', 'MAKELEVEL', 'MFLAGS', 'GBUILD_TRACE']
30 if 'LD_LIBRARY_PATH' in os
.environ
:
31 os
.environ
['GBUILDTOJSON_LD_LIBRARY_PATH'] = os
.environ
['LD_LIBRARY_PATH']
32 del(os
.environ
['LD_LIBRARY_PATH']) # built with ASAN; prevent that
33 for makeenvvar
in makeenvvars
:
34 if makeenvvar
in os
.environ
:
35 del os
.environ
[makeenvvar
]
38 class CheckGbuildToJson(unittest
.TestCase
):
40 getgbuildtesttools(self
)
42 self
.tempwork
= tempfile
.mkdtemp(prefix
='gbuild')
45 shutil
.rmtree(self
.tempwork
)
47 def test_gbuildtojson(self
):
48 os
.makedirs(os
.path
.join(self
.tempwork
, 'LinkTarget', 'Executable'))
49 shutil
.copy(self
.gbuildtojson
, os
.path
.join(self
.tempwork
, 'LinkTarget', 'Executable'))
50 (bashscripthandle
, bashscriptname
) = tempfile
.mkstemp('gbuild')
51 bashscript
= os
.fdopen(bashscripthandle
, 'w', newline
='\n')
52 bashscript
.write("set -e\n")
53 bashscript
.write("cd %s/solenv/qa/python/selftest\n" % os
.environ
['SRCDIR'])
54 bashscript
.write("%s gbuildtojson WORKDIR=%s\n" % (self
.make
, self
.tempwork
.replace('\\', '/')))
56 subprocess
.check_call([self
.bash
, bashscriptname
.replace('\\', '/')])
57 os
.remove(bashscriptname
)
58 jsonfiles
= os
.listdir(os
.path
.join(self
.tempwork
, 'GbuildToJson', 'Library'))
60 for jsonfilename
in jsonfiles
:
61 with
open(os
.path
.join(self
.tempwork
, 'GbuildToJson', 'Library', jsonfilename
), 'r') as f
:
62 gbuildlibs
.append(json
.load(f
))
64 for lib
in gbuildlibs
:
65 self
.assertEqual(set(lib
.keys()), set(['MAKEFILE', 'ASMOBJECTS', 'CFLAGS', 'CFLAGSAPPEND', 'COBJECTS', 'CXXCLRFLAGS', 'CXXCLRFLAGSAPPEND', 'CXXCLROBJECTS', 'CXXFLAGS', 'CXXFLAGSAPPEND', 'CXXOBJECTS', 'DEFS', 'LEXOBJECTS', 'GENCOBJECTS', 'GENCXXOBJECTS', 'GENCXXCLROBJECTS', 'ILIBTARGET', 'INCLUDE', 'JAVAOBJECTS', 'LINKED_LIBS', 'LINKED_STATIC_LIBS', 'LINKTARGET', 'OBJCFLAGS', 'OBJCFLAGSAPPEND', 'OBJCOBJECTS', 'OBJCXXFLAGS', 'OBJCXXFLAGSAPPEND', 'OBJCXXOBJECTS', 'PYTHONOBJECTS', 'YACCOBJECTS']))
66 if lib
['LINKTARGET'].find('gbuildselftestdep') != -1:
67 foundlibs
.add('gbuildselftestdep')
68 elif lib
['LINKTARGET'].find('gbuildselftest') != -1:
69 foundlibs
.add('gbuildselftest')
70 self
.assertIn('-Igbuildtojsontestinclude', lib
['INCLUDE'].split())
71 self
.assertIn('gbuildselftestdep', lib
['LINKED_LIBS'].split())
72 self
.assertIn('solenv/qa/python/selftest/selftestobject', lib
['CXXOBJECTS'].split())
73 self
.assertIn('-DGBUILDSELFTESTDEF', lib
['DEFS'].split())
74 self
.assertIn('-DGBUILDSELFTESTCXXFLAG', lib
['CXXFLAGSAPPEND'].split())
75 self
.assertIn('-DGBUILDSELFTESTCFLAG', lib
['CFLAGSAPPEND'].split())
77 self
.assertTrue(False)
78 self
.assertEqual(foundlibs
, set(['gbuildselftest', 'gbuildselftestdep']))
79 self
.assertEqual(len(foundlibs
), 2)
80 jsonfiles
= os
.listdir(os
.path
.join(self
.tempwork
, 'GbuildToJson', 'Executable'))
82 for jsonfilename
in jsonfiles
:
83 with
open(os
.path
.join(self
.tempwork
, 'GbuildToJson', 'Executable', jsonfilename
), 'r') as f
:
84 gbuildexes
.append(json
.load(f
))
86 for exe
in gbuildexes
:
87 if exe
['LINKTARGET'].find('gbuildselftestexe') != -1:
88 foundexes
.add('gbuildselftestexe')
90 self
.assertTrue(False)
91 self
.assertEqual(foundexes
, set(['gbuildselftestexe']))
92 self
.assertEqual(len(foundexes
), 1)
94 class CheckGbuildToJsonModules(unittest
.TestCase
):
96 getgbuildtesttools(self
)
98 self
.tempwork
= tempfile
.mkdtemp(prefix
='gbuild')
99 self
.tempsrc
= tempfile
.mkdtemp(prefix
='gbuild')
100 self
.srcdir
= os
.environ
['SRCDIR']
101 self
.builddir
= os
.environ
['BUILDDIR']
102 if os
.environ
['OS'] == 'WNT':
103 self
.tempworkmixed
= self
.tempwork
.replace('\\','/')
104 self
.tempsrcmixed
= self
.tempsrc
.replace('\\','/')
105 self
.srcdirnative
= self
.srcdir
.replace('/','\\')
106 self
.builddirnative
= self
.builddir
.replace('/','\\')
108 self
.tempworkmixed
= self
.tempwork
109 self
.tempsrcmixed
= self
.tempsrc
110 self
.srcdirnative
= self
.srcdir
111 self
.builddirnative
= self
.builddir
112 shutil
.copyfile(os
.path
.join(self
.builddirnative
, 'config_host.mk'), os
.path
.join(self
.tempsrc
, 'config_host.mk'))
113 shutil
.copyfile(os
.path
.join(self
.builddirnative
, 'config_host_lang.mk'), os
.path
.join(self
.tempsrc
, 'config_host_lang.mk'))
114 shutil
.copytree(os
.path
.join(self
.builddirnative
, 'config_host'), os
.path
.join(self
.tempsrc
, 'config_host'))
115 shutil
.copyfile(os
.path
.join(self
.srcdirnative
, 'Repository.mk'), os
.path
.join(self
.tempsrc
, 'Repository.mk'))
116 shutil
.copyfile(os
.path
.join(self
.srcdirnative
, 'RepositoryExternal.mk'), os
.path
.join(self
.tempsrc
, 'RepositoryExternal.mk'))
117 shutil
.copyfile(os
.path
.join(self
.srcdirnative
, 'RepositoryFixes.mk'), os
.path
.join(self
.tempsrc
, 'RepositoryFixes.mk'))
118 #print('copytree from _%s_ to _%s_' % (os.path.join(self.srcdirnative, 'solenv').replace('\\', '#').replace('/', '!'), os.path.join(self.tempsrc, 'solenv').replace('\\', '#').replace('/', '!')))
119 shutil
.copytree(os
.path
.join(self
.srcdirnative
, 'solenv'), os
.path
.join(self
.tempsrc
, 'solenv'))
120 shutil
.copytree(os
.path
.join(self
.srcdirnative
, 'pch'), os
.path
.join(self
.tempsrc
, 'pch'))
123 shutil
.rmtree(self
.tempsrc
)
124 shutil
.rmtree(self
.tempwork
)
126 def test_gbuildtojson(self
):
127 modules
= ['accessibility', 'android', 'animations', 'apple_remote', 'avmedia', 'basctl', 'basegfx', 'basic', 'bean', 'canvas', 'chart2', 'codemaker', 'comphelper', 'cppcanvas', 'cui', 'dbaccess', 'desktop', 'drawinglayer', 'editeng', 'embeddedobj', 'embedserv', 'eventattacher', 'extras', 'filter', 'forms', 'formula', 'fpicker', 'framework', 'hwpfilter', 'i18nlangtag', 'i18nutil', 'idl', 'idlc', 'instsetoo_native', 'io', 'ios', 'jvmaccess', 'jvmfwk', 'l10ntools', 'librelogo', 'libreofficekit', 'linguistic', 'lotuswordpro', 'nlpsolver', 'o3tl', 'offapi', 'officecfg', 'onlineupdate', 'oovbaapi', 'oox', 'opencl', 'package', 'postprocess', 'pyuno', 'registry', 'remotebridges', 'reportbuilder', 'reportdesign', 'ridljar', 'salhelper', 'sax', 'sc', 'sccomp', 'scp2', 'scripting', 'sd', 'sdext', 'setup_native', 'sfx2', 'slideshow', 'smoketest', 'soltools', 'sot', 'starmath', 'store', 'svgio', 'emfio', 'svl', 'svtools', 'svx', 'sw', 'swext', 'sysui', 'test', 'testtools', 'toolkit', 'ucb', 'ucbhelper', 'udkapi', 'uitest', 'UnoControls', 'unodevtools', 'unoidl', 'unoil', 'unotest', 'unotools', 'unoxml', 'ure', 'uui', 'vbahelper', 'vcl', 'winaccessibility', 'wizards', 'writerperfect', 'xmerge', 'xmlhelp', 'xmloff', 'xmlreader', 'xmlscript', 'xmlsecurity']
128 if os
.environ
['OS'] == 'WNT':
129 # for now, use a limited subset for testing on windows as it is so annoyingly slow on this
130 modules
= ['chart2', 'cui', 'dbaccess', 'framework', 'oox', 'sfx2', 'svl', 'svtools', 'svx', 'toolkit', 'vcl', 'xmloff']
131 for module
in modules
:
132 shutil
.rmtree(self
.tempwork
)
133 os
.makedirs(os
.path
.join(self
.tempwork
, 'LinkTarget', 'Executable'))
134 shutil
.copy(self
.gbuildtojson
, os
.path
.join(self
.tempwork
, 'LinkTarget', 'Executable'))
135 if module
!= 'solenv':
136 shutil
.copytree(os
.path
.join(os
.environ
['SRCDIR'], module
), os
.path
.join(self
.tempsrc
, module
),
137 ignore
=shutil
.ignore_patterns('.#*', '#*', '*~'))
138 # ignore Emacs lock (.#*), auto-save (#*), and backup (*~) files
139 (bashscripthandle
, bashscriptname
) = tempfile
.mkstemp(prefix
='gbuild')
140 bashscript
= os
.fdopen(bashscripthandle
, 'w', newline
='\n')
141 bashscript
.write("set -e\n")
142 bashscript
.write("cd %s/%s\n" % (self
.tempsrc
.replace('\\','/'), module
))
143 bashscript
.write("%s gbuildtojson WORKDIR=%s SRCDIR=%s\n" % (self
.make
, self
.tempwork
.replace('\\', '/'), self
.tempsrc
.replace('\\','/')))
145 subprocess
.check_call([self
.bash
, bashscriptname
.replace('\\', '/')])
146 os
.remove(bashscriptname
)
147 jsonfiles
= os
.listdir(os
.path
.join(self
.tempwork
, 'GbuildToJson', 'Library'))
149 for jsonfilename
in jsonfiles
:
150 with
open(os
.path
.join(self
.tempwork
, 'GbuildToJson', 'Library', jsonfilename
), 'r') as f
:
151 gbuildlibs
.append(json
.load(f
))
154 if __name__
== "__main__":
157 # vim: set shiftwidth=4 softtabstop=4 expandtab: