Skip to content

Commit

Permalink
Preinstall hooks (jbcoe#126)
Browse files Browse the repository at this point in the history
* A feature test macro to spec

* Add support for pre-commit checks

* Fix merge error
  • Loading branch information
Twon authored Nov 8, 2023
1 parent f7dc9bc commit dd141a7
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 57 deletions.
17 changes: 8 additions & 9 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
Expand Down Expand Up @@ -60,12 +60,12 @@ DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Expand Down Expand Up @@ -99,9 +99,9 @@ PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
RawStringFormats:
- Language: Cpp
Delimiters:
Delimiters:
- cc
- CC
- cpp
Expand All @@ -112,12 +112,12 @@ RawStringFormats:
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
Expand Down Expand Up @@ -147,10 +147,9 @@ SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...

31 changes: 31 additions & 0 deletions .github/workflows/integrity_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Integrity Checks

on:
push:
branches: [main]
pull_request:
branches: [main]

defaults:
run:
shell: bash

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

- name: Install action-validator with asdf
uses: asdf-vm/actions/install@v2
with:
tool_versions: |
action-validator 0.5.1
- name: Lint Actions
run: |
find .github/workflows -type f \( -iname \*.yaml -o -iname \*.yml \) \
| xargs -I {} action-validator --verbose {}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
.venv/
.vs/
.vscode/
_build
Expand Down
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# .pre-commit-config.yaml
# ========================
#
# pre-commit clean
# pre-commit install
# pre-commit install-hooks
#
# precommit hooks installation
#
# - pre-commit autoupdate
#
# - pre-commit run black
#
# continuous integration
# ======================
#
# - pre-commit run --all-files
#
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: forbid-submodules
- id: requirements-txt-fixer
- id: trailing-whitespace
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ target_compile_features(polymorphic_inline_vtable
INTERFACE
cxx_std_23
)
target_compile_definitions(polymorphic_inline_vtable
INTERFACE
target_compile_definitions(polymorphic_inline_vtable
INTERFACE
XYZ_POLYMORPHIC_USES_EXPERIMENTAL_INLINE_VTABLE
)

Expand All @@ -104,8 +104,8 @@ target_compile_features(polymorphic_sbo
INTERFACE
cxx_std_23
)
target_compile_definitions(polymorphic_sbo
INTERFACE
target_compile_definitions(polymorphic_sbo
INTERFACE
XYZ_POLYMORPHIC_USES_EXPERIMENTAL_SMALL_BUFFER_OPTIMIZATION
)

Expand Down Expand Up @@ -143,7 +143,7 @@ if (${CPP_VALUE_TYPES_IS_NOT_SUBPROJECT})
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

add_executable(indirect_test "")
target_sources(indirect_test
PRIVATE
Expand Down Expand Up @@ -187,7 +187,7 @@ if (${CPP_VALUE_TYPES_IS_NOT_SUBPROJECT})
)
target_compile_options(polymorphic_sbo_test
PRIVATE
$<$<CXX_COMPILER_ID:Clang>:-ftemplate-backtrace-limit=0>
$<$<CXX_COMPILER_ID:Clang>:-ftemplate-backtrace-limit=0>
)
target_link_libraries(polymorphic_sbo_test
PRIVATE
Expand Down
4 changes: 2 additions & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@jbcoe
@twon

# CMake
# CMake
CMakeLists.txt @twon

# Bazel
# Bazel
*.bazel @jbcoe
24 changes: 12 additions & 12 deletions DRAFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct A {

class Composite {
indirect<A> a_;

Constness foo() { return a_.foo(); }
Constness foo() const { return a_.foo(); };
};
Expand Down Expand Up @@ -268,7 +268,7 @@ The template parameter `T` of `indirect` may be an incomplete type.
template <class T, class Allocator = std::allocator<T>>
class indirect {
T* p_; // exposition only
Allocator allocator_; // exposition only
Allocator allocator_; // exposition only
public:
using value_type = T;
using allocator_type = Allocator;
Expand All @@ -288,7 +288,7 @@ class indirect {
std::allocator_arg_t, const Allocator& alloc, const indirect& other);
constexpr indirect(indirect&& other) noexcept;
constexpr indirect(
std::allocator_arg_t, const Allocator& alloc, indirect&& other) noexcept;
Expand Down Expand Up @@ -665,7 +665,7 @@ constexpr auto operator<=>(const U& lhs, const indirect<T, A>& rhs);
* _Preconditions_: Alloc meets the _Cpp17Allocator_ requirements.
#### X.Y.10 Hash support [indirect.hash]
```c++
template <class T, class Alloc>
struct std::hash<indirect<T, Alloc>>;
Expand Down Expand Up @@ -756,7 +756,7 @@ The template parameter `T` of `polymorphic` may be an incomplete type.
template <class T, class Allocator = std::allocator<T>>
class polymorphic {
control_block* control_block_; // exposition only
Allocator allocator_; // exposition only
Allocator allocator_; // exposition only
public:
using value_type = T;
using allocator_type = Allocator;
Expand All @@ -771,12 +771,12 @@ class polymorphic {
std::allocator_arg_t, const Allocator& alloc, std::in_place_type_t<U>, Ts&&... ts);

constexpr polymorphic(const polymorphic& other);

constexpr polymorphic(
std::allocator_arg_t, const Allocator& alloc, const polymorphic& other);

constexpr polymorphic(polymorphic&& other) noexcept;

constexpr polymorphic(
std::allocator_arg_t, const Allocator& alloc, polymorphic&& other) noexcept;

Expand Down Expand Up @@ -972,7 +972,7 @@ constexpr allocator_type get_allocator() const noexcept;
* _Returns_: A copy of the Allocator object used to construct the owned object
or, if that allocator has been replaced, a copy of the most recent
replacement.

#### X.Z.7 Swap [polymorphic.swap]

```c++
Expand Down Expand Up @@ -1029,7 +1029,7 @@ Otherwise, the interface of the specialization is as defined in [optional].
Add a new feature-test macro:

```c++
#define __cpp_lib_polymorphic 2023XXL
#define __cpp_lib_value_types 2023XXL
```
## Reference implementation
Expand Down Expand Up @@ -1241,7 +1241,7 @@ class Class {
Class& operator=(const Class&);
Class(Class&&) noexcept;
Class& operator=(Class&&) noexcept;

void do_something();
};
```
Expand Down Expand Up @@ -1291,7 +1291,7 @@ class Class {
Class& operator=(const Class&);
Class(Class&&) noexcept;
Class& operator=(Class&&) noexcept;

void do_something();
};
```
Expand Down Expand Up @@ -1368,7 +1368,7 @@ class Picture {
```
#### After, using `polymorphic`
```c++
class Canvas;
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Composite {
xyz::indirect<A> a_; // a_ owns an object of type A
xyz::indirect<B> b_; // b_ owns an object of type B
public:
Composite(const A& a, const B& b) :
a_(std::in_place, a),
Composite(const A& a, const B& b) :
a_(std::in_place, a),
b_(std::in_place, b) {}

// ...
Expand All @@ -69,8 +69,8 @@ class CompositeWithPolymorphicMembers {
xyz::polymorphic<Y> y_; // y_ owns an object of type Y or derived from Y
public:
template <typename Tx, typename Ty>
Composite(const Tx& x, const Ty& y) :
a_(std::in_place_type<Tx>, x),
Composite(const Tx& x, const Ty& y) :
a_(std::in_place_type<Tx>, x),
b_(std::in_place_type<Ty>, y) {}
// ...
Expand All @@ -94,12 +94,16 @@ This code is licensed under the MIT License. See [LICENSE](LICENSE) for details.
## Talks and presentations

We spoke about an earlier draft at [C++ on
Sea](https://www.youtube.com/watch?v=sjLRX4WMvlU) in 2022.
Sea](https://www.youtube.com/watch?v=sjLRX4WMvlU) in 2022.

There are some significant design changes since this talk was given (after feedback
and discussion at a C++ London meetup). We've pared down the number of constructors
There are some significant design changes since this talk was given (after feedback
and discussion at a C++ London meetup). We've pared down the number of constructors
and made the null state unobservable.

## Developer Guide

For building and working with the project, please see the [developer guide](docs/developer-guide.md).

## References

* [TK's allocator user guide]
Expand Down
44 changes: 44 additions & 0 deletions docs/developer-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Using pre-commit for git hooks

This repository uses the Python `pre-commit` library to manage git hook run as
part of the commit process. Use the following steps to install a virtual
environment with pre-commmit set up, and then use precommit to install git hooks
it to your local repository.

```bash
cd <project root>
python3 -m venv .venv # Create a Python virtual env
source ./.venv/bin/activate # Activate the virtual env for bash by source.
pip install -r requirements.txt # Install latest requirements including pre-commit
pre-commit install # Use pre-commit to install git hooks into the working repository.
```

# Building with CMake

To build the repository with CMake use the following steps
```bash
cd <project root>
mkdir build # Make a build directory
cd build # Switch into the build directory
cmake ../ # Generate build system specified in root with cmake
cmake --build ./ # Build the underlying build system via CMake
```

# Including in your own project

To use the value types code in your own CMake project then you can pull
the project in as a dependency via CMake's FetchContent module as follows:

```
FetchContent_Declare(
value_types
GIT_REPOSITORY https://github.com/jbcoe/value_types
)
FetchContent_MakeAvailable(value_types)
add_executable(my_program)
target_link_libraries(my_program
PUBLIC
value_types::value_types
)
```
Loading

0 comments on commit dd141a7

Please sign in to comment.