2013-12-19 15:32:54 +01:00
#!/usr/bin/python
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import print_function
from optparse import OptionParser
2015-01-27 10:51:57 +01:00
import re
2015-01-27 00:53:28 +01:00
import sys
import xml . etree . ElementTree as ET
2013-12-23 17:44:57 +01:00
# foo_component_getFactory functions are split into groups, so that you could
2014-03-06 13:46:02 +01:00
# choose e.g. 'core' and 'writer' functionality and through factory_map,
2013-12-23 17:44:57 +01:00
# relevant function sections will be referenced in lo_get_factory_map().
# That prevents garbage collector to ignore them as unused.
2014-01-09 09:20:55 +01:00
# The same groups are used for constructor based implementations
# referenced in lo_get_constructor_map().
2013-12-23 17:44:57 +01:00
core_factory_list = [
2014-02-17 12:45:27 +02:00
( " libembobj.a " , " embobj_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " libreflectionlo.a " , " reflection_component_getFactory " ) ,
( " libstocserviceslo.a " , " stocservices_component_getFactory " ) ,
2014-02-17 12:45:27 +02:00
( " libchartcorelo.a " , " chartcore_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " libcomphelper.a " , " comphelp_component_getFactory " ) ,
( " libconfigmgrlo.a " , " configmgr_component_getFactory " ) ,
2014-03-05 17:32:41 +02:00
( " libdrawinglayerlo.a " , " drawinglayer_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " libfilterconfiglo.a " , " filterconfig1_component_getFactory " ) ,
( " libfsstoragelo.a " , " fsstorage_component_getFactory " ) ,
( " libhyphenlo.a " , " hyphen_component_getFactory " ) ,
2014-03-10 11:49:28 +02:00
( " libi18npoollo.a " , " i18npool_component_getFactory " ) ,
2015-01-29 12:36:56 +01:00
( " libi18nsearchlo.a " , " i18nsearch_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " liblnglo.a " , " lng_component_getFactory " ) ,
( " liblnthlo.a " , " lnth_component_getFactory " ) ,
( " liblocalebe1lo.a " , " localebe1_component_getFactory " ) ,
( " libooxlo.a " , " oox_component_getFactory " ) ,
( " libpackage2.a " , " package2_component_getFactory " ) ,
2015-02-02 23:34:16 +01:00
( " libslideshowlo.a " , " slideshow_component_getFactory " ) ,
2014-02-17 12:45:27 +02:00
( " libsmlo.a " , " sm_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " libsotlo.a " , " sot_component_getFactory " ) ,
( " libspelllo.a " , " spell_component_getFactory " ) ,
2014-01-17 13:36:56 +02:00
( " libsrtrs1.a " , " srtrs1_component_getFactory " ) ,
2014-07-01 15:22:42 +02:00
( " libstoragefdlo.a " , " storagefd_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " libucb1.a " , " ucb_component_getFactory " ) ,
( " libucpfile1.a " , " ucpfile_component_getFactory " ) ,
2014-01-17 13:36:56 +02:00
( " libucphier1.a " , " ucphier1_component_getFactory " ) ,
2014-08-13 11:17:40 +03:00
( " libucptdoc1lo.a " , " ucptdoc1_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " libunordflo.a " , " unordf_component_getFactory " ) ,
( " libunoxmllo.a " , " unoxml_component_getFactory " ) ,
( " libutllo.a " , " utl_component_getFactory " ) ,
( " libxmlsecurity.a " , " xmlsecurity_component_getFactory " ) ,
2015-02-05 16:35:56 +01:00
( " libxoflo.a " , " xof_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
( " libxolo.a " , " xo_component_getFactory " ) ,
2014-12-09 15:15:53 +01:00
( " libxsec_xmlsec.a " , " xsec_xmlsec_component_getFactory " , " #ifndef ANDROID " ) ,
2013-12-23 17:44:57 +01:00
( " libxstor.a " , " xstor_component_getFactory " ) ,
2015-01-26 23:20:44 +01:00
( " libcanvasfactorylo.a " , " canvasfactory_component_getFactory " ) ,
( " libvclcanvaslo.a " , " vclcanvas_component_getFactory " ) ,
( " libmtfrendererlo.a " , " mtfrenderer_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
]
2014-01-09 09:20:55 +01:00
core_constructor_list = [
2014-04-25 12:50:27 +03:00
# chart2/source/controller/chartcontroller.component
" com_sun_star_comp_chart2_ChartDocumentWrapper_get_implementation " ,
2014-01-17 14:41:10 +01:00
# framework/util/fwk.component
2014-01-21 15:08:26 +02:00
" com_sun_star_comp_framework_AutoRecovery_get_implementation " ,
2014-01-16 22:30:54 +01:00
" com_sun_star_comp_framework_Desktop_get_implementation " ,
2014-01-21 15:11:24 +02:00
" com_sun_star_comp_framework_Frame_get_implementation " ,
2014-01-21 15:08:26 +02:00
" com_sun_star_comp_framework_JobExecutor_get_implementation " ,
2014-01-21 15:11:24 +02:00
" com_sun_star_comp_framework_LayoutManager_get_implementation " ,
" com_sun_star_comp_framework_ModuleManager_get_implementation " ,
2014-01-29 15:22:09 +02:00
" com_sun_star_comp_framework_ModuleUIConfigurationManager_get_implementation " ,
2014-02-11 09:23:57 +02:00
" com_sun_star_comp_framework_ModuleUIConfigurationManagerSupplier_get_implementation " ,
2014-01-23 18:58:18 +02:00
" com_sun_star_comp_framework_PathSettings_get_implementation " ,
2014-01-09 19:36:11 +01:00
" com_sun_star_comp_framework_PathSubstitution_get_implementation " ,
2014-01-21 15:08:26 +02:00
" com_sun_star_comp_framework_StatusIndicatorFactory_get_implementation " ,
2014-01-09 17:32:35 +01:00
" com_sun_star_comp_framework_TaskCreator_get_implementation " ,
2014-01-29 15:22:09 +02:00
" com_sun_star_comp_framework_ToolBarControllerFactory_get_implementation " ,
" com_sun_star_comp_framework_UIConfigurationManager_get_implementation " ,
" com_sun_star_comp_framework_UIElementFactoryManager_get_implementation " ,
2014-01-21 15:11:24 +02:00
" com_sun_star_comp_framework_URLTransformer_get_implementation " ,
2014-01-09 16:38:11 +01:00
" com_sun_star_comp_framework_WindowStateConfiguration_get_implementation " ,
2015-01-29 15:48:34 +01:00
" com_sun_star_comp_framework_ModuleAcceleratorConfiguration_get_implementation " ,
2014-02-11 14:18:10 +01:00
" org_apache_openoffice_comp_framework_ContextChangeEventMultiplexer_get_implementation " ,
2014-01-27 08:29:52 +01:00
# i18npool/util/i18npool.component
" com_sun_star_i18n_BreakIterator_get_implementation " ,
" com_sun_star_i18n_BreakIterator_Unicode_get_implementation " ,
" com_sun_star_i18n_CharacterClassification_get_implementation " ,
" com_sun_star_i18n_CharacterClassification_Unicode_get_implementation " ,
2014-03-31 20:58:54 +03:00
" com_sun_star_i18n_Collator_get_implementation " ,
2014-01-27 08:29:52 +01:00
" com_sun_star_i18n_LocaleDataImpl_get_implementation " ,
" com_sun_star_i18n_NumberFormatCodeMapper_get_implementation " ,
" com_sun_star_i18n_Transliteration_get_implementation " ,
" com_sun_star_i18n_Transliteration_IGNORE_CASE_get_implementation " ,
" com_sun_star_i18n_Transliteration_IGNORE_KANA_get_implementation " ,
" com_sun_star_i18n_Transliteration_IGNORE_WIDTH_get_implementation " ,
" com_sun_star_text_DefaultNumberingProvider_get_implementation " ,
2014-01-09 09:20:55 +01:00
# sax/source/expatwrap/expwrap.component
2014-01-15 20:00:41 +02:00
" com_sun_star_comp_extensions_xml_sax_FastParser_get_implementation " ,
2014-01-21 15:11:24 +02:00
" com_sun_star_comp_extensions_xml_sax_ParserExpat_get_implementation " ,
2014-02-17 12:45:27 +02:00
" com_sun_star_extensions_xml_sax_Writer_get_implementation " ,
2014-01-17 10:30:06 +01:00
# sfx2/util/sfx.component
2014-01-21 15:11:24 +02:00
" SfxDocumentMetaData_get_implementation " ,
" com_sun_star_comp_office_FrameLoader_get_implementation " ,
2014-01-17 13:36:56 +02:00
" com_sun_star_comp_sfx2_DocumentTemplates_get_implementation " ,
2014-01-17 10:30:06 +01:00
" com_sun_star_comp_sfx2_GlobalEventBroadcaster_get_implementation " ,
2014-01-09 09:20:55 +01:00
# svtools/util/svt.component
2014-02-17 12:45:27 +02:00
" com_sun_star_graphic_GraphicObject_get_implementation " ,
2014-01-09 09:20:55 +01:00
" com_sun_star_comp_graphic_GraphicProvider_get_implementation " ,
# svx/util/svx.component
2014-01-15 20:00:41 +02:00
" com_sun_star_drawing_EnhancedCustomShapeEngine_get_implementation " ,
2014-02-17 12:45:27 +02:00
# svx/util/svxcore.component
2014-02-17 14:44:28 +02:00
" com_sun_star_comp_graphic_PrimitiveFactory2D_get_implementation " ,
" com_sun_star_comp_Draw_GraphicExporter_get_implementation " ,
2014-02-17 12:45:27 +02:00
" com_sun_star_comp_Svx_GraphicExportHelper_get_implementation " ,
2014-02-17 14:44:28 +02:00
" com_sun_star_comp_Svx_GraphicImportHelper_get_implementation " ,
2014-03-07 11:03:55 +01:00
# stoc/source/inspect/introspection.component
" com_sun_star_comp_stoc_Introspection_get_implementation " ,
2014-01-27 08:29:52 +01:00
# toolkit/util/tk.component
2015-02-05 18:07:05 +01:00
" stardiv_Toolkit_UnoComboBoxControl_get_implementation " ,
" stardiv_Toolkit_UnoControlComboBoxModel_get_implementation " ,
2014-03-20 09:32:21 +02:00
" stardiv_Toolkit_UnoControlContainer_get_implementation " ,
" stardiv_Toolkit_UnoControlContainerModel_get_implementation " ,
2015-02-05 18:07:05 +01:00
" stardiv_Toolkit_UnoDateFieldControl_get_implementation " ,
" stardiv_Toolkit_UnoControlDateFieldModel_get_implementation " ,
2015-02-02 23:34:16 +01:00
" stardiv_Toolkit_VCLXPointer_get_implementation " ,
2014-01-24 15:53:16 +02:00
" stardiv_Toolkit_VCLXToolkit_get_implementation " ,
2014-02-10 17:05:19 +02:00
# uui/util/uui.component
" com_sun_star_comp_uui_UUIInteractionHandler_get_implementation " ,
2014-02-11 09:20:03 +02:00
# xmloff/util/xo.component
" XMLVersionListPersistence_get_implementation " ,
2014-01-09 09:20:55 +01:00
]
2014-03-06 14:23:57 +01:00
# edit group for apps, where you can edit documents
edit_factory_list = [
]
edit_constructor_list = [
" com_sun_star_comp_framework_GlobalAcceleratorConfiguration_get_implementation " ,
" com_sun_star_i18n_InputSequenceChecker_get_implementation " ,
" com_sun_star_i18n_OrdinalSuffix_get_implementation " ,
]
2014-03-06 13:46:02 +01:00
calc_factory_list = [
2013-12-23 17:44:57 +01:00
( " libscdlo.a " , " scd_component_getFactory " ) ,
( " libscfiltlo.a " , " scfilt_component_getFactory " ) ,
( " libsclo.a " , " sc_component_getFactory " ) ,
2014-07-28 13:20:32 +02:00
( " libavmedialo.a " , " avmedia_component_getFactory " ) ,
2014-08-03 22:40:02 +02:00
( " libanalysislo.a " , " analysis_component_getFactory " ) ,
( " libdatelo.a " , " date_component_getFactory " ) ,
( " libpricinglo.a " , " pricing_component_getFactory " ) ,
( " libsvllo.a " , " svl_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
]
2014-03-06 13:46:02 +01:00
calc_constructor_list = [
2014-01-09 09:20:55 +01:00
]
2014-03-06 13:46:02 +01:00
draw_factory_list = [
2013-12-23 17:44:57 +01:00
( " libsddlo.a " , " sdd_component_getFactory " ) ,
( " libsdlo.a " , " sd_component_getFactory " ) ,
( " libsvgfilterlo.a " , " svgfilter_component_getFactory " ) ,
2014-08-03 22:40:02 +02:00
( " libdeployment.a " , " deployment_component_getFactory " ) ,
( " libemboleobj.a " , " emboleobj_component_getFactory " ) ,
2015-01-26 23:20:44 +01:00
( " libanimcorelo.a " , " animcore_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
]
2014-03-06 13:46:02 +01:00
draw_constructor_list = [
2014-01-09 09:20:55 +01:00
]
2014-03-06 13:46:02 +01:00
writer_factory_list = [
2015-02-05 18:07:05 +01:00
( " libfrmlo.a " , " frm_component_getFactory " ) ,
2015-02-11 08:52:00 +02:00
( " libsblo.a " , " sb_component_getFactory " , " #if HAVE_FEATURE_SCRIPTING " ) ,
2013-12-23 17:44:57 +01:00
( " libswdlo.a " , " swd_component_getFactory " ) ,
( " libswlo.a " , " sw_component_getFactory " ) ,
2014-01-27 21:15:19 +01:00
( " libwriterfilterlo.a " , " writerfilter_component_getFactory " ) ,
2014-09-30 13:04:02 +02:00
( " libtextfdlo.a " , " textfd_component_getFactory " ) ,
2013-12-23 17:44:57 +01:00
]
2014-03-06 13:46:02 +01:00
writer_constructor_list = [
2014-01-09 09:20:55 +01:00
]
2013-12-23 17:44:57 +01:00
factory_map = {
' core ' : core_factory_list ,
2014-03-06 14:23:57 +01:00
' edit ' : edit_factory_list ,
2013-12-23 17:44:57 +01:00
' calc ' : calc_factory_list ,
2014-03-06 13:46:02 +01:00
' draw ' : draw_factory_list ,
2013-12-23 17:44:57 +01:00
' writer ' : writer_factory_list ,
}
2014-01-09 09:20:55 +01:00
constructor_map = {
' core ' : core_constructor_list ,
2014-03-06 14:23:57 +01:00
' edit ' : edit_constructor_list ,
2014-01-09 09:20:55 +01:00
' calc ' : calc_constructor_list ,
2014-03-06 13:46:02 +01:00
' draw ' : draw_constructor_list ,
2014-01-09 09:20:55 +01:00
' writer ' : writer_constructor_list ,
}
2013-12-23 17:44:57 +01:00
2015-01-27 00:53:28 +01:00
# instead of outputting native-code.cxx, reduce the services.rdb according to
# the constraints, so that we can easily emulate what services do we need to
# add for a fully functional file loading / saving / ...
2015-01-27 09:51:47 +01:00
def limit_rdb ( services_rdb , full_factory_map , full_constructor_map ) :
2015-01-27 00:53:28 +01:00
ET . register_namespace ( ' ' , ' http://openoffice.org/2010/uno-components ' )
tree = ET . parse ( services_rdb [ 0 ] )
root = tree . getroot ( )
for component in root . findall ( ' { http://openoffice.org/2010/uno-components}component ' ) :
2015-01-27 10:51:57 +01:00
# direct
uri = component . get ( ' uri ' )
component_name = None
if uri != None :
component_name = re . sub ( ' ^vnd.sun.star.expand: \ $LO_LIB_DIR/([^.]*).so$ ' , ' \\ 1.a ' , uri )
if component_name in full_factory_map :
continue
# via a constructor - limit only to those we have
has_constructor = False
2015-01-27 00:53:28 +01:00
for implementation in component . findall ( ' { http://openoffice.org/2010/uno-components}implementation ' ) :
constructor = implementation . get ( ' constructor ' )
2015-01-27 10:51:57 +01:00
if constructor in full_constructor_map :
has_constructor = True
else :
2015-01-27 00:53:28 +01:00
component . remove ( implementation )
2015-01-27 10:51:57 +01:00
if not has_constructor :
root . remove ( component )
2015-01-27 00:53:28 +01:00
tree . write ( services_rdb [ 0 ] + ' .out ' , xml_declaration = True , method = ' xml ' )
# do the actual work
2013-12-19 15:32:54 +01:00
opts = OptionParser ( )
opts . add_option ( " -j " , " --java-guard " , action = " store_true " , help = " include external java functions " , dest = " java " , default = False )
2013-12-23 17:44:57 +01:00
opts . add_option ( " -g " , " --group " , action = " append " , help = " group of implementations to make available in application " , dest = " groups " )
2015-01-27 00:53:28 +01:00
opts . add_option ( " -r " , " --limit-rdb " , action = " append " , help = " instead of outputting native-code.cxx, limit the services.rdb only to the services defined by the groups " , dest = " services " )
2013-12-19 15:32:54 +01:00
( options , args ) = opts . parse_args ( )
2015-01-27 09:51:47 +01:00
# dict of all the contructors that we need according to -g's
2015-01-27 00:53:28 +01:00
full_constructor_map = { }
if options . groups :
for constructor_group in options . groups :
for constructor in constructor_map [ constructor_group ] :
full_constructor_map [ constructor ] = True
2015-01-27 09:51:47 +01:00
# dict of all the factories that we need according to -g's
full_factory_map = { }
if options . groups :
for factory_group in options . groups :
for entry in factory_map [ factory_group ] :
factory_guard = None
if len ( entry ) > 2 :
factory_guard = entry [ 2 ]
map_entry = { ' function ' : entry [ 1 ] , ' guard ' : factory_guard }
full_factory_map [ entry [ 0 ] ] = map_entry
# are we only shuffling the services.rdb?
2015-01-27 00:53:28 +01:00
if options . services :
2015-01-27 09:51:47 +01:00
limit_rdb ( options . services , full_factory_map , full_constructor_map )
2015-01-27 00:53:28 +01:00
exit ( 0 )
2014-01-01 17:01:18 +00:00
print ( """ /*
* This is a generated file . Do not edit .
2014-01-09 09:20:55 +01:00
* file generated by solenv / bin / native - code . py
2014-01-01 17:01:18 +00:00
* /
2013-12-23 17:44:57 +01:00
#include <osl/detail/component-mapping.h>
extern " C " {
""" )
2015-01-27 09:51:47 +01:00
for entry in sorted ( full_factory_map . keys ( ) ) :
factory_function = full_factory_map [ entry ] [ ' function ' ]
factory_guard = full_factory_map [ entry ] [ ' guard ' ]
if factory_guard :
print ( factory_guard )
print ( ' void * ' + factory_function + ' ( const char* , void* , void* ); ' )
if factory_guard :
print ( ' #endif ' )
2013-12-23 17:44:57 +01:00
print ( ' ' )
2015-01-27 09:17:01 +01:00
for constructor in sorted ( full_constructor_map . keys ( ) ) :
print ( ' void * ' + constructor + ' ( void *, void * ); ' )
2013-12-23 17:44:57 +01:00
print ( """
2013-12-19 15:32:54 +01:00
const lib_to_factory_mapping *
lo_get_factory_map ( void )
{
static lib_to_factory_mapping map [ ] = { """ )
2015-01-27 09:51:47 +01:00
for entry in sorted ( full_factory_map . keys ( ) ) :
factory_function = full_factory_map [ entry ] [ ' function ' ]
factory_guard = full_factory_map [ entry ] [ ' guard ' ]
if factory_guard :
print ( factory_guard )
print ( ' { " ' + entry + ' " , ' + factory_function + ' }, ' )
if factory_guard :
print ( ' #endif ' )
2013-12-19 15:32:54 +01:00
print ( """
2013-12-23 17:44:57 +01:00
{ 0 , 0 }
2013-12-19 15:32:54 +01:00
} ; """ )
if options . java :
print ( """
/ / Guard against possible function - level link - time pruning of
/ / " unused " code . We need to pull these in , too , as they aren ' t in
/ / any of the libs we link with - Wl , - - whole - archive . Is this necessary ?
extern void Java_org_libreoffice_android_AppSupport_runMain ( ) ;
volatile void * p = ( void * ) Java_org_libreoffice_android_AppSupport_runMain ;
extern void Java_org_libreoffice_android_AppSupport_renderVCL ( ) ;
2014-06-28 18:23:24 +02:00
p = ( void * ) Java_org_libreoffice_android_AppSupport_renderVCL ;
2014-06-30 23:34:15 +02:00
extern void Java_org_libreoffice_kit_LibreOfficeKit_initializeNative ( ) ;
p = ( void * ) Java_org_libreoffice_kit_LibreOfficeKit_initializeNative ;
2014-11-17 10:38:54 +01:00
extern void Java_org_libreoffice_kit_Office_getError ( ) ;
p = ( void * ) Java_org_libreoffice_kit_Office_getError ;
2014-06-30 23:34:15 +02:00
""" )
2013-12-19 15:32:54 +01:00
print ( """
return map ;
}
const lib_to_constructor_mapping *
lo_get_constructor_map ( void )
{
2013-12-23 17:44:57 +01:00
static lib_to_constructor_mapping map [ ] = { """ )
2014-01-09 09:20:55 +01:00
2015-01-27 09:17:01 +01:00
for constructor in sorted ( full_constructor_map . keys ( ) ) :
print ( ' { " ' + constructor + ' " , ' + constructor + ' }, ' )
2013-12-19 15:32:54 +01:00
print ( """
2013-12-23 17:44:57 +01:00
{ 0 , 0 }
2013-12-19 15:32:54 +01:00
} ;
return map ;
2013-12-23 17:44:57 +01:00
}
2013-12-19 15:32:54 +01:00
} """ )
2014-12-09 15:15:53 +01:00
# vim:set shiftwidth=4 softtabstop=4 expandtab: