package mopsa

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

Module Mopsa_build_dbSource

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

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

    Source languages.

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

    absolute path of source file

    *)
  2. source_obj : string;
    (*

    absolute path of the object file

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

    compilation options

    *)
  5. source_cwd : string;
    (*

    directory from where the compilation was launched

    *)
}

Represents a compiled source.

Sourceval source_unknown : string -> source

Helper to create an unknown source with the given name.

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

    Kinds of lirbaries.

    *)

Map with string key

Sourcetype 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

    *)
Sourceand file = string * file_kind

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

Sourceval empty_db : db

The empty database.

Printing

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

Apply file operations to DB

Sourceval db_remove : bool -> db -> string -> db

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

Sourceval db_copymove : bool -> bool -> db -> string -> string -> db

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

Sourceval 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.

Sourceval db_remove_archive : db -> string -> string list -> db

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

Sourceval db_extract_archive : db -> string -> string list -> db

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

Sourceval db_extract_archive_all : db -> string -> db

db_extract_archive_all db archive extracts a the files in a library.

Sourceval 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

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

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

Sourceval close_db : Unix.file_descr -> unit

Unlock and close DB file.

Sourceval read_db : Unix.file_descr -> db

Read from open DB file.

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

Write to open DB file.

Sourceval load_db : string -> db

Load DB from file.

DB extraction for analysis driver

Sourceval get_executables : db -> string list

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

Sourceval get_libraries : db -> string list

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

Sourceval 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).

Sourceval 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.

Sourceval 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

Sourceval log : bool ref
Sourceval logfile : out_channel ref
Sourceval starts_with : string -> string -> bool
Sourceval ends_with : string -> string -> bool
Sourceval absolute_path : string -> string
OCaml

Innovation. Community. Security.