Skip to content

Commit

Permalink
🪝 Set up pre-commit checks (#341)
Browse files Browse the repository at this point in the history
* 🪝 Added a simple initial pre-commit configuration

* 🎨 Incorporated pre-commit fixes

* 🪝 Added a check to handle unwanted unicode characters

* 🎨 Incorporated pre-commit fixes

* 🪝 Added a check for common RST mistakes

* 🎨 Incorporated pre-commit fixes

* 🪝 Added an automatic clang-format check

* 🎨 Incorporated pre-commit fixes

* 🪝 Added a check for CMake linting and formatting

* 🎨 Incorporated pre-commit fixes
  • Loading branch information
marcelwa authored Nov 27, 2023
1 parent 8e61624 commit 481331f
Show file tree
Hide file tree
Showing 33 changed files with 1,656 additions and 1,571 deletions.
4 changes: 2 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ footer: |
template: |
## 👀 What's Changed
$CHANGES
**Full [CHANGELOG](https://fiction.readthedocs.io/en/latest/changelog.html)**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
large-packages: false
docker-images: false
swap-storage: false

- name: Install libraries and the respective compiler
run: sudo apt-get update && sudo apt-get install -yq libtbb-dev ${{matrix.compiler}}

Expand Down
62 changes: 62 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# To run all pre-commit checks, use:
#
# pre-commit run -a
#
# To install pre-commit hooks that run every time you commit:
#
# pre-commit install
#

ci:
autoupdate_commit_msg: "⬆️ Bump pre-commit hooks"
autofix_commit_msg: "🎨 Incorporated pre-commit fixes"

exclude: "^libs/|^benchmarks/"

repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

# Handle unwanted unicode characters
- repo: https://github.com/sirosen/texthooks
rev: 0.6.2
hooks:
- id: fix-ligatures
- id: fix-smartquotes

# Check for common RST mistakes
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

# clang-format the C++ part of the code base
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.4
hooks:
- id: clang-format
types_or: [ c++, c ]
args: [ "-style=file" ]

# CMake format and lint the CMakeLists.txt files
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: [ pyyaml ]
- id: cmake-lint
additional_dependencies: [ pyyaml ]
105 changes: 53 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# Large parts of this build system are based on Jason Turner's
# C++ Starter Project (https://github.com/lefticus/cpp_starter_project) and
# CMake Template (https://github.com/cpp-best-practices/cmake_template)
# Large parts of this build system are based on Jason Turner's C++ Starter
# Project (https://github.com/lefticus/cpp_starter_project) and CMake Template
# (https://github.com/cpp-best-practices/cmake_template)

cmake_minimum_required(VERSION 3.21)

# Only set the CMAKE_CXX_STANDARD if it is not set by someone else
if (NOT DEFINED CMAKE_CXX_STANDARD)
# Set C++ standard; at least C++17 is required
set(CMAKE_CXX_STANDARD 17)
endif ()
if(NOT DEFINED CMAKE_CXX_STANDARD)
# Set C++ standard; at least C++17 is required
set(CMAKE_CXX_STANDARD 17)
endif()

# strongly encouraged to enable this globally to avoid conflicts between
# -Wpedantic being enabled and -std=c++20 and -std=gnu++20 for example
# when compiling with PCH enabled
# -Wpedantic being enabled and -std=c++20 and -std=gnu++20 for example when
# compiling with PCH enabled
set(CMAKE_CXX_EXTENSIONS OFF)

# Set the project name and version
project(fiction
VERSION 0.5.0
DESCRIPTION "An open-source design automation framework for Field-coupled Nanotechnologies"
HOMEPAGE_URL "https://github.com/cda-tum/fiction"
LANGUAGES CXX C)
project(
fiction
VERSION 0.5.0
DESCRIPTION
"An open-source design automation framework for Field-coupled Nanotechnologies"
HOMEPAGE_URL "https://github.com/cda-tum/fiction"
LANGUAGES CXX C)

include(cmake/PreventInSourceBuilds.cmake)
include(cmake/ProjectOptions.cmake)
Expand All @@ -30,18 +32,13 @@ fiction_setup_options()
fiction_global_options()
fiction_local_options()


# don't know if this should be set globally from here or not...
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set(GIT_SHA
"Unknown"
CACHE STRING "SHA this build was generated from")
string(
SUBSTRING "${GIT_SHA}"
0
8
GIT_SHORT_SHA)
"Unknown"
CACHE STRING "SHA this build was generated from")
string(SUBSTRING "${GIT_SHA}" 0 8 GIT_SHORT_SHA)

target_compile_features(fiction_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD})

