~drizzle-trunk/drizzle/development

992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
1
#!/usr/bin/python
2
992.1.25 by Monty Taylor
Moved myisam to new plugin system.
3
#  Copyright (C) 2009 Sun Microsystems
4
#
5
#  This program is free software; you can redistribute it and/or modify
6
#  it under the terms of the GNU General Public License as published by
7
#  the Free Software Foundation; version 2 of the License.
8
#
9
#  This program is distributed in the hope that it will be useful,
10
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#  GNU General Public License for more details.
13
#
14
#  You should have received a copy of the GNU General Public License
15
#  along with this program; if not, write to the Free Software
16
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
19
# Find plugins in the tree and add them to the build system 
20
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
21
import ConfigParser, os, sys
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
22
import datetime, time
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
23
24
top_srcdir='.'
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
25
top_builddir='.'
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
26
plugin_ini_fname='plugin.ini'
27
plugin_list=[]
1192.3.25 by Monty Taylor
It seems to work.
28
plugin_am_file=None
29
plugin_ac_file=None
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
30
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
31
class ChangeProtectedFile(object):
32
33
  def __init__(self, fname):
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
34
    self.bogus_file= False
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
35
    self.real_fname= fname
36
    self.new_fname= "%s.new" % fname
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
37
    try:
38
      self.new_file= open(self.new_fname,'w+')
39
    except IOError:
40
      self.bogus_file= True
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
41
42
  def write(self, text):
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
43
    if not self.bogus_file:
44
      self.new_file.write(text)
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
45
46
  # We've written all of this out into .new files, now we only copy them
47
  # over the old ones if they are different, so that we don't cause 
48
  # unnecessary recompiles
49
  def close(self):
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
50
    """Return True if the file had changed."""
1192.3.11 by Monty Taylor
Fixed a few distcheck issues.
51
    if self.bogus_file:
52
      return
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
53
    self.new_file.seek(0)
54
    new_content = self.new_file.read()
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
55
    self.new_file.close()
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
56
    try:
57
        old_file = file(self.real_fname, 'r')
58
        old_content = old_file.read()
59
        old_file.close()
60
    except IOError:
61
        old_content = None
62
    if new_content != old_content:
63
      if old_content != None:
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
64
        os.unlink(self.real_fname)
65
      os.rename(self.new_fname, self.real_fname)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
66
      return True
67
    else:
68
        try:
69
          os.unlink(self.new_fname)
70
        except:
71
          pass
72
73
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
74
def write_external_configure(plugin, plugin_file):
75
  """Write the initial bits of the configure.ac file"""
76
  if not os.path.exists('m4'):
77
    os.mkdir('m4')
78
  plugin_file.write("""
79
AC_PREREQ(2.59)dnl		Minimum Autoconf version required.
80
AC_INIT([%(name)s],[%(version)s],[%(url)s])
81
AC_CONFIG_SRCDIR([%(main_source)s])
82
AC_CONFIG_AUX_DIR(config)
83
AC_CONFIG_HEADERS([config.h])
84
AC_CONFIG_MACRO_DIR([m4])
85
1241.9.5 by Monty Taylor
Fixed the plugin script to not bork plugin visibility.
86
PANDORA_CANONICAL_TARGET(less-warnings, warnings-always-on, require-cxx, force-gcc42,skip-visibility)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
87
88
PANDORA_REQUIRE_LIBPROTOBUF
89
PANDORA_PROTOBUF_REQUIRE_VERSION([2.1.0])
90
PANDORA_REQUIRE_PROTOC
91
92
AC_LANG_PUSH(C++)
93
PANDORA_REQUIRE_PTHREAD
94
PANDORA_REQUIRE_LIBDL
95
AC_LANG_POP
96
97
PANDORA_USE_BETTER_MALLOC
98
99
PANDORA_DRIZZLE_BUILD
100
""" % plugin)
101
102
  write_plugin_ac(plugin, plugin_file)
