improvements to gbuildtoide

- move supported module selection from the test directly into gbuild, it
  should not be possible now to have 'make gbuildtoide' failing, it
  should skip problematic parts
- move from whitelisting to blacklisting bad modules
- toplevel 'make gbuildtoide' should work now, so add test (limit to
  non-Windows for now, as Windows is stupid and slow)
- remove spurious debug output in test

Change-Id: I9838dd2fa091e5fb3e56f414f60164086e8f2076
Reviewed-on: https://gerrit.libreoffice.org/31072
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Tested-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
diff --git a/solenv/gbuild/extensions/post_GbuildToIde.mk b/solenv/gbuild/extensions/post_GbuildToIde.mk
index 47d0779..fd5ca19 100644
--- a/solenv/gbuild/extensions/post_GbuildToIde.mk
+++ b/solenv/gbuild/extensions/post_GbuildToIde.mk
@@ -88,15 +88,34 @@ $(call gb_LinkTarget__add_include,$(1),$(call gb_CustomTarget_get_workdir,$(2)))

endef

define gb_Module_add_target
$(if $(filter Library_% Executable_%,$(2)),$(call gb_Module__read_targetfile,$(1),$(2),target))

$(if $(filter Library_% Executable_%,$(2)),$(call gb_Module_get_nonl10n_target,$(1)) : $$(gb_Module_CURRENTTARGET))
define gb_Module__add_target_impl
$(call gb_Module__read_targetfile,$(1),$(2),target)

$(call gb_Module_get_nonl10n_target,$(1)) : $(3)

endef

define gb_Module_add_target
$(if $(filter Library_% Executable_%,$(2)),$(call gb_Module__add_target_impl,$(1),$(2),$$(gb_Module_CURRENTTARGET)))
endef

gb_Module_add_l10n_target =

gb_GbuildToIde_BLACKLISTEDMODULES := connectivity compilerplugins cli_ure dictionaries bridges helpcompiler helpcontent2 icon-themes jurt sal shell cppu cppuhelper cpputools extensions external i18npool javaunohelper jurt lingucomponent odk scaddins solenv stoc tools translations udkapi unoidl writerfilter

define gb_Module__add_moduledir_impl
include $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Module_MODULELOCATIONS)))/$(2)/Module_$(2).mk
$(call gb_Module_get_target,$(1)) : $$(firstword $$(gb_Module_TARGETSTACK))
gb_Module_TARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_TARGETSTACK)),$$(gb_Module_TARGETSTACK))

endef

define gb_Module_add_moduledir
$(if $(filter $(gb_GbuildToIde_BLACKLISTEDMODULES),$(2)),,$(call gb_Module__add_moduledir_impl,$(1),$(2)))

endef

endif

# vim: set noet ts=4 sw=4:
diff --git a/solenv/qa/python/gbuildtoide.py b/solenv/qa/python/gbuildtoide.py
index 8ff87ba..1d643c6 100644
--- a/solenv/qa/python/gbuildtoide.py
+++ b/solenv/qa/python/gbuildtoide.py
@@ -112,7 +112,7 @@ class CheckGbuildToIdeModules(unittest.TestCase):
        shutil.copyfile(os.path.join(self.srcdirnative, 'RepositoryExternal.mk'), os.path.join(self.tempsrc, 'RepositoryExternal.mk'))
        shutil.copyfile(os.path.join(self.srcdirnative, 'RepositoryFixes.mk'), os.path.join(self.tempsrc, 'RepositoryFixes.mk'))
        shutil.copytree(os.path.join(self.srcdirnative, 'config_host'),  os.path.join(self.tempsrc, 'config_host'))
        print('copytree from _%s_ to _%s_' % (os.path.join(self.srcdirnative, 'solenv').replace('\\', '#').replace('/', '!'), os.path.join(self.tempsrc, 'solenv').replace('\\', '#').replace('/', '!')))
        #print('copytree from _%s_ to _%s_' % (os.path.join(self.srcdirnative, 'solenv').replace('\\', '#').replace('/', '!'), os.path.join(self.tempsrc, 'solenv').replace('\\', '#').replace('/', '!')))
        shutil.copytree(os.path.join(self.srcdirnative, 'solenv'),  os.path.join(self.tempsrc, 'solenv'))

    def tearDown(self):
