~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to config/pandora-plugin

Merge in Joe's transaction id code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#  along with this program; if not, write to the Free Software
16
16
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
 
18
pandora_plugin_file = 'config/pandora-plugin.ini'
18
19
 
19
 
# Find plugins in the tree and add them to the build system 
 
20
# Find plugins in the tree and add them to the build system
20
21
 
21
22
import ConfigParser, os, sys
22
23
import datetime, time
23
24
import subprocess
24
25
 
25
 
top_srcdir='.'
26
 
top_builddir='.'
27
 
plugin_ini_fname='plugin.ini'
28
 
plugin_list=[]
29
26
plugin_am_file=None
30
27
plugin_ac_file=None
31
 
plugin_prefix=''
32
 
plugin_suffix='_plugin'
33
 
extra_cflags=''
34
 
extra_cppflags=''
35
 
extra_cxxflags=''
36
 
root_plugin_dir='plugin'
37
 
pkgplugindir='$(libdir)/drizzle'
38
 
default_install='True'
39
 
default_plugin_version=''
 
28
plugin_doc_index=None
40
29
 
41
30
class ChangeProtectedFile(object):
42
31
 
54
43
      self.new_file.write(text)
55
44
 
56
45
  # We've written all of this out into .new files, now we only copy them
57
 
  # over the old ones if they are different, so that we don't cause 
 
46
  # over the old ones if they are different, so that we don't cause
58
47
  # unnecessary recompiles
59
48
  def close(self):
60
49
    """Return True if the file had changed."""
145
134
""" % plugin)
146
135
  if plugin['headers'] != "":
147
136
    plugin_file.write("noinst_HEADERS = %(headers)s\n" % plugin)
 
137
  if plugin['install_headers'] != "":
 
138
    plugin_file.write("nobase_include_HEADERS += %(install_headers)s\n" % plugin)
148
139
  if plugin['testsuite']:
149
140
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
150
141
      plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin)
151
142
  plugin_file.write("""
152
 
pkgplugin_LTLIBRARIES=%(pname)s.la
153
 