Expand All @@ -57,46 +54,50 @@ add_subdirectory(include)
add_subdirectory(libs)

# Enable progress bars
if (NOT WIN32)
option(FICTION_PROGRESS_BARS "Enable animated progress bars in command line" ON)
if (FICTION_PROGRESS_BARS)
target_compile_definitions(fiction_options INTERFACE PROGRESS_BARS)
endif ()
endif ()
if(NOT WIN32)
option(FICTION_PROGRESS_BARS "Enable animated progress bars in command line"
ON)
if(FICTION_PROGRESS_BARS)
target_compile_definitions(fiction_options INTERFACE PROGRESS_BARS)
endif()
endif()

# CLI
option(FICTION_CLI "Build fiction CLI" ON)
if (FICTION_CLI)
message(STATUS "Building fiction CLI")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cli)
endif ()
if(FICTION_CLI)
message(STATUS "Building fiction CLI")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cli)
endif()

# Experiments
option(FICTION_EXPERIMENTS "Build fiction experiments" OFF)
if (FICTION_EXPERIMENTS)
message(STATUS "Building fiction experiments")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/experiments)
endif ()
if(FICTION_EXPERIMENTS)
message(STATUS "Building fiction experiments")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/experiments)
endif()

# Testing
option(FICTION_TEST "Build fiction tests" OFF)
if (FICTION_TEST)
enable_testing()
message(STATUS "Building fiction tests")
add_subdirectory(test)
endif ()

# If MSVC is being used, and ASAN is enabled, we need to set the debugger environment
# so that it behaves well with MSVC's debugger, and we can run the target from visual studio
if (MSVC)
get_all_installable_targets(all_targets)
message("all_targets=${all_targets}")
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%")
endif ()
if(FICTION_TEST)
enable_testing()
message(STATUS "Building fiction tests")
add_subdirectory(test)
endif()

# If MSVC is being used, and ASAN is enabled, we need to set the debugger
# environment so that it behaves well with MSVC's debugger, and we can run the
# target from visual studio
if(MSVC)
get_all_installable_targets(all_targets)
message("all_targets=${all_targets}")
set_target_properties(
${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT
"PATH=$(VC_ExecutablePath_x64);%PATH%")
endif()

# set the startup project for the "play" button in MSVC
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT intro)

if (CMAKE_SKIP_INSTALL_RULES)
return()
endif ()
if(CMAKE_SKIP_INSTALL_RULES)
return()
endif()
43 changes: 19 additions & 24 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET(SOURCES ${PROJECT_SOURCE_DIR}/cli/fiction.cpp)
set(SOURCES ${PROJECT_SOURCE_DIR}/cli/fiction.cpp)

# Include configuration file
include_directories(${PROJECT_BINARY_DIR}/include/)
Expand All @@ -10,36 +10,31 @@ add_executable(fiction ${SOURCES})
target_link_libraries(fiction PRIVATE libfiction alice)

# Strip the executable if we are in Release mode
if (CMAKE_BUILD_TYPE STREQUAL "Release")
if (CMAKE_STRIP)
add_custom_command(
TARGET fiction
POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:fiction>
)
else ()
message(WARNING "Strip command is not available. The executables will not be stripped.")
endif ()
endif ()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CMAKE_STRIP)
add_custom_command(
TARGET fiction
POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:fiction>)
else()
message(
WARNING
"Strip command is not available. The executables will not be stripped.")
endif()
endif()

# Package the CLI executable
include(../cmake/PackageProject.cmake)

# Add other targets that you want installed here, by default we just package the one executable
# we know we want to ship
fiction_package_project(
TARGETS
fiction
fiction_options
fiction_warnings
)
# Add other targets that you want installed here, by default we just package the
# one executable we know we want to ship
fiction_package_project(TARGETS fiction fiction_options fiction_warnings)

# Experience shows that explicit package naming can help make it easier to sort
# out potential ABI related issues before they start, while helping you
# track a build to a specific GIT SHA
# out potential ABI related issues before they start, while helping you track a
# build to a specific GIT SHA
set(CPACK_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${GIT_SHORT_SHA}-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}"
"${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${GIT_SHORT_SHA}-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}"
)