@@ -120,7 +120,6 @@ class CheckGbuildToIdeModules(unittest.TestCase):
        shutil.rmtree(self.tempwork)

    def test_gbuildtoide(self):
        blacklisted_modules = ['compilerplugins', 'cli_ure', 'dictionaries', 'bridges', 'helpcompiler', 'helpcontent2', 'icon-themes', 'sal', 'shell', 'cppu', 'cppuhelper', 'cpputools', 'extensions', 'external', 'i18npool', 'javaunohelper', 'jurt', 'lingucomponent', 'odk', 'scaddins', 'solenv', 'stoc', 'tools', 'translations', 'writerfilter']
        modules = ['accessibility', 'android', 'animations', 'apple_remote', 'avmedia', 'basctl', 'basegfx', 'basic', 'bean', 'canvas', 'chart2', 'codemaker', 'comphelper', 'cppcanvas', 'cui', 'dbaccess', 'desktop', 'drawinglayer', 'dtrans', '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', 'mysqlc', 'nlpsolver', 'o3tl', 'offapi', 'officecfg', 'onlineupdate', 'oovbaapi', 'oox', 'opencl', 'package', 'postprocess', 'pyuno', 'registry', 'remotebridges', 'reportbuilder', 'reportdesign', 'ridljar', 'rsc', 'salhelper', 'sax', 'sc', 'sccomp', 'scp2', 'scripting', 'sd', 'sdext', 'setup_native', 'sfx2', 'slideshow', 'smoketest', 'soltools', 'sot', 'starmath', 'store', 'svgio', 'svl', 'svtools', 'svx', 'sw', 'swext', 'sysui', 'test', 'testtools', 'toolkit', 'tubes', 'ucb', 'ucbhelper', 'udkapi', 'uitest', 'UnoControls', 'unodevtools', 'unoidl', 'unoil', 'unotest', 'unotools', 'unoxml', 'ure', 'uui', 'vbahelper', 'vcl', 'winaccessibility', 'wizards', 'writerperfect', 'xmerge', 'xmlhelp', 'xmloff', 'xmlreader', 'xmlscript', 'xmlsecurity']
        if os.environ['OS'] == 'WNT':
            # for now, use a limited subset for testing on windows as it is so annoyingly slow on this
@@ -145,6 +144,57 @@ class CheckGbuildToIdeModules(unittest.TestCase):
            with open(os.path.join(self.tempwork, 'GbuildToIde', 'Library', jsonfilename), 'r') as f:
                gbuildlibs.append(json.load(f))

class CheckGbuildToIdeTopLevel(unittest.TestCase):
    def setUp(self):
        if os.environ['OS'] == 'WNT':
            # for now, skip this on windows
            return
        getgbuildtesttools(self)
        clearmakevars()
        self.tempwork = tempfile.mkdtemp()
        self.tempsrcparent = tempfile.mkdtemp()
        self.tempsrc = os.path.join(self.tempsrcparent, 'src')
        print('tempsrcparent:', self.tempsrcparent, 'tempsrc:', self.tempsrc)
        self.srcdir = os.environ['SRCDIR']
        if os.environ['OS'] == 'WNT':
            self.tempworkmixed = self.tempwork.replace('\\','/')
            self.tempsrcmixed = self.tempsrc.replace('\\','/')
            self.srcdirnative = self.srcdir.replace('/','\\')
        else:
            self.tempworkmixed = self.tempwork
            self.tempsrcmixed = self.tempsrc
            self.srcdirnative = self.srcdir
        shutil.copytree(self.srcdirnative, self.tempsrc)

    def tearDown(self):
        if os.environ['OS'] == 'WNT':
            # for now, skip this on windows
            return
        shutil.rmtree(self.tempsrcparent)
        shutil.rmtree(self.tempwork)

    def test_gbuildtoide(self):
        if os.environ['OS'] == 'WNT':
            # for now, skip this on windows
            return
        shutil.rmtree(self.tempwork)
        os.makedirs(os.path.join(self.tempwork, 'LinkTarget', 'Executable'))
        shutil.copy(self.gbuildtojson, os.path.join(self.tempwork, 'LinkTarget', 'Executable'))
        (bashscripthandle, bashscriptname) = tempfile.mkstemp()
        bashscript = os.fdopen(bashscripthandle, 'w', newline='\n')
        bashscript.write("set -e\n")
        bashscript.write("cd %s\n" % self.tempsrc.replace('\\','/'))
        bashscript.write("echo TEMPSRC: %s\n" % self.tempsrc.replace('\\','/'))
        bashscript.write("%s gbuildtoide WORKDIR=%s SRCDIR=%s\n" % (self.make, self.tempwork.replace('\\', '/'), self.tempsrc.replace('\\','/')))
        bashscript.close()
        subprocess.check_call([self.bash, bashscriptname.replace('\\', '/')])
        os.remove(bashscriptname)
        jsonfiles = os.listdir(os.path.join(self.tempwork, 'GbuildToIde', 'Library'))
        gbuildlibs = []
        for jsonfilename in jsonfiles:
            with open(os.path.join(self.tempwork, 'GbuildToIde', 'Library', jsonfilename), 'r') as f:
                gbuildlibs.append(json.load(f))


if __name__ == "__main__":
    unittest.main()