103
104
  plugin_file.write("""
105
AC_CONFIG_FILES(Makefile)
106
107
AC_OUTPUT
108
109
echo "---"
110
echo "Configuration summary for $PACKAGE_NAME version $VERSION $PANDORA_RELEASE_COMMENT"
111
echo ""
112
echo "   * Installation prefix:       $prefix"
113
echo "   * System type:               $host_vendor-$host_os"
114
echo "   * Host CPU:                  $host_cpu"
115
echo "   * C Compiler:                $CC_VERSION"
116
echo "   * C++ Compiler:              $CXX_VERSION"
117
echo "   * Debug enabled:             $with_debug"
118
echo "   * Warnings as failure:       $ac_cv_warnings_as_errors"
119
echo "   * C++ cstdint location:      $ac_cv_cxx_cstdint"
120
echo "   * C++ hash_map location:     $ac_cv_cxx_hash_map"
121
echo "   * C++ hash namespace:        $ac_cv_cxx_hash_namespace"
122
echo "   * C++ shared_ptr namespace:  $ac_cv_shared_ptr_namespace"
123
echo ""
124
echo "---"
125
126
  """ % plugin)
127
128
def write_external_makefile(plugin, plugin_file):
129
130
  plugin_file.write("""
131
ACLOCAL_AMFLAGS = -I m4 --force
132
VERSION=$(PANDORA_RELEASE_VERSION)
133
134
pkgplugindir=$(libdir)/drizzle/plugin
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
135
EXTRA_DIST = plugin.ini
1192.3.53 by Robert Collins
Build fixes from Robert.
136
137
""" % plugin)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
138
  if plugin['headers'] != "":
139
    plugin_file.write("noinst_HEADERS = %(headers)s\n" % plugin)
140
  if plugin['testsuite']:
141
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
142
      plugin_file.write("EXTRA_DIST += %(testsuitedir)s\n" % plugin)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
143
  plugin_file.write("""
144
pkgplugin_LTLIBRARIES=lib%(name)s_plugin.la
1192.3.77 by Monty Taylor
Fixed dynamic loading with lcov and gprof.
145
lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
146
lib%(name)s_plugin_la_LIBADD=%(libs)s
147
lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
148
lib%(name)s_plugin_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
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
149
lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
150
lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
151
152
lib%(name)s_plugin_la_SOURCES=%(sources)s
1192.3.53 by Robert Collins
Build fixes from Robert.
153
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
154
""" % plugin)
155
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
156
  if os.path.exists(plugin_am_file):
157
    plugin_file.write('include %s\n' % plugin_am_file)
158
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
159
def write_external_plugin():
160
  """Return True if the plugin had changed."""
161
  plugin = read_plugin_ini('.')
162
  expand_plugin_ini(plugin, '.')
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
163
  plugin_file = ChangeProtectedFile('configure.ac')
164
  write_external_configure(plugin, plugin_file)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
165
  result = plugin_file.close()
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
166
  plugin_file = ChangeProtectedFile('Makefile.am')
167
  write_external_makefile(plugin, plugin_file)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
168
  # Write some stub configure.ac and Makefile.am files that include the above
169
  result = plugin_file.close() or result
170
  return result
171
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
172
def write_plugin(plugin_dir):
173
  """Return True if the plugin had changed."""
174
  plugin = read_plugin_ini(plugin_dir)
175
  expand_plugin_ini(plugin, plugin_dir)
1192.3.25 by Monty Taylor
It seems to work.
176
  write_plugin_ac(plugin, plugin_ac_file)
177
  write_plugin_am(plugin, plugin_am_file)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
178
179
def write_plugin_ac(plugin, plugin_ac):
180
  #
181
  # Write plugin config instructions into plugin.ac file.
182
  #
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
183
  plugin_ac_file=os.path.join(plugin['rel_path'],'plugin.ac')
184
  plugin_m4_dir=os.path.join(plugin['rel_path'],'m4')
185
  plugin_m4_files=[]
186
  if os.path.exists(plugin_m4_dir) and os.path.isdir(plugin_m4_dir):
187
    for m4_file in os.listdir(plugin_m4_dir):
188
      if os.path.splitext(m4_file)[-1] == '.m4':
189
        plugin_m4_files.append(os.path.join(plugin['rel_path'], m4_file))
1192.3.25 by Monty Taylor
It seems to work.
190
  plugin_ac.write("""
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
191
dnl Config for %(title)s
992.1.23 by Monty Taylor
New system now runs in parallel to old system.
192
""" % plugin)
193
  for m4_file in plugin_m4_files:
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
194
    plugin_ac.write('m4_sinclude([%s])\n' % m4_file)
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
195
  plugin['plugin_dep_libs']=" ".join(["\${top_builddir}/%s" % f for f in plugin['libs'].split()])