%(pname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
154
 
%(pname)s_la_LIBADD=%(libs)s
155
 
%(pname)s_la_DEPENDENCIES=%(libs)s
156
 
%(pname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(name)s -DPANDORA_MODULE_AUTHOR="%(author)s" -DPANDORA_MODULE_TITLE="%(title)s" -DPANDORA_MODULE_VERSION="%(version)s" -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s
157
 
%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
158
 
%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
159
 
 
160
 
%(pname)s_la_SOURCES=%(sources)s
161
 
 
 
143
pkgplugin_LTLIBRARIES=%(libname)s.la
 
144
%(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
 
145
%(libname)s_la_LIBADD=%(libs)s
 
146
%(libname)s_la_DEPENDENCIES=%(libs)s
 
147
%(libname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(module_name)s -DPANDORA_MODULE_AUTHOR='"%(author)s"' -DPANDORA_MODULE_TITLE='"%(title)s"' -DPANDORA_MODULE_VERSION='"%(version)s"' -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s
 
148
%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
 
149
%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
 
150
%(libname)s_la_SOURCES=%(sources)s
 
151
check_PROGRAMS += %(tests)s
162
152
""" % plugin)
163
153
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
164
154
  if os.path.exists(plugin_am_file):
167
157
def write_external_plugin():
168
158
  """Return True if the plugin had changed."""
169
159
  plugin = read_plugin_ini('.')
170
 
  expand_plugin_ini(plugin, '.')
 
160
  expand_plugin_ini(plugin)
171
161
  plugin_file = ChangeProtectedFile('configure.ac')
172
162
  write_external_configure(plugin, plugin_file)
173
163
  result = plugin_file.close()
177
167
  result = plugin_file.close() or result
178
168
  return result
179
169
 
180
 
def write_plugin(plugin_dir):
181
 
  """Return True if the plugin had changed."""
182
 
  plugin = read_plugin_ini(plugin_dir)
183
 
  expand_plugin_ini(plugin, plugin_dir)
 
170
def write_plugin(plugin, plugin_ini_list):
 
171
  # Since this function is recursive, make sure we're not already in it.
 
172
  if plugin.has_key('writing_status'):
 
173
    if plugin['writing_status'] == 'done':
 
174
      return
 
175
    else:
 
176
      print "Dependency loop detected with %s" % plugin['name']
 
177
      exit(1)
 
178
 
 
179
  plugin['writing_status'] = 'dependencies'
 
180
 
 
181
  # Write all dependencies first to get around annoying automake bug
 
182
  for dependency in plugin['dependency_list']:
 
183
    found = False
 
184
    for find_plugin in plugin_ini_list:
 
185
      if find_plugin['module_name'] == dependency:
 
186
        found = True
 
187
        write_plugin(find_plugin, plugin_ini_list)
 
188
        break
 
189
    if found is False:
 
190
      print "Could not find dependency %s: %s" % (plugin['name'], dependency)
 
191
      exit(1)
 
192
 
184
193
  write_plugin_ac(plugin, plugin_ac_file)
185
194
  write_plugin_am(plugin, plugin_am_file)
 
195
  write_plugin_docs(plugin, plugin_doc_index)
 
196
  plugin['writing_status'] = 'done'
 
197
 
 
198
def write_plugin_docs(plugin, doc_index):
 
199
  if plugin['docs'] is not None and os.path.isdir("docs/plugins"):
 
200
    if not os.path.exists(os.path.join("docs/plugins",plugin["name"])):
 
201
      os.symlink(os.path.abspath(plugin["docs"]), os.path.join("docs/plugins",plugin["name"]))
 
202
    doc_index.write("""
 
203
   %(name)s/index""" % plugin)
186
204
 
187
205
def write_plugin_ac(plugin, plugin_ac):
188
206
  #
202
220
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
203
221
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
204
222
 
205
 
  if plugin['static']:
206
 
    plugin_ac.write("""
207
 
dnl This plugin is staticly built, which means we cannot live without and it is not
208
 
dnl possible to disable it. Once it is disableable, we will make it non-static.
209
 
with_%(name)s_plugin=yes
210
 
pandora_builtin_list="_drizzled_%(name)s_plugin_,${pandora_builtin_list}"
211
 
pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/%(root_plugin_dir)s/%(pname)s.la"
212
 
PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
213
 
 
214
 
""" % plugin)
215
 
    if plugin['testsuite']:
216
 
      plugin_ac.write("""
217
 
pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
218
 
""" % plugin)
219
 
  else:
220
 
    plugin_ac.write("""
 
223
  plugin_ac.write("""
221
224
AC_ARG_WITH([%(name_with_dashes)s-plugin],[
222
225
dnl indented wierd to make the help output correct
223
226
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(enabled)s@:>@])
235
238
  ])
236
239
AC_ARG_ENABLE([%(name_with_dashes)s-plugin],[
237
240
dnl indented wierd to make the help output correct
238
 
AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(default_yesno)s@:>@])
239
 
AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable building %(title)s])
 
241
AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Enable loading %(title)s by default. @<:@default=%(default_yesno)s@:>@])
 
242
AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable loading %(title)s by default.])
240
243
  ],
241
 
  [enable_%(name)s_plugin="$withval"],
 
244
  [enable_%(name)s_plugin="$enableval"],
242
245
  [enable_%(name)s_plugin=%(default_yesno)s])
243
246
 
244
247
""" % plugin)
245
248
  if os.path.exists(plugin_ac_file):
246
 
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) 
 
249
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file)
247
250
  # The plugin author has specified some check to make to determine
248
 
  # if the plugin can be built. If the plugin is turned on and this 
 
251
  # if the plugin can be built. If the plugin is turned on and this
249
252
  # check fails, then configure should error out. If the plugin is not
250
253
  # turned on, then the normal conditional build stuff should just let
251
254
  # it silently not build
265
268
AM_CONDITIONAL([%(build_conditional_tag)s],
266
269
               [test %(build_conditional)s])
267
270
    """ % plugin)
268
 
  if not plugin['static']:
269
 
    plugin_ac.write("""
 
271
 
 
272
  plugin_ac.write("""
270
273
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
271
 
      [
 
274
    [
272
275
""" % plugin)
273
 
    if plugin['testsuite']:
274
 
      plugin_ac.write("""
275
 
        pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
276
 
      """ % plugin)
 
276
  if plugin['testsuite']:
 
277
    plugin_ac.write("""
 
278
      pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
 
279
    """ % plugin)
 
280
  if plugin['static']:
 
281
    plugin_ac.write("""
 
282
        AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
 
283
          pandora_builtin_load_list="%(module_name)s,${pandora_builtin_load_list}"
 
284
          pandora_builtin_load_symbols_list="_drizzled_%(module_name)s_plugin_,${pandora_builtin_load_symbols_list}"
 
285
          PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
 
286
        ])
 
287
        pandora_builtin_list="%(module_name)s,${pandora_builtin_list}"
 
288
        pandora_builtin_symbols_list="_drizzled_%(module_name)s_plugin_,${pandora_builtin_symbols_list}"
 
289
        pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/%(root_plugin_dir)s/%(libname)s.la"
 
290
    """ % plugin)
277
291
 
 
292
  else:
278
293
    plugin_ac.write("""
279
294
        AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
280
295
          pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
281
296
        ])
282
297
    """ % plugin)
283
 
    plugin_ac.write("      ])\n")
284
 
 
285
 
 
286
 
def expand_plugin_ini(plugin, plugin_dir):
 
298
  plugin_ac.write("      ])\n")
 
299
 
 
300
def fix_file_paths(plugin, files):
 
301
  # TODO: determine path to plugin dir relative to top_srcdir... append it to
 
302
  # source files if they don't already have it
 
303
  new_files=""
 
304
  if plugin['plugin_dir'] != ".":
 
305
    for file in files.split():
 
306
      if not file.startswith(plugin['rel_path']):
 
307
        file= os.path.join(plugin['rel_path'], file)
 
308
        new_files= "%s %s" % (new_files, file)
 
309
  else:
 
310
    new_files= " ".join(plugin['sources'].split())
 
311
  if new_files != "":
 
312
    return new_files
 
313
  return files
 
314
 
 
315
def expand_plugin_ini(plugin):
287
316
    if plugin['name'] == "**OUT-OF-TREE**":
288
317
      print "Out of tree plugins require the name field to be specified in plugin.ini"
289
318
      sys.exit(1)
290
319
 
291
 
    if plugin_dir == ".":
292
 
      plugin['rel_path']= plugin_dir
 
320
    if plugin['plugin_dir'] == ".":
 
321
      plugin['rel_path']= plugin['plugin_dir']
293
322
      plugin['unconditional']=True
294
323
    else:
295
 
      plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
 
324
      plugin['rel_path']= plugin['plugin_dir'][len(config['top_srcdir'])+len(os.path.sep):]
296
325
      plugin['unconditional']=False
297
 
    # TODO: determine path to plugin dir relative to top_srcdir... append it to
298
 
    # source files if they don't already have it
299
 
    if plugin['sources'] == "":
300
 
      plugin['sources']="%s.cc" % plugin['name']
301
 
    new_sources=""
302
 
    if plugin_dir != ".":
303
 
      for src in plugin['sources'].split():
304
 
        if not src.startswith(plugin['rel_path']):
305
 
          src= os.path.join(plugin['rel_path'], src)
306
 
          new_sources= "%s %s" % (new_sources, src)
307
 
    else:
308
 
      new_sources= " ".join(plugin['sources'].split())
309
 
    if new_sources != "":
310
 
      plugin['sources']= new_sources
 
326
 
 
327
    plugin['sources']= fix_file_paths(plugin, plugin['sources'])
311
328
    plugin['main_source']= plugin['sources'].split()[0]
312
 
    
313
 
    new_headers=""
314
 
    if plugin_dir != ".":
315
 
      for header in plugin['headers'].split():
316
 
        if not header.startswith(plugin['rel_path']):
317
 
          header= os.path.join(plugin['rel_path'], header)
318
 
          new_headers= "%s %s" % (new_headers, header)
319
 
    else:
320
 
      new_headers= " ".join(plugin['headers'].split())
321
 
    if new_headers != "":
322
 
      plugin['headers']= new_headers
323
 
    
 
329
    plugin['headers']= fix_file_paths(plugin, plugin['headers'])
 
330
    plugin['install_headers']= fix_file_paths(plugin, plugin['install_headers'])
 
331
    plugin['tests']= fix_file_paths(plugin, plugin['tests'])
 
332
 
324
333
    # Make a yes/no version for autoconf help messages
325
334
    if plugin['load_by_default']:
326
335
      plugin['default_yesno']="yes"
327
336
    else:
328
337
      plugin['default_yesno']="no"
329
338
 
330
 
    
 
339
    if plugin.has_key('extra_dist'):
 
340
      plugin['extra_dist']=" ".join([os.path.join(plugin['rel_path'],f) for f in plugin['extra_dist'].split()])
 
341
 
 
342
 
331
343
    plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
332
344
    plugin['name_with_dashes']= plugin['name'].replace('_','-')
333
345
    if plugin.has_key('build_conditional'):
338
350
      plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
339
351
 
340
352
    if plugin['install']:
341
 
      plugin['library_type']= 'pkgplugin';
 
353
      plugin['library_type']= 'pkgplugin'
342
354
    else:
343
 
      plugin['library_type']= 'noinst';
 
355
      plugin['library_type']= 'noinst'
344
356
 
345
357
def find_testsuite(plugin_dir):
346
358
  for testdir in ['drizzle-tests','tests']:
350
362
    return ""
351
363
  return None
352
364
 
 
365
def find_docs(plugin_dir):
 
366
  if os.path.isfile(os.path.join(plugin_dir, "docs", "index.rst")):
 
367
    return os.path.join(plugin_dir, "docs")
 
368
 
353
369
def read_plugin_ini(plugin_dir):
354
370
    if plugin_dir == ".":
355
371
      plugin_name="**OUT-OF-TREE**"
356
372
    else:
357
 
      plugin_name=os.path.basename(plugin_dir)
358
 
 
359
 
    plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
360
 
    plugin_defaults= dict(sources="",
 
373
      short_name=os.path.basename(plugin_dir)
 
374
      plugin_name = plugin_dir[plugin_dir.index(config['root_plugin_dir']) + len(config['root_plugin_dir']) + 1:]
 
375
      module_name = plugin_name.replace("/", config['module_name_separator']).replace("\\", config['module_name_separator'])
 
376
      plugin_name = plugin_name.replace("/", config['plugin_name_separator']).replace("\\", config['plugin_name_separator'])
 
377
 
 
378
 
 
379
    plugin_file= os.path.join(plugin_dir,config['plugin_ini_fname'])
 
380
    plugin_defaults= dict(sources="%s.cc" % short_name,
361
381
                          headers="",
 
382
                          install_headers="",
362
383
                          cflags="",
363
384
                          cppflags="",
364
385
                          cxxflags="",
369
390
                          description="",
370
391
                          license="PLUGIN_LICENSE_GPL",
371
392
                          name=plugin_name,
372
 
                          load_by_default="False",
 
393
                          module_name=module_name,
 
394
                          load_by_default=config['default_load_by_default'],
373
395
                          disabled="False",
374
396
                          static="False",
375
 
                          install=default_install)
 
397
                          dependencies="",
 
398
                          dependency_aliases="",
 
399
                          tests="",
 
400
                          install=config['default_install'])
376
401
    parser=ConfigParser.ConfigParser(defaults= plugin_defaults)
377
402
    parser.read(plugin_file)
378
403
    plugin=dict(parser.items('plugin'))
 
404
    plugin['plugin_dir'] = plugin_dir
379
405
    if plugin_dir == '.':
380
406
      if not plugin.has_key('url'):
381
407
        print "External Plugins are required to specifiy a url"
385
411
        print "External Plugins are required to specifiy a version"
386
412
        sys.exit(1)
387
413
    if not plugin.has_key('version'):
388
 
      plugin['version'] = default_plugin_version
389
 
   
 
414
      plugin['version'] = config['default_plugin_version']
390
415
    if plugin.has_key('load_by_default'):
391
416
      plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
392
417
    if plugin.has_key('disabled'):
396
421
    else:
397
422
      plugin['enabled']="yes"
398
423
    if plugin.has_key('static'):
399
 
      plugin['static']= parser.getboolean('plugin','static')
 
424
      try:
 
425
        plugin['static']= parser.getboolean('plugin','static')
 
426
      except:
 
427
        if plugin['static'][:5] == os.sys.platform[:5]:
 
428
          plugin['static']= True
 
429
        else:
 
430
          plugin['static']= False
400
431
    if plugin.has_key('install'):
401
432
      plugin['install']= parser.getboolean('plugin','install')
402
433
    if plugin.has_key('testsuite'):
403
434
      if plugin['testsuite'] == 'disable':
404
435
        plugin['testsuite']= False
 
436
        plugin['dist_testsuite']= find_testsuite(plugin_dir)
405
437
    else:
406
438
      plugin_testsuite= find_testsuite(plugin_dir)
407
439
      plugin['testsuitedir']=plugin_testsuite
409
441
        plugin['testsuite']=True
410
442
      else:
411
443
        plugin['testsuite']=False
412
 
 
413
 
    plugin['cflags']+= extra_cflags
414
 
    plugin['cppflags']+= extra_cppflags
415
 
    plugin['cxxflags']+= extra_cxxflags
416
 
 
417
 
    plugin['pname']= "lib%s%s%s" % (plugin_prefix, plugin['name'], plugin_suffix)
418
 
    plugin['root_plugin_dir']= root_plugin_dir
419
 
    plugin['plugin_prefix']= plugin_prefix
420
 
    plugin['plugin_suffix']= plugin_suffix
421
 
    plugin['pkgplugindir']= pkgplugindir
422
 
 
 
444
    plugin['docs']= find_docs(plugin_dir)
 
445
 
 
446
    plugin['cflags']+= ' ' + config['extra_cflags']
 
447
    plugin['cppflags']+= ' ' + config['extra_cppflags']
 
448
    plugin['cxxflags']+= ' ' + config['extra_cxxflags']
 
449
 
 
450
    plugin['libname']= "lib%s%s%s" % (config['plugin_prefix'],
 
451
                                      plugin['name'],
 
452
                                      config['plugin_suffix'])
 
453
    if config['force_lowercase_libname']:
 
454
      plugin['libname']= plugin['libname'].lower()
 
455
 
 
456
    plugin['root_plugin_dir']= config['root_plugin_dir']
 
457
    plugin['plugin_prefix']= config['plugin_prefix']
 
458
    plugin['plugin_suffix']= config['plugin_suffix']
 
459
    plugin['pkgplugindir']= config['pkgplugindir']
 
460
 
 
461
    # Dependencies must have a module but dependency aliases are simply added
 
462
    # to the variable passed during compile.
 
463
    plugin['dependency_list'] = plugin['dependencies'].split()
 
464
    dependency_aliases = plugin['dependency_aliases'].split()
 
465
    plugin['dependencies'] = ','.join(plugin['dependency_list'] +
 
466
                                      plugin['dependency_aliases'].split())
 
467
    dependency_libs = ["%s/lib%s%s.la" % (config['root_plugin_dir'],
 
468
                                          dependency.lower().replace('::', '_'),
 
469
                                          config['plugin_suffix'])
 
470
                       for dependency in plugin['dependency_list']]
 
471
    plugin['libs'] = " ".join(plugin['libs'].split() + dependency_libs);
 
472
 
 
473
# Libtool is going to expand:
 
474
#      -DPANDORA_MODULE_AUTHOR='"Padraig O'"'"'Sullivan"'
 
475
# to:
 
476
# "-DPANDORA_MODULE_AUTHOR=\"Padraig O'Sullivan\""
 
477
# So we have to replace internal ''s to '"'"'
 
478
    for key in ('author','title','description','version'):
 
479
      plugin[key]=plugin[key].replace('"','\\"')
 
480
      plugin[key]=plugin[key].replace("'","'\"'\"'")
423
481
    return plugin
424
482
 
425
483
 
426
484
def write_plugin_am(plugin, plugin_am):
427
485
  """Write an automake fragment for this plugin.
428
 
  
 
486
 
429
487
  :param plugin: The plugin dict.
430
488
  :param plugin_am: The file to write to.
431
489
  """
438
496
%(rel_path)s/plugin.ini:
439
497
 
440
498
""" % plugin)
 
499
  if plugin.has_key('extra_dist') and plugin['extra_dist'] != "":
 
500
    plugin_am.write("EXTRA_DIST += %(extra_dist)s\n" % plugin)
441
501
  if plugin['headers'] != "":
442
502
    plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
 
503
  if plugin['install_headers'] != "":
 
504
    plugin_am.write("nobase_include_HEADERS += %(install_headers)s\n" % plugin)
443
505
  if plugin['testsuite']:
444
506
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
445
507
      plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin)
 
508
  if plugin.has_key('dist_testsuite') and plugin['dist_testsuite'] != "":
 
509
    plugin_am.write("EXTRA_DIST += %(rel_path)s/%(dist_testsuite)s\n" % plugin)
 
510
  if plugin['docs'] is not None:
 
511
    plugin_am.write("EXTRA_DIST += ${top_srcdir}/%(rel_path)s/docs/*.rst\n" % plugin)
446
512
  if plugin['static']:
447
513
    plugin_am.write("""
448
514
%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
449
515
EXTRA_DIST += %(rel_path)s/plugin.ini
450
516
if %(build_conditional_tag)s
451
 
  noinst_LTLIBRARIES+=%(root_plugin_dir)s/%(pname)s.la
452
 
  %(root_plugin_dir)s_%(pname)s_la_LIBADD=%(libs)s
453
 
  %(root_plugin_dir)s_%(pname)s_la_DEPENDENCIES=%(libs)s
454
 
  %(root_plugin_dir)s_%(pname)s_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
455
 
  %(root_plugin_dir)s_%(pname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_MODULE_NAME=%(name)s -DPANDORA_MODULE_AUTHOR="%(author)s" -DPANDORA_MODULE_TITLE="%(title)s" -DPANDORA_MODULE_VERSION="%(version)s" -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s
456
 
  %(root_plugin_dir)s_%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
457
 
  %(root_plugin_dir)s_%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
458
 
 
459
 
  %(root_plugin_dir)s_%(pname)s_la_SOURCES=%(sources)s
460
 
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/%(root_plugin_dir)s/%(pname)s.la
 
517
  noinst_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la
 
518
  %(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s
 
519
  %(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s
 
520
  %(root_plugin_dir)s_%(libname)s_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
 
521
  %(root_plugin_dir)s_%(libname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_MODULE_NAME=%(module_name)s -DPANDORA_MODULE_AUTHOR='"%(author)s"' -DPANDORA_MODULE_TITLE='"%(title)s"' -DPANDORA_MODULE_VERSION='"%(version)s"' -DPANDORA_MODULE_LICENSE=%(license)s -DPANDORA_MODULE_DEPENDENCIES='"%(dependencies)s"' %(cppflags)s
 
522
  %(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
 
523
  %(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
 
524
  %(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s
 
525
  check_PROGRAMS += %(tests)s
 
526
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/%(root_plugin_dir)s/%(libname)s.la
461
527
endif
462
528
""" % plugin)
463
529
  else:
465
531
%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
466
532
EXTRA_DIST += %(rel_path)s/plugin.ini
467
533
if %(build_conditional_tag)s
468
 
  %(library_type)s_LTLIBRARIES+=%(root_plugin_dir)s/%(pname)s.la
469
 
  %(root_plugin_dir)s_%(pname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
470
 
  %(root_plugin_dir)s_%(pname)s_la_LIBADD=%(libs)s
471
 
  %(root_plugin_dir)s_%(pname)s_la_DEPENDENCIES=%(libs)s
472
 
  %(root_plugin_dir)s_%(pname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(name)s -DPANDORA_MODULE_AUTHOR="%(author)s" -DPANDORA_MODULE_TITLE="%(title)s" -DPANDORA_MODULE_VERSION="%(version)s" -DPANDORA_MODULE_LICENSE=%(license)s %(cppflags)s
473
 
  %(root_plugin_dir)s_%(pname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
474
 
  %(root_plugin_dir)s_%(pname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
475
 
 
476
 
  %(root_plugin_dir)s_%(pname)s_la_SOURCES=%(sources)s
 
534
  %(library_type)s_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la
 
535
  %(root_plugin_dir)s_%(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
 
536
  %(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s
 
537
  %(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s
 
538
  %(root_plugin_dir)s_%(libname)s_la_CPPFLAGS=$(AM_CPPFLAGS) -DPANDORA_DYNAMIC_PLUGIN -DPANDORA_MODULE_NAME=%(module_name)s -DPANDORA_MODULE_AUTHOR='"%(author)s"' -DPANDORA_MODULE_TITLE='"%(title)s"' -DPANDORA_MODULE_VERSION='"%(version)s"' -DPANDORA_MODULE_LICENSE=%(license)s -DPANDORA_MODULE_DEPENDENCIES='"%(dependencies)s"' %(cppflags)s
 
539
  %(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
 
540
  %(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
 
541
  %(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s
 
542
  check_PROGRAMS += %(tests)s
477
543
endif
478
544
""" % plugin)
479
545
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
480
546
  if os.path.exists(plugin_am_file):
481
547
    plugin_am.write('include %s\n' % plugin_am_file)
482
548
 
483
 
#MAIN STARTS HERE:
 
549
#
 
550
# MAIN STARTS HERE:
 
551
#
 
552
 
 
553
# Parse the pandora-plugin config file
 
554
 
 
555
config_defaults= dict(
 
556
  top_srcdir='.',
 
557
  top_builddir='.',
 
558
  plugin_ini_fname='plugin.ini',
 
559
  plugin_prefix='',
 
560
  plugin_suffix='',
 
561
  extra_cflags='',
 
562
  extra_cppflags='',
 
563
  extra_cxxflags='',
 
564
  root_plugin_dir='',
 
565
  pkgplugindir='',
 
566
  default_install='True',
 
567
  default_plugin_version='',
 
568
  default_load_by_default='False',
 
569
  force_lowercase_libname='True',
 
570
  plugin_name_separator='_',
 
571
  module_name_separator='::'
 
572
)
 
573
 
 
574
config_parser = ConfigParser.ConfigParser(defaults=config_defaults)
 
575
config_parser.read(pandora_plugin_file)
 
576
config = dict(config_parser.items('pandora-plugin'))
 
577
config['force_lowercase_libname']=config_parser.getboolean('pandora-plugin','force_lowercase_libname')
484
578
 
485
579
# I'm 3 seconds away from writing a comprehensive build solution
486
580
if not os.path.exists('config/pandora_vc_revinfo'):
487
581
  if os.path.exists('.bzr'):
488
582
    bzr_revno= subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE).communicate()[0].strip()
489
583
    rev_date= datetime.date.fromtimestamp(time.time())
490
 
    default_plugin_version = "%d.%02d.%s" % (rev_date.year, rev_date.month, bzr_revno)
 
584
    config['default_plugin_version'] = "%d.%02d.%s" % (rev_date.year, rev_date.month, bzr_revno)
491
585
  else:
492
 
    default_plugin_version=datetime.date.fromtimestamp(time.time()).isoformat()
 
586
    config['default_plugin_version']=datetime.date.fromtimestamp(time.time()).isoformat()
493
587
else:
494
588
  # need to read config/pandora_vc_revno
495
589
  pandora_vc_revno=open('config/pandora_vc_revinfo','r').read().split()
502
596
    elif revno_key == 'PANDORA_RELEASE_DATE':
503
597
      rev_date=revno_val.strip()
504
598
 
505
 
  default_plugin_version = "%s.%s" % (rev_date, bzr_revno)
 
599
  config['default_plugin_version'] = "%s.%s" % (rev_date, bzr_revno)
506
600
 
507
601
actions=[]
508
602
for arg in sys.argv:
509
603
  if arg.startswith('--top_srcdir='):
510
 
    top_srcdir=arg[12:]
 
604
    config['top_srcdir']=arg[12:]
511
605
  elif arg.startswith('--top_builddir='):
512
 
    top_builddir=arg[14:]
 
606
    config['top_builddir']=arg[14:]
513
607
  elif arg == "--force-all":
514
608
    actions=['plugin-list','pandora-plugin.am','write']
515
609
    break
518
612
if len(actions) == 0:
519
613
  actions.append('write')
520
614
 
 
615
plugin_list=[]
 
616
 
521
617
def accumulate_plugins(arg, dirname, fnames):
522
618
  # plugin_ini_fname is a name in dirname indicating dirname is a plugin.
523
 
  if plugin_ini_fname in fnames:
 
619
  if config['plugin_ini_fname'] in fnames:
524
620
    arg.append(dirname)
525
 
os.path.walk(os.path.join(top_srcdir,root_plugin_dir),accumulate_plugins,plugin_list)
526
621
 
 
622
os.path.walk(os.path.join(config['top_srcdir'],
 
623
                          config['root_plugin_dir']),
 
624
             accumulate_plugins,
 
625
             plugin_list)
527
626
 
528
627
if not os.path.exists("config/pandora-plugin.am") or "write" in actions:
529
628
  plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am'))
541
640
EXTRA_DIST += \
542
641
        config/pandora-plugin.am \
543
642
        config/pandora-plugin.ac \
544
 
        config/pandora-plugin
 
643
        config/pandora-plugin \
 
644
        config/pandora-plugin.ini
545
645
 
546
646
 
547
647
# Seed the list of plugin LDADDS which plugins may extend.
554
654
  plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac'))
555
655
  plugin_ac_file.write("dnl Generated file, run make to rebuild\n")
556
656
 
 
657
if os.path.exists("docs/plugins"):
 
658
  if not os.path.exists("docs/plugins/list.rst") or "write" in actions:
 
659
    plugin_doc_index = ChangeProtectedFile("docs/plugins/list.rst")
 
660
    plugin_doc_index.write("""
 
661
Plugin Documentation
 
662
====================
 
663
 
 
664
.. toctree::
 
665
   :maxdepth: 2
 
666
""")
 
667
 
557
668
 
558
669
if os.path.exists('plugin.ini'):
559
670
  # Are we in a plugin dir which wants to have a self-sufficient build system?
573
684
  for plugin_dir in plugin_list:
574
685
    plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir)
575
686
  plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n")
 
687
  plugin_ini_list=[]
 
688
 
 
689
  # Load all plugin.ini files first so we can do dependency tracking.
576
690
  for plugin_dir in plugin_list:
577
 
    write_plugin(plugin_dir)
 
691
    plugin = read_plugin_ini(plugin_dir)
 
692
    expand_plugin_ini(plugin)
 
693
    plugin_ini_list.append(plugin)
 
694
 
 
695
  # Check for duplicates
 
696
  plugin_name_list = [plugin['libname'] for plugin in plugin_ini_list]
 
697
  for plugin in plugin_ini_list:
 
698
    if plugin_name_list.count(plugin['libname']) != 1:
 
699
      print "Duplicate module name %s" % plugin['libname']
 
700
      exit(1)
 
701
 
 
702
  for plugin in plugin_ini_list:
 
703
    write_plugin(plugin, plugin_ini_list)
578
704
 
579
705
if plugin_am_file is not None:
580
706
  plugin_am_file.close()
581
707
if plugin_ac_file is not None:
582
708
  plugin_ac_file.close()
 
709
if plugin_doc_index is not None:
 
710
  plugin_doc_index.close()