Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
fix_missing_includes Namespace Reference

Functions

 external_header (sym)
 
 layer_of (rel)
 
 build_index ()
 
 _conditional_depth (text, offset)
 
 insert_includes (path, headers)
 
 main ()
 

Variables

 REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 SRC = os.path.join(REPO, "src")
 
dict LAYER
 
list EXTERNAL
 
list MISSING
 
list DECLARE
 
 ENUM_MEMBER = re.compile(r"^\s*([A-Z][A-Z0-9_]{2,})\s*(?:=|,|$)")
 
 COMMENT_BLOCK = re.compile(r"/\*.*?\*/", re.S)
 
 COMMENT_LINE = re.compile(r"//[^\n]*")
 

Detailed Description

Add the include that supplies each symbol the compiler says is missing.

Removing a god-header leaves files that were quietly living off what it dragged in. The
compiler names every one of them precisely -- `implicit declaration of function 'dt_print'`,
`'DT_DEBUG_CONTROL' undeclared` -- so the repair is mechanical: find which header declares the
symbol, add it, repeat until the build is clean.

Reads a compiler log on stdin (or a file), extracts the missing symbols per file, resolves
each against an index of every header under src/, and inserts the includes. A symbol declared
in more than one header is resolved by preferring the lowest layer -- a leaf library over a
module that re-exports it -- which is the include you want anyway.

Usage:
    ninja -k 0 2>&1 | tools/fix_missing_includes.py [--dry-run]

Function Documentation

◆ _conditional_depth()

fix_missing_includes._conditional_depth (   text,
  offset 
)
protected
How many #if/#ifdef blocks enclose `offset`.

Definition at line 126 of file fix_missing_includes.py.

References max.

Referenced by insert_includes().

◆ build_index()

fix_missing_includes.build_index ( )
symbol -> [header relpaths], best candidate first.

Definition at line 94 of file fix_missing_includes.py.

References layer_of().

Referenced by main().

◆ external_header()

fix_missing_includes.external_header (   sym)

Definition at line 61 of file fix_missing_includes.py.

Referenced by main().

◆ insert_includes()

fix_missing_includes.insert_includes (   path,
  headers 
)

Definition at line 134 of file fix_missing_includes.py.

References _conditional_depth().

Referenced by main().

◆ layer_of()

fix_missing_includes.layer_of (   rel)

Definition at line 89 of file fix_missing_includes.py.

Referenced by build_index().

◆ main()

fix_missing_includes.main ( void  )

Definition at line 173 of file fix_missing_includes.py.

References build_index(), external_header(), insert_includes(), and main().

Referenced by main().

Variable Documentation

◆ COMMENT_BLOCK

fix_missing_includes.COMMENT_BLOCK = re.compile(r"/\*.*?\*/", re.S)

Definition at line 85 of file fix_missing_includes.py.

◆ COMMENT_LINE

fix_missing_includes.COMMENT_LINE = re.compile(r"//[^\n]*")

Definition at line 86 of file fix_missing_includes.py.

◆ DECLARE

list fix_missing_includes.DECLARE
Initial value:
1= [
2 re.compile(r"^\s*#\s*define\s+([A-Za-z_]\w*)"),
3 re.compile(r"^\s*}[^;]*?\b([A-Za-z_]\w*)\s*;"), # `} name;` and `} ATTR(..) name;`
4 re.compile(r"^\s*typedef\s+.*?\b([A-Za-z_]\w*)\s*;"),
5 re.compile(r"^\s*typedef\s+.*\‍(\s*\*\s*([A-Za-z_]\w*)\s*\‍)\s*\‍("), # function-pointer typedef
6 re.compile(r"^\s*(?:struct|union|enum)\s+([A-Za-z_]\w*)\s*[;{]"),
7 re.compile(r"^\s*(?:[A-Za-z_][\w \t*]*?[ \t*])([A-Za-z_]\w*)\s*\‍("),
8]

Definition at line 75 of file fix_missing_includes.py.

◆ ENUM_MEMBER

fix_missing_includes.ENUM_MEMBER = re.compile(r"^\s*([A-Z][A-Z0-9_]{2,})\s*(?:=|,|$)")

Definition at line 83 of file fix_missing_includes.py.

◆ EXTERNAL

list fix_missing_includes.EXTERNAL
Initial value:
1= [
2 (re.compile(r"^(?:GList|GSList|GHashTable|GError|GString|GArray|GPtrArray|GQueue|"
3 r"GValue|GObject|GType|GFile|GTimer|GThread|GMutex|GCond|GRegex|GKeyFile|"
4 r"GDateTime|GMainLoop|GMainContext|GSource|GBytes|GVariant|GCancellable|"
5 r"g_[a-z_]+|G_[A-Z_]+)$"), "<glib.h>"),
6 (re.compile(r"^(?:Gtk\w+|Gdk\w+|Pango\w+|gtk_\w+|gdk_\w+|pango_\w+|GTK_\w+|GDK_\w+|"
7 r"PANGO_\w+)$"), "<gtk/gtk.h>"),
8 (re.compile(r"^(?:cairo_\w+|CAIRO_\w+)$"), "<cairo.h>"),
9 (re.compile(r"^(?:u?int(?:8|16|32|64)_t|u?intptr_t|SIZE_MAX|(?:U?INT(?:8|16|32|64)_(?:MAX|MIN)))$"),
10 "<stdint.h>"),
11 (re.compile(r"^(?:_|N_|Q_|C_)$"), "<glib/gi18n.h>"),
12 (re.compile(r"^(?:printf|fprintf|snprintf|vsnprintf|fopen|fclose|fflush|stdout|stderr)$"),
13 "<stdio.h>"),
14 (re.compile(r"^(?:malloc|calloc|realloc|free|abs|qsort|getenv|exit)$"), "<stdlib.h>"),
15 (re.compile(r"^(?:memcpy|memset|strlen|strcmp|strncmp|strdup|strstr|strchr)$"), "<string.h>"),
16]

Definition at line 43 of file fix_missing_includes.py.

◆ LAYER

dict fix_missing_includes.LAYER
Initial value:
1= {
2 'external': 0, 'win': 0, 'system': 0,
3 'common': 1, 'math': 1, 'colorprofiles': 1,
4 'pixel': 2,
5 'control': 3,
6 'gui': 4, 'widgets': 4,
7 'develop': 5,
8 'iop': 6, 'imageio': 6,
9 'libs': 7, 'views': 7, 'chart': 7,
10 'apps': 10,
11}

Definition at line 28 of file fix_missing_includes.py.

◆ MISSING

list fix_missing_includes.MISSING
Initial value:
1= [
2 re.compile(r"^(?P<file>[^:]+):\d+:\d+: (?:error|warning): implicit declaration of function '(?P<sym>\w+)'"),
3 re.compile(r"^(?P<file>[^:]+):\d+:\d+: error: '(?P<sym>\w+)' undeclared"),
4 re.compile(r"^(?P<file>[^:]+):\d+:\d+: error: unknown type name '(?P<sym>\w+)'"),
5 re.compile(r"^(?P<file>[^:]+):\d+:\d+: error: '(?P<sym>\w+)' was not declared in this scope"),
6]

Definition at line 68 of file fix_missing_includes.py.

◆ REPO

fix_missing_includes.REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Definition at line 23 of file fix_missing_includes.py.

◆ SRC

fix_missing_includes.SRC = os.path.join(REPO, "src")

Definition at line 24 of file fix_missing_includes.py.