Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update @bazel_clang_format and source file formatting #61

Merged
merged 1 commit into from
Jun 29, 2024
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
17 changes: 12 additions & 5 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ build --nolegacy_important_outputs
build:clang --extra_toolchains=//toolchain:clang
build:gcc --extra_toolchains=//toolchain:gcc

build:clang-format --aspects @bazel_clang_format//:defs.bzl%clang_format_aspect
build:clang-format --@bazel_clang_format//:binary=@llvm_toolchain//:clang-format
build:clang-format --@bazel_clang_format//:config=//:format_config
build:clang-format --output_groups=report
build:clang-format --keep_going
build --@bazel_clang_format//:binary=@llvm_toolchain//:clang-format
build --@bazel_clang_format//:config=//:format_config

build:clang-format-base --output_groups=report
build:clang-format-base --keep_going

build:clang-format --config=clang-format-base
build:clang-format --aspects @bazel_clang_format//:defs.bzl%check_aspect

build:clang-format-fix --config=clang-format-base
build:clang-format-fix --aspects @bazel_clang_format//:defs.bzl%fix_aspect
build:clang-format-fix --use_action_cache=false

build:clang-tidy-base --config=clang
build:clang-tidy-base --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
Expand Down
8 changes: 5 additions & 3 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,17 @@ register_toolchains(
"@gcc_toolchain//:toolchain",
)

BAZEL_CLANG_FORMAT_COMMIT = "d7c679e9478c6f64f5d7e5d151ad22e6507718bd"
BAZEL_CLANG_FORMAT_COMMIT = "b6473887d54512becb88bd1985bca110d0193fd3"

http_archive(
name = "bazel_clang_format",
integrity = "sha256-uRqzR4YmVrUcC2YBpymr3gKVzCZogmWVywo73pPYL60=",
integrity = "sha256-eLLwaG09kfljgB0/XCPAKUqHRlo9oQInynnwdmLvOqI=",
strip_prefix = "bazel_clang_format-{commit}".format(
commit = BAZEL_CLANG_FORMAT_COMMIT,
),
url = "https://github.com/oliverlee/bazel_clang_format/archive/%s.tar.gz" % BAZEL_CLANG_FORMAT_COMMIT,
url = "https://github.com/oliverlee/bazel_clang_format/archive/{commit}.tar.gz".format(
commit = BAZEL_CLANG_FORMAT_COMMIT,
),
)

BAZEL_CLANG_TIDY_COMMIT = "aae87699cca19d8f6e84538576ab47587043d1d2"
Expand Down
3 changes: 1 addition & 2 deletions exercises/2.12.1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ struct line
V2 direction;

