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