196
197
  if plugin['static']:
198
    plugin_ac.write("""
199
dnl This plugin is staticly built, which means we cannot live without and it is not
200
dnl possible to disable it. Once it is disableable, we will make it non-static.
201
with_%(name)s_plugin=yes
202
pandora_builtin_list="_drizzled_%(name)s_plugin_,${pandora_builtin_list}"
203
pandora_plugin_libs="${pandora_plugin_libs} \${top_builddir}/plugin/lib%(name)s_plugin.la"
204
PANDORA_PLUGIN_DEP_LIBS="${PANDORA_PLUGIN_DEP_LIBS} %(plugin_dep_libs)s"
205
206
""" % plugin)
207
    if plugin['testsuite']:
208
      plugin_ac.write("""
209
pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
210
""" % plugin)
211
  else:
212
    plugin_ac.write("""
1022.2.4 by Monty Taylor
Fixed turning off plugins.
213
AC_ARG_WITH([%(name_with_dashes)s-plugin],[
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
214
dnl indented wierd to make the help output correct
215
AS_HELP_STRING([--with-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=yes@:>@])
1022.2.4 by Monty Taylor
Fixed turning off plugins.
216
AS_HELP_STRING([--without-%(name_with_dashes)s-plugin],[Disable building %(title)s])
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
217
  ],[
218
    with_%(name)s_plugin="$withval"
219
    requested_%(name)s_plugin="yes"
220
  ],[
221
    with_%(name)s_plugin="yes"
222
    requested_%(name)s_plugin="no"
223
  ])
224
AC_ARG_ENABLE([%(name_with_dashes)s-plugin],[
225
dnl indented wierd to make the help output correct
226
AS_HELP_STRING([--enable-%(name_with_dashes)s-plugin],[Build %(title)s. @<:@default=%(default_yesno)s@:>@])
227
AS_HELP_STRING([--disable-%(name_with_dashes)s-plugin],[Disable building %(title)s])
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
228
  ],
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
229
  [enable_%(name)s_plugin="$withval"],
230
  [enable_%(name)s_plugin=%(default_yesno)s])
231
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
232
""" % plugin)
233
  if os.path.exists(plugin_ac_file):
234
    plugin_ac.write('m4_sinclude([%s])\n' % plugin_ac_file) 
235
  # The plugin author has specified some check to make to determine
236
  # if the plugin can be built. If the plugin is turned on and this 
237
  # check fails, then configure should error out. If the plugin is not
238
  # turned on, then the normal conditional build stuff should just let
239
  # it silently not build
240
  if plugin['has_build_conditional']:
241
    plugin_ac.write("""
997.2.5 by Monty Taylor
Merged up with trunk properly.
242
AS_IF([test %(build_conditional)s],
1166.1.1 by Monty Taylor
Fixed an accidental logic error that caused any plugin which was availble to be built to be automatically enabled/builtin.
243
      [], dnl build_conditional can only negate
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
244
      [
245
        AS_IF([test "x${requested_%(name)s_plugin}" = "xyes"],
246
              [AC_MSG_ERROR([Plugin %(name)s was explicitly requested, yet failed build dependency checks. Aborting!])])
247
        with_%(name)s_plugin=no
248
      ])
1192.3.53 by Robert Collins
Build fixes from Robert.
249
250
""" % plugin)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
251
  if not plugin['unconditional']:
252
    plugin_ac.write("""
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
253
AM_CONDITIONAL([%(build_conditional_tag)s],
254
               [test %(build_conditional)s])
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
255
    """ % plugin)
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
256
  if not plugin['static']:
257
    plugin_ac.write("""
992.1.21 by Monty Taylor
First pass at replacing plugin.m4.
258
AS_IF([test "x$with_%(name)s_plugin" = "xyes"],
992.1.22 by Monty Taylor
Moved towards having register_plugins.py make builtin plugins, so we can have a first step.
259
      [
1192.3.53 by Robert Collins
Build fixes from Robert.
260
""" % plugin)
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
261
    if plugin['testsuite']:
262
      plugin_ac.write("""
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
263
        pandora_plugin_test_list="%(name)s,${pandora_plugin_test_list}"
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
264
      """ % plugin)
