Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ contrib/pybind11/

# Local configuration files
config/*_locations.yaml
config/gambit_bits.yaml

# Scratch files
scratch/**
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,5 @@ if(EXISTS "${PROJECT_SOURCE_DIR}/ScannerBit/")
include(${PROJECT_BINARY_DIR}/linkedout.cmake)
endif()

# Create a list of Gambit bits to be used in the diagnostic system of Gambit.
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/Utils/scripts/find_all_gambit_bits.py --source-dir ${PROJECT_SOURCE_DIR} --output-file=${PROJECT_SOURCE_DIR}/config/gambit_bits.yaml)
34 changes: 28 additions & 6 deletions Core/src/diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,41 @@ namespace Gambit
/// Basic module diagnostic function
void gambit_core::module_diagnostic()
{
table_formatter table("Modules", "#functions");
YAML::Node gambit_bits_yaml = YAML::LoadFile(GAMBIT_DIR "/config/gambit_bits.yaml");
auto gambit_bits = gambit_bits_yaml["gambit_bits"].as<std::vector<std::string>>();

// We need to manually add this here, can not be crawled by our script.
// We want to sort it again to keep alphabetical ordering from the python script after adding bits explicitly here.
gambit_bits.emplace_back(std::string{"BackendIniBit"});
std::sort(gambit_bits.begin(), gambit_bits.end());

table_formatter table("Modules", "Status", "#functions");
table.padding(1);
table.capitalize_title();
table.default_widths(25);
for (const auto &module : modules)

for (const auto &bit: gambit_bits)
{
int nf = 0;
for (const auto &functor : functorList)
table << bit;

auto result = std::find(std::begin(modules), std::end(modules), bit);
if (result == std::end(modules))
{
if (functor->origin() == module) nf++;
table.red() << "ditched";
table << "n/a";
}
else
{
int nf = 0;
for (const auto &functor : functorList)
{
if (functor->origin() == bit) nf++;
}
table.green() << "OK";
table << nf;
}
table << module << nf;
}

std::stringstream out;
out << table.str();
print_to_screen(out.str(), "module");
Expand Down
46 changes: 46 additions & 0 deletions Utils/scripts/find_all_gambit_bits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

import os
import yaml
import argparse


def get_bits_from_directory_list(gambit_directory):
"""Get Gambit Bits.

Return a sorted list of directory names with "Bit" in the name.
This effectively generates a list of all available Bits in Gambit based on the established nameing scheme inside the Gambit repository.

Args:
gambit_directory (str): Directory to search in. To work properly this has to be the Gambit source directory.

Returns:
list: sorted list of Gambit Bits
"""
return sorted(set([directory for directory in os.listdir(gambit_directory) if "Bit" in directory]))


def write_list_to_yaml(list_of_bits, output_file, yaml_key="gambit_bits"):
"""Write given list to a yaml file.

Args:
list_of_bits list(str): List of Gambit Bits.
output_file (str): Path/name for the output file.
yaml_key (str): Key which is used to write the yaml file.
"""
with open(output_file, "w+") as f:
yaml.dump({
yaml_key: list_of_bits
}, f)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="""Generates a list of all available Gambit Bits which can be used by the Gambit cmake and diagnostic systems.""")
parser.add_argument("--source-dir", required=True, help="Source directory of the Gambit repository.")
parser.add_argument("--output-file", required=True, help="Output path for the generated yaml file containing the list of Bits. Recommended to place the file in config/gambit_bits.yaml.")
args = parser.parse_args()

write_list_to_yaml(
get_bits_from_directory_list(args.source_dir),
args.output_file
)