Class: Archsight::Import::Handlers::CppGrapher

Inherits:
Grapher show all
Defined in:
lib/archsight/import/handlers/cpp_grapher.rb

Overview

CppGrapher — analyses a C/C++ repository and generates a GraphViz DOT graph of its directory/module structure, stored as architecture/cpp/modules on the TechnologyArtifact.

C/C++ has no formal module system, so directory structure is the de facto module boundary. Quoted #include "..." statements express local dependencies; angled #include <...> are system/external headers and are ignored.

Supports single-project and multi-project (CMake add_subdirectory) layouts. Pure static regex analysis — no compiler or CMake required.

File-to-package mapping:

src/engine/core.cpp   → project/engine/core → capped → project/engine
include/engine/core.h → project/engine/core → capped → project/engine
src/renderer.cpp      → project/renderer (depth 1, not capped)
main.cpp              → dep extraction skipped (entry point)

Configuration:

import/config/path    - Path to the C/C++ repository root
import/config/ranksep - Horizontal gap between rank columns (default: 0.6)
import/config/nodesep - Vertical gap between nodes in a column (default: 0.15)

Constant Summary collapse

SKIP_DIRS =
%w[build .build out .git third_party extern external vendor test tests
googletest gtest CMakeFiles cmake .cache _deps generated].freeze
MAX_PKG_DEPTH =
2
SOURCE_EXTS =
%w[.cpp .c .cc .cxx .h .hpp .hh .hxx].freeze
SRC_PREFIXES =
%w[src/ include/ lib/ source/].freeze
INCLUDE_RE =
/^\s*#\s*include\s+"([^"]+)"/
ENTRY_FILES =
%w[main.cpp main.c Main.cpp Main.c].freeze
EXT_RE =
/\.(cpp|c|cc|cxx|hpp|h|hh|hxx)\z/

Constants inherited from Grapher

Grapher::PALETTE

Instance Attribute Summary

Attributes inherited from Archsight::Import::Handler

#database, #import_resource, #progress, #resources_dir, #shared_writer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Grapher

#dot_graph, #execute, #safe_glob

Methods inherited from Archsight::Import::Handler

#compute_config_hash, #config, #config_all, #execute, #import_yaml, #initialize, #resource_yaml, #resources_to_yaml, #self_marker, #write_generates_meta, #write_yaml

Constructor Details

This class inherits a constructor from Archsight::Import::Handler

Class Method Details

.applicable?(path) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/archsight/import/handlers/cpp_grapher.rb', line 31

def self.applicable?(path)
  File.exist?(File.join(path, "CMakeLists.txt")) ||
    File.exist?(File.join(path, "meson.build")) ||
    Dir.glob(File.join(path, "*.{cpp,c,cc,cxx,h,hpp}")).any? ||
    Dir.glob(File.join(path, "src/*.{cpp,c,cc,cxx}")).any? ||
    Dir.glob(File.join(path, "include/*.{h,hpp,hh}")).any?
end

.language_nameObject



29
# File 'lib/archsight/import/handlers/cpp_grapher.rb', line 29

def self.language_name = "cpp"

Instance Method Details

#wrap_single_module?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/archsight/import/handlers/cpp_grapher.rb', line 39

def wrap_single_module?
  true
end