1099.1.16 by Monty Taylor
Added support for conditionally building plugin's test suite if the plugin is built.
265
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
266
    plugin_ac.write("""
267
        AS_IF([test "x$enable_%(name)s_plugin" = "xyes"],[
268
          pandora_default_plugin_list="%(name)s,${pandora_default_plugin_list}"
269
        ])
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
270
    """ % plugin)
1259.7.5 by Monty Taylor
Removed the apparent ability to disable builtin plugins. We don't actually support it
271
    plugin_ac.write("      ])\n")
1093.9.13 by Monty Taylor
pandora-build v0.42 - Started splitting out plugin system into pandora-build
272
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
273
274
def expand_plugin_ini(plugin, plugin_dir):
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
275
    if plugin_dir == ".":
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
276
      plugin['rel_path']= plugin_dir
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
277
      plugin['unconditional']=True
278
    else:
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
279
      plugin['rel_path']= plugin_dir[len(top_srcdir)+len(os.path.sep):]
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
280
      plugin['unconditional']=False
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
281
    # TODO: determine path to plugin dir relative to top_srcdir... append it to
282
    # source files if they don't already have it
283
    if plugin['sources'] == "":
284
      plugin['sources']="%s.cc" % plugin['name']
285
    new_sources=""
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
286
    if plugin_dir != ".":
287
      for src in plugin['sources'].split():
288
        if not src.startswith(plugin['rel_path']):
289
          src= os.path.join(plugin['rel_path'], src)
290
          new_sources= "%s %s" % (new_sources, src)
291
      if new_sources != "":
292
        plugin['sources']= new_sources
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
293
    plugin['main_source']= plugin['sources'].split()[0]
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
294
    
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
295
    if plugin_dir != ".":
296
      new_headers=""
297
      for header in plugin['headers'].split():
298
        if not header.startswith(plugin['rel_path']):
299
          header= os.path.join(plugin['rel_path'], header)
300
          new_headers= "%s %s" % (new_headers, header)
301
      plugin['headers']= new_headers
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
302
    
303
    # Make a yes/no version for autoconf help messages
304
    if plugin['load_by_default']:
305
      plugin['default_yesno']="yes"
306
    else:
307
      plugin['default_yesno']="no"
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
308
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
309
    
310
    plugin['build_conditional_tag']= "BUILD_%s_PLUGIN" % plugin['name'].upper()
311
    plugin['name_with_dashes']= plugin['name'].replace('_','-')
312
    if plugin.has_key('build_conditional'):
313
      plugin['has_build_conditional']=True
314
    else:
315
      plugin['has_build_conditional']=False
316
      plugin['build_conditional']='"x${with_%(name)s_plugin}" = "xyes"' %plugin
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
317
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
318
def find_testsuite(plugin_dir):
319
  for testdir in ['drizzle-tests','tests']:
320
    if os.path.isdir(os.path.join(plugin_dir,testdir)):
321
      return testdir
322
  if os.path.isdir(os.path.join('tests','suite',os.path.basename(plugin_dir))):
323
    return ""
324
  return None
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
325
326
def read_plugin_ini(plugin_dir):
327
    plugin_file= os.path.join(plugin_dir,plugin_ini_fname)
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
328
    plugin_defaults= dict(sources="",
329
                          headers="",
330
                          cflags="",
331
                          cppflags="",
332
                          cxxflags="",
333
                          libs="",
334
                          ldflags="",
335
                          author="",
336
                          title="",
337
                          description="",
338
                          license="PLUGIN_LICENSE_GPL",
339
                          name=os.path.basename(plugin_dir),
340
                          load_by_default="False",
341
                          static="False")
342
    parser=ConfigParser.ConfigParser(defaults= plugin_defaults)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
343
    parser.read(plugin_file)
344
    plugin=dict(parser.items('plugin'))
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
345
    if plugin_dir == '.':
346
      if not plugin.has_key('url'):
347
        print "External Plugins are required to specifiy a url"
348
        plugin['url']= 'http://launchpad.net/%(name)s' % plugin
349
        sys.exit(1)
350
      if plugin_dir == '.' and not plugin.has_key('version'):
351
        print "External Plugins are required to specifiy a version"
352
        sys.exit(1)
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
353
    if not plugin.has_key('version'):
354
      plugin['version']=datetime.date.fromtimestamp(time.time()).isoformat()
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
355
   
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
356
    if plugin.has_key('load_by_default'):
