Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 1 | # Big issue: |
| 2 | # emitter depends on doxyfile which is generated from doxyfile.in. |
| 3 | # build fails after cleaning and relaunching the build. |
| 4 | |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 5 | # Todo: |
| 6 | # Add helper function to environment like for glob |
| 7 | # Easier passage of header/footer |
| 8 | # Automatic deduction of index.html path based on custom parameters passed to doxyfile |
| 9 | |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 10 | import os |
| 11 | import os.path |
| 12 | import glob |
| 13 | from fnmatch import fnmatch |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 14 | import SCons |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 15 | |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 16 | def Doxyfile_emitter(target, source, env): |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 17 | """ |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 18 | Modify the target and source lists to use the defaults if nothing |
| 19 | else has been specified. |
| 20 | |
| 21 | Dependencies on external HTML documentation references are also |
| 22 | appended to the source list. |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 23 | """ |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 24 | doxyfile_template = env.File(env['DOXYFILE_FILE']) |
| 25 | source.insert(0, doxyfile_template) |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 26 | |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 27 | return target, source |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 28 | |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 29 | def Doxyfile_Builder(target, source, env): |
| 30 | """Input: |
| 31 | DOXYFILE_FILE |
| 32 | Path of the template file for the output doxyfile |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 33 | |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 34 | DOXYFILE_DICT |
| 35 | A dictionnary of parameter to append to the generated doxyfile |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 36 | """ |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 37 | subdir = os.path.split(source[0].abspath)[0] |
| 38 | doc_top_dir = os.path.split(target[0].abspath)[0] |
| 39 | doxyfile_path = source[0].abspath |
| 40 | doxy_file = file( target[0].abspath, 'wt' ) |
| 41 | try: |
| 42 | # First, output the template file |
| 43 | try: |
| 44 | f = file(doxyfile_path, 'rt') |
| 45 | doxy_file.write( f.read() ) |
| 46 | f.close() |
| 47 | doxy_file.write( '\n' ) |
| 48 | doxy_file.write( '# Generated content:\n' ) |
| 49 | except: |
| 50 | raise SCons.Errors.UserError, "Can't read doxygen template file '%s'" % doxyfile_path |
| 51 | # Then, the input files |
| 52 | doxy_file.write( 'INPUT = \\\n' ) |
| 53 | for source in source: |
| 54 | if source.abspath != doxyfile_path: # skip doxyfile path, which is the first source |
| 55 | doxy_file.write( '"%s" \\\n' % source.abspath ) |
| 56 | doxy_file.write( '\n' ) |
| 57 | # Dot... |
| 58 | values_dict = { 'HAVE_DOT': env.get('DOT') and 'YES' or 'NO', |
| 59 | 'DOT_PATH': env.get('DOT') and os.path.split(env['DOT'])[0] or '', |
| 60 | 'OUTPUT_DIRECTORY': doc_top_dir, |
| 61 | 'WARN_LOGFILE': target[0].abspath + '-warning.log'} |
| 62 | values_dict.update( env['DOXYFILE_DICT'] ) |
| 63 | # Finally, output user dictionary values which override any of the previously set parameters. |
| 64 | for key, value in values_dict.iteritems(): |
| 65 | doxy_file.write ('%s = "%s"\n' % (key, str(value))) |
| 66 | finally: |
| 67 | doxy_file.close() |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 68 | |
| 69 | def generate(env): |
| 70 | """ |
| 71 | Add builders and construction variables for the |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 72 | Doxygen tool. |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 73 | """ |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 74 | ## Doxyfile builder |
| 75 | def doxyfile_message (target, source, env): |
| 76 | return "creating Doxygen config file '%s'" % target[0] |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 77 | |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 78 | doxyfile_variables = [ |
| 79 | 'DOXYFILE_DICT', |
| 80 | 'DOXYFILE_FILE' |
| 81 | ] |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 82 | |
Christopher Dunn | 060c45a | 2009-05-24 22:22:08 +0000 | [diff] [blame^] | 83 | #doxyfile_action = SCons.Action.Action( Doxyfile_Builder, doxyfile_message, |
| 84 | # doxyfile_variables ) |
| 85 | doxyfile_action = SCons.Action.Action( Doxyfile_Builder, doxyfile_message) |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 86 | |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 87 | doxyfile_builder = SCons.Builder.Builder( action = doxyfile_action, |
| 88 | emitter = Doxyfile_emitter ) |
| 89 | |
| 90 | env['BUILDERS']['Doxyfile'] = doxyfile_builder |
| 91 | env['DOXYFILE_DICT'] = {} |
| 92 | env['DOXYFILE_FILE'] = 'doxyfile.in' |
| 93 | |
| 94 | ## Doxygen builder |
| 95 | def Doxygen_emitter(target, source, env): |
| 96 | output_dir = str( source[0].dir ) |
| 97 | if str(target[0]) == str(source[0]): |
| 98 | target = env.File( os.path.join( output_dir, 'html', 'index.html' ) ) |
| 99 | return target, source |
| 100 | |
| 101 | doxygen_action = SCons.Action.Action( [ '$DOXYGEN_COM'] ) |
| 102 | doxygen_builder = SCons.Builder.Builder( action = doxygen_action, |
| 103 | emitter = Doxygen_emitter ) |
| 104 | env['BUILDERS']['Doxygen'] = doxygen_builder |
| 105 | env['DOXYGEN_COM'] = '$DOXYGEN $DOXYGEN_FLAGS $SOURCE' |
| 106 | env['DOXYGEN_FLAGS'] = '' |
| 107 | env['DOXYGEN'] = 'doxygen' |
| 108 | |
| 109 | dot_path = env.WhereIs("dot") |
| 110 | if dot_path: |
| 111 | env['DOT'] = dot_path |
Christopher Dunn | f986423 | 2007-06-14 21:01:26 +0000 | [diff] [blame] | 112 | |
| 113 | def exists(env): |
| 114 | """ |
| 115 | Make sure doxygen exists. |
| 116 | """ |
| 117 | return env.Detect("doxygen") |