include(CPack)
2 changes: 1 addition & 1 deletion cli/cmd/io/tt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class tt_command : public command
"expression !E, the conjunction of multiple expressions (E...E), the disjunction of "
"multiple expressions {E...E}, the exclusive OR of multiple expressions [E...E], or the "
"majority of three expressions <EEE>. Examples are [(ab)(!ac)] to describe if-then-else, "
"or !{!a!b} to describe the application of De Morgans law to (ab). The size of the truth "
"or !{!a!b} to describe the application of De Morgan's law to (ab). The size of the truth "
"table must fit the largest variable in the expression, e.g., if c is the largest "
"variable, then the truth table have at least three variables.")
{
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/logic/miginvopt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class miginvopt_command : public command
// clone it because inverter optimization is an in-place algorithm
auto ntk_clone = ntk_ptr->clone();

// mockturtle::fanout_view fo_ntk_clone{ntk_clone};
// mockturtle::fanout_view fo_ntk_clone{ntk_clone};
mockturtle::mig_inv_optimization(ntk_clone, &st);

const auto mig_ptr = std::make_shared<fiction::mig_nt>(ntk_clone);
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/physical_design/exact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,4 @@ ALICE_ADD_COMMAND(exact, "Physical Design")

#endif // FICTION_CMD_EXACT_HPP

#endif // FICTION_Z3_SOLVER
#endif // FICTION_Z3_SOLVER
53 changes: 25 additions & 28 deletions cmake/Cache.cmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
# Enable cache if available
function(fiction_enable_cache)
set(CACHE_OPTION
"ccache"
CACHE STRING "Compiler cache to be used")
set(CACHE_OPTION_VALUES "ccache" "sccache")
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES})
list(
FIND
CACHE_OPTION_VALUES
${CACHE_OPTION}
CACHE_OPTION_INDEX)
set(CACHE_OPTION
"ccache"
CACHE STRING "Compiler cache to be used")
set(CACHE_OPTION_VALUES "ccache" "sccache")
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES})
list(FIND CACHE_OPTION_VALUES ${CACHE_OPTION} CACHE_OPTION_INDEX)

if (${CACHE_OPTION_INDEX} EQUAL -1)
message(
STATUS
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}"
)
endif ()
if(${CACHE_OPTION_INDEX} EQUAL -1)
message(
STATUS
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}"
)
endif()

find_program(CACHE_BINARY NAMES ${CACHE_OPTION_VALUES})
if (CACHE_BINARY)
message(STATUS "${CACHE_BINARY} found and enabled")
set(CMAKE_CXX_COMPILER_LAUNCHER
${CACHE_BINARY}
CACHE FILEPATH "CXX compiler cache used")
set(CMAKE_C_COMPILER_LAUNCHER
${CACHE_BINARY}
CACHE FILEPATH "C compiler cache used")
else ()
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it")
endif ()
find_program(CACHE_BINARY NAMES ${CACHE_OPTION_VALUES})
if(CACHE_BINARY)
message(STATUS "${CACHE_BINARY} found and enabled")
set(CMAKE_CXX_COMPILER_LAUNCHER
${CACHE_BINARY}
CACHE FILEPATH "CXX compiler cache used")
set(CMAKE_C_COMPILER_LAUNCHER
${CACHE_BINARY}
CACHE FILEPATH "C compiler cache used")
else()
message(
WARNING "${CACHE_OPTION} is enabled but was not found. Not using it")
endif()
endfunction()
14 changes: 8 additions & 6 deletions cmake/CheckSubmodules.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# check whether the submodule ``modulename`` is correctly cloned in the ``/libs`` directory.
# check whether the submodule ``modulename`` is correctly cloned in the
# ``/libs`` directory.
macro(check_if_present modulename)
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/libs/${modulename}/CMakeLists.txt")
message(
FATAL_ERROR
"Submodule `${modulename}` not cloned properly. Please run `git submodule update --init --recursive` from the main project directory to fix this issue.")
endif ()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/libs/${modulename}/CMakeLists.txt")
message(
FATAL_ERROR
"Submodule `${modulename}` not cloned properly. Please run `git submodule update --init --recursive` from the main project directory to fix this issue."
)
endif()
endmacro()
Loading

0 comments on commit 481331f

Please sign in to comment.