357
      plugin['load_by_default']=parser.getboolean('plugin','load_by_default')
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
358
    if plugin.has_key('static'):
359
      plugin['static']= parser.getboolean('plugin','static')
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
360
    if plugin.has_key('testsuite'):
361
      if plugin['testsuite'] == 'disable':
362
        plugin['testsuite']= False
363
    else:
364
      plugin_testsuite= find_testsuite(plugin_dir)
365
      plugin['testsuitedir']=plugin_testsuite
366
      if plugin_testsuite is not None:
367
        plugin['testsuite']=True
368
      else:
369
        plugin['testsuite']=False
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
370
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
371
    return plugin
372
373
374
def write_plugin_am(plugin, plugin_am):
375
  """Write an automake fragment for this plugin.
376
  
377
  :param plugin: The plugin dict.
378
  :param plugin_am: The file to write to.
379
  """
380
  # The .plugin.ini.stamp avoids changing the datestamp on plugin.ini which can
381
  # confuse VCS systems.
1192.3.25 by Monty Taylor
It seems to work.
382
  plugin_am.write("""
383
EXTRA_DIST += %(rel_path)s/plugin.ini
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
384
385
# Prevent errors when a plugin dir is removed
386
%(rel_path)s/plugin.ini:
1192.3.53 by Robert Collins
Build fixes from Robert.
387
388
""" % plugin)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
389
  if plugin['headers'] != "":
390
    plugin_am.write("noinst_HEADERS += %(headers)s\n" % plugin)
1192.3.20 by Monty Taylor
Added the testsuite location finding code to support in-plugin-dir test suites.
391
  if plugin['testsuite']:
392
    if plugin.has_key('testsuitedir') and plugin['testsuitedir'] != "":
393
      plugin_am.write("EXTRA_DIST += %(rel_path)s/%(testsuitedir)s\n" % plugin)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
394
  if plugin['static']:
395
    plugin_am.write("""
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
396
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
397
EXTRA_DIST += %(rel_path)s/plugin.ini
398
if %(build_conditional_tag)s
399
  noinst_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
400
  plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
401
  plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
1192.3.77 by Monty Taylor
Fixed dynamic loading with lcov and gprof.
402
  plugin_lib%(name)s_plugin_la_LDFLAGS=$(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)  
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
403
  plugin_lib%(name)s_plugin_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
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
404
  plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
405
  plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
406
407
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
408
  PANDORA_DYNAMIC_LDADDS+=${top_builddir}/plugin/lib%(name)s_plugin.la
409
endif
410
""" % plugin)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
411
  else:
412
    plugin_am.write("""
413
plugin_lib%(name)s_dir=${top_srcdir}/%(rel_path)s
414
EXTRA_DIST += %(rel_path)s/plugin.ini
415
if %(build_conditional_tag)s
416
  pkgplugin_LTLIBRARIES+=plugin/lib%(name)s_plugin.la
1192.3.77 by Monty Taylor
Fixed dynamic loading with lcov and gprof.
417
  plugin_lib%(name)s_plugin_la_LDFLAGS=-module -avoid-version -rpath $(pkgplugindir) $(AM_LDFLAGS) %(ldflags)s $(GCOV_LIBS)
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
418
  plugin_lib%(name)s_plugin_la_LIBADD=%(libs)s
419
  plugin_lib%(name)s_plugin_la_DEPENDENCIES=%(libs)s
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
420
  plugin_lib%(name)s_plugin_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
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
421
  plugin_lib%(name)s_plugin_la_CXXFLAGS=$(AM_CXXFLAGS) %(cxxflags)s
422
  plugin_lib%(name)s_plugin_la_CFLAGS=$(AM_CFLAGS) %(cflags)s
423
424
  plugin_lib%(name)s_plugin_la_SOURCES=%(sources)s
425
endif
426
""" % plugin)
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
427
  plugin_am_file=os.path.join(plugin['rel_path'],'plugin.am')
428
  if os.path.exists(plugin_am_file):
429
    plugin_am.write('include %s\n' % plugin_am_file)
430
1192.3.25 by Monty Taylor
It seems to work.
431
#MAIN STARTS HERE:
432
433
actions=[]
434
for arg in sys.argv:
435
  if arg.startswith('--top_srcdir='):
436
    top_srcdir=arg[12:]
