package mopsa

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Mopsa_build_db - Build a database to manage the analysis of multi-file projects

To help with the analysis of large projects that may have multiple source files, specific libraries, headers, preprocessing and compilation options, we create a database of these information. The database is typically extracted from an actual build, using wrappers for the build tools - see BuildWrapper.

Note: the database is not very efficient as it is completely loaded and recreated at each file operation. Also, it requires a file lock in case of a concurrent build (e.g.: make -j). It should suffice for small project though and is probably not a bottleneck.

DB representation

type source_kind =
  1. | SOURCE_C
  2. | SOURCE_CXX
  3. | SOURCE_ASM
  4. | SOURCE_UNKNOWN
    (*

    Source languages.

    *)
type source = {
  1. source_path : string;
    (*

    absolute path of source file

    *)
  2. source_kind : source_kind;
  3. source_opts : string list;
    (*

    compilation options

    *)
  4. source_cwd : string;
    (*

    directory from where the compilation was launched

    *)
}

Represents a compiled source.

val source_unknown : string -> source

Helper to create an unknown source with the given name.

type library_kind =
  1. | LIBRARY_STATIC
  2. | LIBRARY_DYNAMIC
    (*

    Kinds of lirbaries.

    *)
module StringMap : Stdlib.Map.S

Map with string key

type file_kind =
  1. | Object of source
  2. | Library of library_kind * file StringMap.t
    (*

    contents, indexed by file name

    *)
  3. | Executable of file list
  4. | Unknown of string
    (*

    absolute path

    *)
and file = string * file_kind
type db = file StringMap.t

Represents a full compilation database. Files are indexed by absolute paths.

val empty_db : db

The empty database.

Printing

val source_kind_name : source_kind -> string
val print_file : string -> file -> unit
val print_db : db -> unit
val print_file_json : file -> unit
val print_db_json : db -> unit

Apply file operations to DB

val db_remove : bool -> db -> string -> db

db_remove recurse db file deletes a file or directory, possibly recursively.

val db_copymove : bool -> bool -> db -> string -> string -> db

db_copymove move rcur db org_file dest_file copies or moves a file or directory.

val db_add_archive : db -> string -> library_kind -> string list -> db

db_add_archive db archive kind files creates or add files to a static or dynamic library.

val db_remove_archive : db -> string -> string list -> db

db_remove_archive db archive files removes some files from a static or dynamic library.

val db_extract_archive : db -> string -> string list -> db

db_extract_archive db archive files extracts a specified set of files from a library.

val db_extract_archive_all : db -> string -> db

db_extract_archive_all db archive extracts a the files in a library.

val db_compile : db -> source_kind -> string -> string -> string list -> file StringMap.t

db_compile db language source object args compliles the specified source file in the specified language into the specified object file, with the specified compilation command-line arguments.

db_link db executable sources links the specified list of files into the specified executable file.

DB loading, saving, locking

val open_db : ?create:bool -> string -> Unix.file_descr

Open DB file and lock. Optionally create if it does not exist.

val close_db : Unix.file_descr -> unit

Unlock and close DB file.

val read_db : Unix.file_descr -> db

Read from open DB file.

val write_db : Unix.file_descr -> db -> unit

Write to open DB file.

val load_db : string -> db

Load DB from file.

DB extraction for analysis driver

val get_executables : db -> string list

get_executables db returns the list of all executable compiled in this database. Full path-names are returned.

val get_libraries : db -> string list

get_libraries db returns the list of all libraries compiled in this database. Full path-names are returned.

val get_file_sources : ?expected_kind:file_kind -> db -> string -> source list

get_file_sources expected_kind db executable_path returns the list of sources that compose the given expected kind (by default, executables) in the database (includes recursively the contents of libraries linked to the executable, when known).

val get_executable_sources : db -> string -> source list

get_executable_sources db executable behaves as get_file_sources but uses the short executable name instead of the full path-name.

val get_library_sources : db -> string -> source list

get_library_sources db executable behaves as get_file_sources with the library kind, but it uses the short executable name instead of the full path-name.

Exported utilities

val log : bool Stdlib.ref
val logfile : Stdlib.out_channel Stdlib.ref
val starts_with : string -> string -> bool
val ends_with : string -> string -> bool
val absolute_path : string -> string
OCaml

Innovation. Community. Security.