1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
|
#!/usr/bin/python
# Copyright (C) 2009 Sun Microsystems, Inc.
# Copyright (C) 2010, 2011 Monty Taylor
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
pandora_plugin_file = 'config/pandora-plugin.ini'
# Find plugins in the tree and add them to the build system
import ConfigParser, os, sys
import datetime, time
import subprocess
plugin_am_file=None
plugin_ac_file=None
plugin_doc_index=None
class ChangeProtectedFile(object):
def __init__(self, fname):
self.bogus_file= False
self.real_fname= fname
self.new_fname= "%s.new" % fname
try:
self.new_file= open(self.new_fname,'w+')
except IOError:
self.bogus_file= True
def write(self, text):
if not self.bogus_file:
self.new_file.write(text)
# We've written all of this out into .new files, now we only copy them
# over the old ones if they are different, so that we don't cause
# unnecessary recompiles
def close(self):
"""Return True if the file had changed."""
if self.bogus_file:
return
self.new_file.seek(0)
new_content = self.new_file.read()
self.new_file.close()
try:
old_file = file(self.real_fname, 'r')
old_content = old_file.read()
old_file.close()
except IOError:
old_content = None
if new_content != old_content:
if old_content != None:
os.unlink(self.real_fname)
os.rename(self.new_fname, self.real_fname)
return True
else:
try:
os.unlink(self.new_fname)
except:
pass
def write_external_configure(plugin, plugin_file):
"""Write the initial bits of the configure.ac file"""
if not os.path.exists('m4'):
os.mkdir('m4')
plugin_file.write("""
AC_PREREQ(2.59)dnl Minimum Autoconf version required.
AC_INIT([%(name)s],[%(version)s],[%(url)s])
AC_CONFIG_SRCDIR([%(main_source)s])
AC_CONFIG_AUX_DIR(config)
PANDORA_CANONICAL_TARGET(less-warnings, warnings-always-on, require-cxx, force-gcc42,skip-visibility)
PANDORA_REQUIRE_LIBPROTOBUF
PANDORA_PROTOBUF_REQUIRE_VERSION([2.1.0])
PANDORA_REQUIRE_PROTOC
AC_LANG_PUSH(C++)
PANDORA_REQUIRE_PTHREAD
PANDORA_REQUIRE_LIBDL
AC_LANG_POP
PANDORA_USE_BETTER_MALLOC
PANDORA_DRIZZLE_BUILD
""" % plugin)
write_plugin_ac(plugin, plugin_file)
plugin_file.write("""
AC_CONFIG_FILES(Makefile)
AC_OUTPUT
echo "---"
echo "Configuration summary for $PACKAGE_NAME version $VERSION $PANDORA_RELEASE_COMMENT"
echo ""
echo " * Installation prefix: $prefix"
echo " * System type: $host_vendor-$host_os"
echo " * Host CPU: $host_cpu"
echo " * C Compiler: $CC_VERSION"
echo " * C++ Compiler: $CXX_VERSION"
echo " * Debug enabled: $with_debug"
echo " * Warnings as failure: $ac_cv_warnings_as_errors"
echo " * C++ cstdint location: $ac_cv_cxx_cstdint"
echo " * C++ hash_map location: $ac_cv_cxx_hash_map"
echo " * C++ hash namespace: $ac_cv_cxx_hash_namespace"
echo " * C++ shared_ptr namespace: $ac_cv_shared_ptr_namespace"
echo ""
echo "---"
""" % plugin)
def write_external_makefile(plugin, plugin_file):
plugin_file.write("""
ACLOCAL_AMFLAGS = -I m4 --force
VERSION=$(PANDORA_RELEASE_VERSION)
pkgplugindir=%(pkgplugindir)s
EXTRA_DIST = plugin.ini
noinst_HEADERS=
nobase_include_HEADERS=
nobase_pkginclude_HEADERS=
check_PROGRAMS=
noinst_LTLIBRARIES=
bin_PROGRAMS=
""" % plugin)
if plugin['headers'] != "":
plugin_file.write("noinst_HEADERS += %(headers)s\n" % plugin)
if plugin['install_headers'] != "":
plugin_file.write("nobase_pkginclude_HEADERS += %(install_headers)s\n" % plugin)
if plugin['testsuite']:
if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin)
plugin_file.write("""
pkgplugin_LTLIBRARIES=%(libname)s.la
%(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
%(libname)s_la_LIBADD=%(libs)s
%(libname)s_la_DEPENDENCIES=%(libs)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 %(cppflags)s
%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
%(libname)s_la_SOURCES=%(sources)s
check_PROGRAMS += %(tests)s
""" % plugin)
plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
if os.path.exists(plugin_am_file):
plugin_file.write('include %s\n' % plugin_am_file)
def write_external_plugin():
"""Return True if the plugin had changed."""
plugin = read_plugin_ini('.')
expand_plugin_ini(plugin)
plugin_file = ChangeProtectedFile('configure.ac')
write_external_configure(plugin, plugin_file)
result = plugin_file.close()
plugin_file = ChangeProtectedFile('Makefile.am')
write_external_makefile(plugin, plugin_file)
# Write some stub configure.ac and Makefile.am files that include the above
result = plugin_file.close() or result
return result
def write_plugin(plugin, plugin_ini_list):
# Since this function is recursive, make sure we're not already in it.
if plugin.has_key('writing_status'):
if plugin['writing_status'] == 'done':
return
else:
print "Dependency loop detected with %s" % plugin['name']
exit(1)
plugin['writing_status'] = 'dependencies'
# Write all dependencies first to get around annoying automake bug
for dependency in plugin['dependency_list']:
found = False
for find_plugin in plugin_ini_list:
if find_plugin['module_name'] == dependency:
found = True
write_plugin(find_plugin, plugin_ini_list)
break
if found is False:
print "Could not find dependency %s: %s" % (plugin['name'], dependency)
exit(1)
write_plugin_ac(plugin, plugin_ac_file)
write_plugin_am(plugin, plugin_am_file)
write_plugin_docs(plugin, plugin_doc_index, plugin_am_file)
plugin['writing_status'] = 'done'
def write_plugin_docs(plugin, doc_index, plugin_am):
if plugin['docs'] is not None and os.path.isdir("docs/plugins"):
if not os.path.exists(os.path.join("docs/plugins",plugin["name"])):
os.symlink(os.path.abspath(plugin["docs"]), os.path.join("docs/plugins",plugin["name"]))
doc_index.write("""
%(name)s/index""" % plugin)
plugin_am.write("""
EXTRA_DIST+=${top_srcdir}/docs/plugins/%(name)s/*.rst
""" % plugin)
def write_plugin_ac(plugin, plugin_ac):
#
# Write plugin config instructions into plugin.ac file.
#
plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
plugin_m4_files=[]
if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
for m4_file in os.listdir(plugin_m4_dir):
if os.path.splitext(m4_file)[-1] == '.m4':
plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
plugin_ac.write("""
dnl Config for %(title)s
""" % plugin)
for m4_file in plugin_m4_files:
plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
plugin_ac.write("""
AC_ARG_WITH([%(name_with_dashes)s-plugin],[
dnl indented wierd to make the help output correct
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(enabled)s@:>@])
AS_HELP_STRING([--without-%(name_with_dashes)s-plugin],[Disable building %(title)s])
],[
with_%(name)s_plugin="$withval"
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],[
requested_%(name)s_plugin="yes"
],[
requested_%(name)s_plugin="no"
])
],[
with_%(name)s_plugin="%(enabled)s"
requested_%(name)s_plugin="no"
])
AC_ARG_WITH([static-%(name_with_dashes)s-plugin],[
AS_HELP_STRING([--with-static-%(name_with_dashes)s-plugin],[Build Archive Storage Engine. @<:@default=%(static_yesno)s@:>@])
AS_HELP_STRING([--without-static-%(name_with_dashes)s-plugin],[Disable building Archive Storage Engine])
],[
with_static_%(name)s_plugin=${withval}
],[
with_static_%(name)s_plugin=%(static_yesno)s
])
AS_IF([test "x${with_static_%(name)s_plugin}" = "xyes" -o "x${with_all_static}" = "xyes"],[
shared_%(name)s_plugin=no
],[
shared_%(name)s_plugin=yes
])
AC_ARG_ENABLE([%(name_with_dashes)s-plugin],[
dnl indented wierd to make the help output correct
AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Enable loading %(title)s by default. @<:@default=%(default_yesno)s@:>@])
AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable loading %(title)s by default.])
],
[enable_%(name)s_plugin="$enableval"],
[enable_%(name)s_plugin=%(default_yesno)s])
""" % plugin)
if os.path.exists(plugin_ac_file):
plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file)
# The plugin author has specified some check to make to determine
# if the plugin can be built. If the plugin is turned on and this
# check fails, then configure should error out. If the plugin is not
# turned on, then the normal conditional build stuff should just let
# it silently not build
if plugin['has_build_conditional']:
plugin_ac.write("""
AS_IF([test %(build_conditional)s],
[], dnl build_conditional can only negate
[
AS_IF([test "x${requested_%(name)s_plugin}" = "xyes"],
[AC_MSG_ERROR([Plugin %(name)s was explicitly requested, yet failed build dependency checks. Aborting!])])
with_%(name)s_plugin=no
])
""" % plugin)
if not plugin['unconditional']:
plugin_ac.write("""
AM_CONDITIONAL([%(static_build_conditional_tag)s],
[test %(build_conditional)s -a ! %(shared_build)s])
AM_CONDITIONAL([%(shared_build_conditional_tag)s],
[test %(build_conditional)s -a %(shared_build)s])
AM_CONDITIONAL([%(build_conditional_tag)s],
[test %(build_conditional)s])
""" % plugin)
plugin_ac.write("""
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],[
""" % plugin)
if plugin['testsuite']:
plugin_ac.write("""
pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
""" % plugin)
plugin_ac.write("""
AS_IF([test "x${with_static_%(name)s_plugin}" = "xyes" -o "x${with_all_static}" = "xyes"],[
AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
pandora_builtin_load_list="%(module_name)s,${pandora_builtin_load_list}"
pandora_builtin_load_symbols_list="_drizzled_%(module_name)s_plugin_,${pandora_builtin_load_symbols_list}"
PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
])
pandora_builtin_list="%(module_name)s,${pandora_builtin_list}"
pandora_builtin_symbols_list="_drizzled_%(module_name)s_plugin_,${pandora_builtin_symbols_list}"
pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/%(root_plugin_dir)s/%(libname)s.la"
],[
AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
])
])
""" % plugin)
plugin_ac.write("])\n")
def fix_file_paths(plugin, files):
# TODO: determine path to plugin dir relative to top_srcdir... append it to
# source files if they don't already have it
new_files=""
if plugin['plugin_dir'] != ".":
for file in files.split():
if not file.startswith(plugin['rel_path']):
file= os.path.join(plugin['rel_path'], file)
new_files= "%s %s" % (new_files, file)
else:
new_files= " ".join(plugin['sources'].split())
if new_files != "":
return new_files
return files
def expand_plugin_ini(plugin):
if plugin['name'] == "**OUT-OF-TREE**":
print "Out of tree plugins require the name field to be specified in plugin.ini"
sys.exit(1)
if plugin['plugin_dir'] == ".":
plugin['rel_path']= plugin['plugin_dir']
plugin['unconditional']=True
else:
plugin['rel_path']= plugin['plugin_dir'][len(config['top_srcdir'])+len(os.path.sep):]
plugin['unconditional']=False
plugin['sources']= fix_file_paths(plugin, plugin['sources'])
plugin['main_source']= plugin['sources'].split()[0]
plugin['headers']= fix_file_paths(plugin, plugin['headers'])
plugin['install_headers']= fix_file_paths(plugin, plugin['install_headers'])
plugin['tests']= fix_file_paths(plugin, plugin['tests'])
# Make a yes/no version for autoconf help messages
if plugin['load_by_default']:
plugin['default_yesno']="yes"
else:
plugin['default_yesno']="no"
if plugin.has_key('extra_dist'):
plugin['extra_dist']=" ".join([os.path.join(plugin['rel_path'],f) for f in plugin['extra_dist'].split()])
if plugin['static']:
plugin['static_yesno']="yes"
else:
plugin['static_yesno']="no"
plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
plugin['shared_build_conditional_tag']= "BUILD_%s_PLUGIN_SHARED" % plugin['name'].upper()
plugin['static_build_conditional_tag']= "BUILD_%s_PLUGIN_STATIC" % plugin['name'].upper()
plugin['name_with_dashes']= plugin['name'].replace('_','-')
if plugin.has_key('build_conditional'):
plugin['has_build_conditional']=True
plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes" -a %(build_conditional)s' % plugin
else:
plugin['has_build_conditional']=False
plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
plugin['shared_build']='"x${shared_%(name)s_plugin}" = "xyes"' %plugin
if plugin['install']:
plugin['library_type']= 'pkgplugin'
else:
plugin['library_type']= 'noinst'
def find_testsuite(plugin_dir):
for testdir in ['drizzle-tests','tests']:
if os.path.isdir(os.path.join(plugin_dir,testdir)):
return testdir
if os.path.isdir(os.path.join('tests','suite',os.path.basename(plugin_dir))):
return ""
return None
def find_docs(plugin_dir):
if os.path.isfile(os.path.join(plugin_dir, "docs", "index.rst")):
return os.path.join(plugin_dir, "docs")
def read_plugin_ini(plugin_dir):
sources_default=""
if plugin_dir == ".":
plugin_name="**OUT-OF-TREE**"
module_name="**OUT-OF-TREE**"
else:
sources_default="%s.cc" % os.path.basename(plugin_dir)
plugin_name = plugin_dir[plugin_dir.index(config['root_plugin_dir']) + len(config['root_plugin_dir']) + 1:]
module_name = plugin_name.replace("/", config['module_name_separator']).replace("\\", config['module_name_separator'])
plugin_name = plugin_name.replace("/", config['plugin_name_separator']).replace("\\", config['plugin_name_separator'])
plugin_file= os.path.join(plugin_dir,config['plugin_ini_fname'])
plugin_defaults= dict(sources=sources_default,
headers="",
install_headers="",
cflags="",
cppflags="",
cxxflags="",
libs="",
ldflags="",
author="",
title="",
description="",
license="PLUGIN_LICENSE_GPL",
name=plugin_name,
module_name=module_name,
load_by_default=config['default_load_by_default'],
disabled="False",
static="False",
dependencies="",
dependency_aliases="",
tests="",
install=config['default_install'])
parser=ConfigParser.ConfigParser(defaults= plugin_defaults)
parser.read(plugin_file)
plugin=dict(parser.items('plugin'))
plugin['plugin_dir'] = plugin_dir
if plugin_dir == '.':
if not plugin.has_key('url'):
print "External Plugins are required to specifiy a url"
plugin['url']= 'http://launchpad.net/%(name)s' % plugin
sys.exit(1)
if plugin_dir == '.' and not plugin.has_key('version'):
print "External Plugins are required to specifiy a version"
sys.exit(1)
if not plugin.has_key('version'):
plugin['version'] = config['default_plugin_version']
if plugin.has_key('load_by_default'):
plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
if plugin.has_key('disabled'):
plugin['disabled']=parser.getboolean('plugin','disabled')
if plugin['disabled']:
plugin['enabled']="no"
else:
plugin['enabled']="yes"
if plugin.has_key('static'):
try:
plugin['static']= parser.getboolean('plugin','static')
except:
if plugin['static'][:5] == os.sys.platform[:5]:
plugin['static']= True
else:
plugin['static']= False
if plugin.has_key('install'):
plugin['install']= parser.getboolean('plugin','install')
if plugin.has_key('testsuite'):
if plugin['testsuite'] == 'disable':
plugin['testsuite']= False
plugin['dist_testsuite']= find_testsuite(plugin_dir)
else:
plugin_testsuite= find_testsuite(plugin_dir)
plugin['testsuitedir']=plugin_testsuite
if plugin_testsuite is not None:
plugin['testsuite']=True
else:
plugin['testsuite']=False
plugin['docs']= find_docs(plugin_dir)
plugin['cflags']+= ' ' + config['extra_cflags']
plugin['cppflags']+= ' ' + config['extra_cppflags']
plugin['cxxflags']+= ' ' + config['extra_cxxflags']
plugin['libname']= "lib%s%s%s" % (config['plugin_prefix'],
plugin['name'],
config['plugin_suffix'])
if config['force_lowercase_libname']:
plugin['libname']= plugin['libname'].lower()
plugin['root_plugin_dir']= config['root_plugin_dir']
plugin['plugin_prefix']= config['plugin_prefix']
plugin['plugin_suffix']= config['plugin_suffix']
plugin['pkgplugindir']= config['pkgplugindir']
# Dependencies must have a module but dependency aliases are simply added
# to the variable passed during compile.
plugin['dependency_list'] = plugin['dependencies'].split()
dependency_aliases = plugin['dependency_aliases'].split()
plugin['dependencies'] = ','.join(plugin['dependency_list'] +
plugin['dependency_aliases'].split())
dependency_libs = ["%s/lib%s%s.la" % (config['root_plugin_dir'],
dependency.lower().replace('::', '_'),
config['plugin_suffix'])
for dependency in plugin['dependency_list']]
plugin['libs'] = " ".join(plugin['libs'].split() + dependency_libs);
# Libtool is going to expand:
# -DPANDORA_MODULE_AUTHOR='"Padraig O'"'"'Sullivan"'
# to:
# "-DPANDORA_MODULE_AUTHOR=\"Padraig O'Sullivan\""
# So we have to replace internal ''s to '"'"'
for key in ('author','title','description','version'):
plugin[key]=plugin[key].replace('"','\\"')
plugin[key]=plugin[key].replace("'","'\"'\"'")
return plugin
def write_plugin_am(plugin, plugin_am):
"""Write an automake fragment for this plugin.
:param plugin: The plugin dict.
:param plugin_am: The file to write to.
"""
# The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can
# confuse VCS systems.
plugin_am.write("""
EXTRA_DIST += %(rel_path)s/plugin.ini
# Prevent errors when a plugin dir is removed
%(rel_path)s/plugin.ini:
""" % plugin)
if plugin.has_key('extra_dist') and plugin['extra_dist'] != "":
plugin_am.write("EXTRA_DIST += %(extra_dist)s\n" % plugin)
if plugin['headers'] != "":
plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
if plugin['install_headers'] != "":
plugin_am.write("nobase_pkginclude_HEADERS += %(install_headers)s\n" % plugin)
if plugin['testsuite']:
if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin)
if plugin.has_key('dist_testsuite') and plugin['dist_testsuite'] != "":
plugin_am.write("EXTRA_DIST += %(rel_path)s/%(dist_testsuite)s\n" % plugin)
if plugin['docs'] is not None:
plugin_am.write("EXTRA_DIST += ${top_srcdir}/%(rel_path)s/docs/*.rst\n" % plugin)
plugin_am.write("""
%(root_plugin_dir)s_%(plugin_prefix)s%(name)s_dir=${top_srcdir}/%(rel_path)s
# Include sources in EXTRA_DIST because we might not build this, but we
# still want the sources to wind up in a tarball
EXTRA_DIST += %(rel_path)s/plugin.ini %(sources)s
if %(static_build_conditional_tag)s
noinst_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la
%(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s
%(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s
%(root_plugin_dir)s_%(libname)s_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
%(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
%(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
%(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
%(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s
check_PROGRAMS += %(tests)s
PANDORA_DYNAMIC_LDADDS+=${top_builddir}/%(root_plugin_dir)s/%(libname)s.la
endif
EXTRA_DIST += %(rel_path)s/plugin.ini
if %(shared_build_conditional_tag)s
%(library_type)s_LTLIBRARIES+=%(root_plugin_dir)s/%(libname)s.la
%(root_plugin_dir)s_%(libname)s_la_LDFLAGS=-avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
%(root_plugin_dir)s_%(libname)s_la_LIBADD=%(libs)s
%(root_plugin_dir)s_%(libname)s_la_DEPENDENCIES=%(libs)s
%(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
%(root_plugin_dir)s_%(libname)s_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
%(root_plugin_dir)s_%(libname)s_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
%(root_plugin_dir)s_%(libname)s_la_SOURCES=%(sources)s
check_PROGRAMS += %(tests)s
endif
""" % plugin)
plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
if os.path.exists(plugin_am_file):
plugin_am.write('include %s\n' % plugin_am_file)
#
# MAIN STARTS HERE:
#
# Parse the pandora-plugin config file
config_defaults= dict(
top_srcdir='.',
top_builddir='.',
plugin_ini_fname='plugin.ini',
plugin_prefix='',
plugin_suffix='',
extra_cflags='',
extra_cppflags='',
extra_cxxflags='',
root_plugin_dir='',
pkgplugindir='',
default_install='True',
default_plugin_version='',
default_load_by_default='False',
force_lowercase_libname='True',
plugin_name_separator='_',
module_name_separator='::'
)
config_parser = ConfigParser.ConfigParser(defaults=config_defaults)
config_parser.read(pandora_plugin_file)
config = dict(config_parser.items('pandora-plugin'))
config['force_lowercase_libname']=config_parser.getboolean('pandora-plugin','force_lowercase_libname')
# I'm 3 seconds away from writing a comprehensive build solution
if not os.path.exists('config/pandora_vc_revinfo'):
if os.path.exists('.bzr'):
bzr_revno= subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE).communicate()[0].strip()
rev_date= datetime.date.fromtimestamp(time.time())
config['default_plugin_version'] = "%d.%02d.%s" % (rev_date.year, rev_date.month, bzr_revno)
else:
config['default_plugin_version']=datetime.date.fromtimestamp(time.time()).isoformat()
else:
# need to read config/pandora_vc_revno
pandora_vc_revno=open('config/pandora_vc_revinfo','r').read().split()
rev_date=""
bzr_revno=""
for revno_line in pandora_vc_revno:
(revno_key,revno_val)= revno_line.split("=")
if revno_key == 'PANDORA_VC_REVNO':
bzr_revno=revno_val.strip()
elif revno_key == 'PANDORA_RELEASE_DATE':
rev_date=revno_val.strip()
config['default_plugin_version'] = "%s.%s" % (rev_date, bzr_revno)
actions=[]
for arg in sys.argv:
if arg.startswith('--top_srcdir='):
config['top_srcdir']=arg[12:]
elif arg.startswith('--top_builddir='):
config['top_builddir']=arg[14:]
elif arg == "--force-all":
actions=['plugin-list','pandora-plugin.am','write']
break
else:
actions.append(arg)
if len(actions) == 0:
actions.append('write')
plugin_list=[]
def accumulate_plugins(arg, dirname, fnames):
# plugin_ini_fname is a name in dirname indicating dirname is a plugin.
if config['plugin_ini_fname'] in fnames:
arg.append(dirname)
os.path.walk(os.path.join(config['top_srcdir'],
config['root_plugin_dir']),
accumulate_plugins,
plugin_list)
if not os.path.exists("config/pandora-plugin.am") or "write" in actions:
plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am'))
plugin_am_file.write("""
# always the current list, generated every build so keep this lean.
# pandora-plugin.list: datestamp preserved list
${srcdir}/config/pandora-plugin.list: .plugin.scan
.plugin.scan:
@cd ${top_srcdir} && python config/pandora-plugin plugin-list
# Plugins affect configure; so to prevent configure running twice in a tarball
# build (once up front, once with the right list of plugins, we ship the
# generated list of plugins and the housekeeping material for that list so it
# is likewise not updated.
EXTRA_DIST += \
config/pandora-plugin.am \
config/pandora-plugin.ac \
config/pandora-plugin \
config/pandora-plugin.ini
# Seed the list of plugin LDADDS which plugins may extend.
PANDORA_DYNAMIC_LDADDS=
# plugin.stamp: graph dominator for creating all per pandora-plugin.ac/am
# files. This is invoked when the code to generate such files has altered.""")
if not os.path.exists("config/pandora-plugin.ac") or "write" in actions:
plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac'))
plugin_ac_file.write("dnl Generated file, run make to rebuild\n")
plugin_ac_file.write("""
AC_ARG_WITH([all-static],[
AS_HELP_STRING([--with-all-static],[Link all plugins staticly into the server @<:@default=no@:>@])
],[
with_all_static="$withval"
],[
with_all_static=no
])
""")
if os.path.exists("docs/plugins"):
if not os.path.exists("docs/plugins/list.rst") or "write" in actions:
plugin_doc_index = ChangeProtectedFile("docs/plugins/list.rst")
plugin_doc_index.write("""
Plugin Documentation
====================
.. toctree::
:maxdepth: 2
""")
if os.path.exists('plugin.ini'):
# Are we in a plugin dir which wants to have a self-sufficient build system?
plugin_list=['.']
write_external_plugin()
else:
plugin_list_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.list'))
for p in plugin_list:
plugin_list_file.write(p)
plugin_list_file.write("\n")
plugin_list.sort()
plugin_list_file.close()
if not os.path.exists("config/pandora-plugin.am") or 'write' in actions:
plugin_am_file.write("\n${top_srcdir}/config/pandora-plugin.am: ${top_srcdir}/config/pandora-plugin.list ${top_srcdir}/config/pandora-plugin ")
for plugin_dir in plugin_list:
plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir)
plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n")
plugin_ini_list=[]
# Load all plugin.ini files first so we can do dependency tracking.
for plugin_dir in plugin_list:
plugin = read_plugin_ini(plugin_dir)
expand_plugin_ini(plugin)
plugin_ini_list.append(plugin)
# Check for duplicates
plugin_name_list = [plugin['libname'] for plugin in plugin_ini_list]
for plugin in plugin_ini_list:
if plugin_name_list.count(plugin['libname']) != 1:
print "Duplicate module name %s" % plugin['libname']
exit(1)
for plugin in plugin_ini_list:
write_plugin(plugin, plugin_ini_list)
if plugin_am_file is not None:
plugin_am_file.close()
if plugin_ac_file is not None:
plugin_ac_file.close()
if plugin_doc_index is not None:
plugin_doc_index.close()
|