[[nodiscard]]
constexpr
operator std::tuple<V1, V2>() const
constexpr operator std::tuple<V1, V2>() const
{
return {position, direction};
}
Expand Down
37 changes: 14 additions & 23 deletions geometry/src/algebra_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,38 +174,32 @@ struct algebra_core
///
/// @{
[[nodiscard]]
friend constexpr auto
operator==(blade x, blade y) noexcept -> bool
friend constexpr auto operator==(blade x, blade y) noexcept -> bool
{
return x.coefficient == y.coefficient;
}
[[nodiscard]]
friend constexpr auto
operator!=(blade x, blade y) noexcept -> bool
friend constexpr auto operator!=(blade x, blade y) noexcept -> bool
{
return x.coefficient != y.coefficient;
}
[[nodiscard]]
friend constexpr auto
operator<(blade x, blade y) noexcept -> bool
friend constexpr auto operator<(blade x, blade y) noexcept -> bool
{
return x.coefficient < y.coefficient;
}
[[nodiscard]]
friend constexpr auto
operator>(blade x, blade y) noexcept -> bool
friend constexpr auto operator>(blade x, blade y) noexcept -> bool
{
return x.coefficient > y.coefficient;
}
[[nodiscard]]
friend constexpr auto
operator<=(blade x, blade y) noexcept -> bool
friend constexpr auto operator<=(blade x, blade y) noexcept -> bool
{
return x.coefficient <= y.coefficient;
}
[[nodiscard]]
friend constexpr auto
operator>=(blade x, blade y) noexcept -> bool
friend constexpr auto operator>=(blade x, blade y) noexcept -> bool
{
return x.coefficient >= y.coefficient;
}
Expand All @@ -214,8 +208,7 @@ struct algebra_core
/// unary negation
///
[[nodiscard]]
friend constexpr auto
operator-(blade x) -> blade
friend constexpr auto operator-(blade x) -> blade
{
return blade{-x.coefficient};
}
Expand All @@ -224,8 +217,7 @@ struct algebra_core
///
/// @{
[[nodiscard]]
friend constexpr auto
operator+(blade x, blade y) -> blade
friend constexpr auto operator+(blade x, blade y) -> blade
{
return blade{x.coefficient + y.coefficient};
}
Expand All @@ -242,8 +234,7 @@ struct algebra_core
///
template <std::size_t... Js>
[[nodiscard]]
friend constexpr auto
operator*(blade x, blade<Js...> y)
friend constexpr auto operator*(blade x, blade<Js...> y)
{
constexpr auto unit_blade_coeff =
reified_blade_coefficient_v<Is..., Js...>;
Expand All @@ -259,9 +250,10 @@ struct algebra_core

/// stream insertion
///
friend auto operator<<(std::ostream& os, blade x) -> std::enable_if_t<
(N < 10),
decltype(os << std::declval<const scalar_type&>(), os)>
friend auto operator<<(std::ostream& os, blade x)
-> std::enable_if_t<
(N < 10),
decltype(os << std::declval<const scalar_type&>(), os)>
{
if (sizeof...(Is) == 0) {
os << x.coefficient;
Expand Down Expand Up @@ -375,8 +367,7 @@ struct algebra_core
/// unary negation
///
[[nodiscard]]
friend constexpr auto
operator-(const multivector& x) -> multivector
friend constexpr auto operator-(const multivector& x) -> multivector
{
return multivector{-get<Bs>(x)...};
}
Expand Down
3 changes: 1 addition & 2 deletions geometry/src/detail/multivector_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ inline constexpr class
class ExprFilter,
class T>
[[nodiscard]]
constexpr auto
operator()(
constexpr auto operator()(
const multivector<B1s...>& x,
const multivector<B2s...>& y,
ExprFilter pred,
Expand Down
6 changes: 2 additions & 4 deletions geometry/src/equality_comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ namespace geometry {
/// @{
template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator==(const T1& x, const T2& y)
constexpr auto operator==(const T1& x, const T2& y)
{
return to_multivector<A>(x) == to_multivector<A>(y);
}
template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator!=(const T1& x, const T2& y) -> decltype(x == y)
constexpr auto operator!=(const T1& x, const T2& y) -> decltype(x == y)
{
return not(x == y);
}
Expand Down
3 changes: 1 addition & 2 deletions geometry/src/exterior_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ inline constexpr auto exterior_product = //

template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator^(const T1& x, const T2& y)
constexpr auto operator^(const T1& x, const T2& y)
{
return exterior_product(x, y);
}
Expand Down
9 changes: 4 additions & 5 deletions geometry/src/geometric_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ inline constexpr class
class D2 = std::decay_t<typename T2::eval_type>,
class Algebra = common_algebra_type_t<D1, D2>,
class L = detail::pending_dimensions_list_t<D1, D2>>
constexpr auto
operator()(expression_template::op<expression_template::multiplies, T1, T2>)
const -> std::bool_constant<
constexpr auto operator()(
expression_template::op<expression_template::multiplies, T1, T2>) const
-> std::bool_constant<
tmp::convert_to_sequence_t<
L,
Algebra::template reified_blade_coefficient>::value == 0>
Expand All @@ -47,8 +47,7 @@ inline constexpr auto geometric_product = //

template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator*(const T1& x, const T2& y)
constexpr auto operator*(const T1& x, const T2& y)
{
return geometric_product(x, y);
}
Expand Down
2 changes: 1 addition & 1 deletion geometry/src/get.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct get_fn
class V,
class D = std::decay_t<V>,
class = std::enable_if_t<is_multivector_v<D> and D::template contains<B>>>
constexpr decltype(auto) operator()(V && v) const
constexpr decltype(auto) operator()(V&& v) const
{
return get<B>(std::forward<V>(v));
}
Expand Down
2 changes: 1 addition & 1 deletion geometry/src/get_or.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct get_or_fn
class = std::enable_if_t<
is_multivector_v<V> and is_blade_v<B>,
common_algebra_type_t<V, B>>>
constexpr decltype(auto) operator()(const V & v, const B & value) const
constexpr decltype(auto) operator()(const V& v, const B& value) const
{
return get_or(v, value);
}
Expand Down
6 changes: 2 additions & 4 deletions geometry/src/regressive_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ inline constexpr struct
{
template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator()(const T1& x, const T2& y) const
constexpr auto operator()(const T1& x, const T2& y) const
{
return undual(dual(x) ^ dual(y));
}
} regressive_product{};

template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator&(const T1& x, const T2& y)
constexpr auto operator&(const T1& x, const T2& y)
{
return regressive_product(x, y);
}
Expand Down
9 changes: 3 additions & 6 deletions geometry/src/sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ inline constexpr class
public:
template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator()(const T1& x, const T2& y) const
constexpr auto operator()(const T1& x, const T2& y) const
{
return impl(to_multivector<A>(x), to_multivector<A>(y));
}
} sum{};

template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator+(const T1& x, const T2& y)
constexpr auto operator+(const T1& x, const T2& y)
{
return sum(x, y);
}
Expand All @@ -66,8 +64,7 @@ operator+(const T1& x, const T2& y)
///
template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
[[nodiscard]]
constexpr auto
operator-(const T1& x, const T2& y)
constexpr auto operator-(const T1& x, const T2& y)
{
return x + -y;
}
Expand Down
7 changes: 4 additions & 3 deletions geometry/type_metaprogramming/cartesian_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ template <
struct cartesian_product<list1<Ts...>, list2<Us...>>
{
template <std::size_t... Is>
static auto impl(std::index_sequence<Is...>) -> list<std::pair<
std::tuple_element_t<(Is / sizeof...(Us)), std::tuple<Ts...>>,
std::tuple_element_t<(Is % sizeof...(Us)), std::tuple<Us...>>>...>;
static auto impl(std::index_sequence<Is...>)
-> list<std::pair<
std::tuple_element_t<(Is / sizeof...(Us)), std::tuple<Ts...>>,
std::tuple_element_t<(Is % sizeof...(Us)), std::tuple<Us...>>>...>;

using type =
decltype(impl(std::make_index_sequence<sizeof...(Ts) * sizeof...(Us)>{}));
Expand Down
2 changes: 1 addition & 1 deletion geometry/type_metaprogramming/same.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct same : std::true_type
{};

template <class T, class... Ts>
struct same<T, Ts...> : std::bool_constant<((std::is_same_v<T, Ts>)and...)>
struct same<T, Ts...> : std::bool_constant<((std::is_same_v<T, Ts>) and ...)>
{};

template <class... Ts>
Expand Down
3 changes: 1 addition & 2 deletions test/algebra_multivector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ inline constexpr struct
sizeof...(Bs) != 0,
::geometry::common_algebra_type_t<Bs...>>>
[[nodiscard]]
constexpr auto
operator()(Bs... bs) const
constexpr auto operator()(Bs... bs) const
{
return typename Algebra::template multivector<Bs...>{bs...};
}
Expand Down
23 changes: 15 additions & 8 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
load("@bazel_clang_format//:defs.bzl", "clang_format_update")
load("@bazel_clang_tidy//:defs.bzl", "clang_tidy_apply_fixes")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
load("//rules:lcov.bzl", "lcov")
load("@rules_multirun//:defs.bzl", "multirun")

clang_format_update(
name = "clang-format",
binary = "@llvm_toolchain//:clang-format",
config = "//:format_config",
)

clang_tidy_apply_fixes(
name = "clang-tidy-fix",
apply_replacements_binary = "@llvm_toolchain//:clang-apply-replacements",
Expand All @@ -29,13 +22,27 @@ buildifier(
mode = "fix",
)

genrule(
name = "gen-clang-format",
outs = ["clang-format.sh"],
cmd = """
echo "#!/bin/bash" > $@
echo "cd \\$$BUILD_WORKSPACE_DIRECTORY" >> $@
echo "exec bazel build --announce_rc=false //... --config=clang-format-fix" >> $@
""",
)

sh_binary(
name = "clang-format",
srcs = ["clang-format.sh"],
)

multirun(
name = "format",
commands = [
":buildifier.fix",
":clang-format",
],
jobs = 0,
)

genrule(
Expand Down