437
  elif arg.startswith('--top_builddir='):
438
    top_builddir=arg[14:]
439
  elif arg == "--force-all":
440
    actions=['plugin-list','pandora-plugin.am','write']
441
    break
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
442
  else:
1192.3.25 by Monty Taylor
It seems to work.
443
    actions.append(arg)
444
if len(actions) == 0:
445
  actions.append('write')
446
447
def accumulate_plugins(arg, dirname, fnames):
448
  # plugin_ini_fname is a name in dirname indicating dirname is a plugin.
449
  if plugin_ini_fname in fnames:
450
    arg.append(dirname)
451
os.path.walk(os.path.join(top_srcdir,"plugin"),accumulate_plugins,plugin_list)
452
453
454
if not os.path.exists("config/pandora-plugin.am") or "write" in actions:
455
  plugin_am_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.am'))
456
  plugin_am_file.write("""
457
# always the current list, generated every build so keep this lean.
1192.3.74 by Robert Collins
Finish the renaming of plugin.list -> pandora-plugin.list that mtaylor started.
458
# pandora-plugin.list: datestamp preserved list
459
${srcdir}/config/pandora-plugin.list: .plugin.scan
1192.3.25 by Monty Taylor
It seems to work.
460
.plugin.scan:
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
461
	@cd ${top_srcdir} && python config/pandora-plugin plugin-list
1192.3.25 by Monty Taylor
It seems to work.
462
463
# Plugins affect configure; so to prevent configure running twice in a tarball
464
# build (once up front, once with the right list of plugins, we ship the
465
# generated list of plugins and the housekeeping material for that list so it
466
# is likewise not updated.
467
EXTRA_DIST += \
468
	config/pandora-plugin.am \
469
	config/pandora-plugin.ac \
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
470
	config/pandora-plugin
1192.3.25 by Monty Taylor
It seems to work.
471
472
473
# Seed the list of plugin LDADDS which plugins may extend.
474
PANDORA_DYNAMIC_LDADDS=
475
476
# plugin.stamp: graph dominator for creating all per pandora-plugin.ac/am
477
# files. This is invoked when the code to generate such files has altered.""")
478
479
if not os.path.exists("config/pandora-plugin.ac") or "write" in actions:
480
  plugin_ac_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.ac'))
481
  plugin_ac_file.write("dnl Generated file, run make to rebuild\n")
482
1192.4.1 by Robert Collins
Merged buildsystem change from lifeless.
483
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
484
if os.path.exists('plugin.ini'):
485
  # Are we in a plugin dir which wants to have a self-sufficient build system?
1192.3.25 by Monty Taylor
It seems to work.
486
  plugin_list=['.']
1241.9.3 by Monty Taylor
Fixed the out-of-tree plugin file generation.
487
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
488
  write_external_plugin()
489
else:
1192.3.25 by Monty Taylor
It seems to work.
490
  plugin_list_file = ChangeProtectedFile(os.path.join('config', 'pandora-plugin.list'))
491
  for p in plugin_list:
492
    plugin_list_file.write(p)
493
    plugin_list_file.write("\n")
1192.3.7 by Monty Taylor
Added code necessary for building plugins dynamically.
494
  plugin_list.sort()
1192.3.25 by Monty Taylor
It seems to work.
495
  plugin_list_file.close()
496
497
if not os.path.exists("config/pandora-plugin.am") or 'write' in actions:
1192.3.74 by Robert Collins
Finish the renaming of plugin.list -> pandora-plugin.list that mtaylor started.
498
  plugin_am_file.write("\n${top_srcdir}/config/pandora-plugin.am: ${top_srcdir}/config/pandora-plugin.list ${top_srcdir}/config/pandora-plugin ")
1192.3.25 by Monty Taylor
It seems to work.
499
  for plugin_dir in plugin_list:
500
    plugin_am_file.write("\\\n\t%s/plugin.ini " % plugin_dir)
1192.3.28 by Monty Taylor
pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
501
  plugin_am_file.write("\n\tcd ${top_srcdir} && python config/pandora-plugin write\n")
1192.3.25 by Monty Taylor
It seems to work.
502
  for plugin_dir in plugin_list:
503
    write_plugin(plugin_dir)
504
505
if plugin_am_file is not None:
506
  plugin_am_file.close()
507
if plugin_ac_file is not None:
508
  plugin_ac_file.close()