From 8bd614bb1e8e72d4ee1f773141656afa3c2fe1bd Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 18 May 2022 12:23:15 -0700 Subject: [PATCH] [upstream_utils] Use "git am" instead of "git apply" for patches (#4248) This creates actual commits in the thirdparty repo, which makes rebasing them onto new versions much easier. --- .../drake-replace-dense-with-core.patch | 64 --------------- ...-Replace-Eigen-Dense-with-Eigen-Core.patch | 79 +++++++++++++++++++ ...XPORT-to-DARE-function-declarations.patch} | 20 ++++- .../0001-Don-t-throw-on-write-failure.patch} | 38 ++++++--- upstream_utils/update_drake.py | 15 ++-- upstream_utils/update_fmt.py | 10 ++- 6 files changed, 136 insertions(+), 90 deletions(-) delete mode 100644 upstream_utils/drake-replace-dense-with-core.patch create mode 100644 upstream_utils/drake_patches/0001-Replace-Eigen-Dense-with-Eigen-Core.patch rename upstream_utils/{drake-dllexport-dare.patch => drake_patches/0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch} (60%) rename upstream_utils/{fmt-dont-throw-on-write-failure.patch => fmt_patches/0001-Don-t-throw-on-write-failure.patch} (62%) diff --git a/upstream_utils/drake-replace-dense-with-core.patch b/upstream_utils/drake-replace-dense-with-core.patch deleted file mode 100644 index d225597bd3..0000000000 --- a/upstream_utils/drake-replace-dense-with-core.patch +++ /dev/null @@ -1,64 +0,0 @@ -diff --git b/wpimath/src/main/native/include/drake/common/is_approx_equal_abstol.h a/wpimath/src/main/native/include/drake/common/is_approx_equal_abstol.h -index 9af0c4525..b3f369ca0 100644 ---- b/wpimath/src/main/native/include/drake/common/is_approx_equal_abstol.h -+++ a/wpimath/src/main/native/include/drake/common/is_approx_equal_abstol.h -@@ -2,7 +2,7 @@ - - #include - --#include -+#include - - namespace drake { - -diff --git a/wpimath/src/main/native/cpp/drake/math/discrete_algebraic_riccati_equation.cpp b/wpimath/src/main/native/cpp/drake/math/discrete_algebraic_riccati_equation.cpp -index 9585c4dae..49c2fefe7 100644 ---- a/wpimath/src/main/native/cpp/drake/math/discrete_algebraic_riccati_equation.cpp -+++ b/wpimath/src/main/native/cpp/drake/math/discrete_algebraic_riccati_equation.cpp -@@ -1,5 +1,8 @@ - #include "drake/math/discrete_algebraic_riccati_equation.h" - -+#include -+#include -+ - #include "drake/common/drake_assert.h" - #include "drake/common/drake_throw.h" - #include "drake/common/is_approx_equal_abstol.h" -diff --git b/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h a/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h -index b64bfe75e..fc5efb313 100644 ---- b/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h -+++ a/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h -@@ -3,7 +3,7 @@ - #include - #include - --#include -+#include - - namespace drake { - namespace math { - -diff --git b/wpimath/src/test/native/cpp/drake/discrete_algebraic_riccati_equation_test.cpp a/wpimath/src/test/native/cpp/drake/discrete_algebraic_riccati_equation_test.cpp -index 74aa4b23d..2deb039a0 100644 ---- b/wpimath/src/test/native/cpp/drake/discrete_algebraic_riccati_equation_test.cpp -+++ a/wpimath/src/test/native/cpp/drake/discrete_algebraic_riccati_equation_test.cpp -@@ -1,5 +1,6 @@ - #include "drake/math/discrete_algebraic_riccati_equation.h" - -+#include - #include - - #include "drake/common/test_utilities/eigen_matrix_compare.h" -diff --git b/wpimath/src/test/native/include/drake/common/test_utilities/eigen_matrix_compare.h a/wpimath/src/test/native/include/drake/common/test_utilities/eigen_matrix_compare.h -index e3bd85349..d6bcbb8ec 100644 ---- b/wpimath/src/test/native/include/drake/common/test_utilities/eigen_matrix_compare.h -+++ a/wpimath/src/test/native/include/drake/common/test_utilities/eigen_matrix_compare.h -@@ -4,7 +4,7 @@ - #include - #include - --#include -+#include - #include - - // #include "drake/common/text_logging.h" diff --git a/upstream_utils/drake_patches/0001-Replace-Eigen-Dense-with-Eigen-Core.patch b/upstream_utils/drake_patches/0001-Replace-Eigen-Dense-with-Eigen-Core.patch new file mode 100644 index 0000000000..b654f63c0c --- /dev/null +++ b/upstream_utils/drake_patches/0001-Replace-Eigen-Dense-with-Eigen-Core.patch @@ -0,0 +1,79 @@ +From ef037207c433f16721d1f0574bde984b4bdea1f8 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Wed, 18 May 2022 11:13:21 -0700 +Subject: [PATCH 1/2] Replace with + +--- + common/is_approx_equal_abstol.h | 2 +- + common/test_utilities/eigen_matrix_compare.h | 2 +- + math/discrete_algebraic_riccati_equation.cc | 3 +++ + math/discrete_algebraic_riccati_equation.h | 2 +- + math/test/discrete_algebraic_riccati_equation_test.cc | 1 + + 5 files changed, 7 insertions(+), 3 deletions(-) + +diff --git a/common/is_approx_equal_abstol.h b/common/is_approx_equal_abstol.h +index 9af0c45252..b3f369ca01 100644 +--- a/common/is_approx_equal_abstol.h ++++ b/common/is_approx_equal_abstol.h +@@ -2,7 +2,7 @@ + + #include + +-#include ++#include + + namespace drake { + +diff --git a/common/test_utilities/eigen_matrix_compare.h b/common/test_utilities/eigen_matrix_compare.h +index a595da9510..c22567d32c 100644 +--- a/common/test_utilities/eigen_matrix_compare.h ++++ b/common/test_utilities/eigen_matrix_compare.h +@@ -4,7 +4,7 @@ + #include + #include + +-#include ++#include + #include + + #include "drake/common/text_logging.h" +diff --git a/math/discrete_algebraic_riccati_equation.cc b/math/discrete_algebraic_riccati_equation.cc +index 901f2ef240..20ea2b7bbe 100644 +--- a/math/discrete_algebraic_riccati_equation.cc ++++ b/math/discrete_algebraic_riccati_equation.cc +@@ -1,5 +1,8 @@ + #include "drake/math/discrete_algebraic_riccati_equation.h" + ++#include ++#include ++ + #include "drake/common/drake_assert.h" + #include "drake/common/drake_throw.h" + #include "drake/common/is_approx_equal_abstol.h" +diff --git a/math/discrete_algebraic_riccati_equation.h b/math/discrete_algebraic_riccati_equation.h +index 891373ff9d..df7a58b2b8 100644 +--- a/math/discrete_algebraic_riccati_equation.h ++++ b/math/discrete_algebraic_riccati_equation.h +@@ -3,7 +3,7 @@ + #include + #include + +-#include ++#include + + namespace drake { + namespace math { +diff --git a/math/test/discrete_algebraic_riccati_equation_test.cc b/math/test/discrete_algebraic_riccati_equation_test.cc +index 533ced151d..e4ecfd2eb5 100644 +--- a/math/test/discrete_algebraic_riccati_equation_test.cc ++++ b/math/test/discrete_algebraic_riccati_equation_test.cc +@@ -1,5 +1,6 @@ + #include "drake/math/discrete_algebraic_riccati_equation.h" + ++#include + #include + + #include "drake/common/test_utilities/eigen_matrix_compare.h" +-- +2.36.1 + diff --git a/upstream_utils/drake-dllexport-dare.patch b/upstream_utils/drake_patches/0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch similarity index 60% rename from upstream_utils/drake-dllexport-dare.patch rename to upstream_utils/drake_patches/0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch index a37dacd9b0..764330b014 100644 --- a/upstream_utils/drake-dllexport-dare.patch +++ b/upstream_utils/drake_patches/0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch @@ -1,7 +1,16 @@ -diff --git b/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h a/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h -index df7a58b2b..55b8442bf 100644 ---- b/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h -+++ a/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h +From 7dfb527524f42488a00cf156ada36c51d5e13b3f Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Wed, 18 May 2022 11:15:27 -0700 +Subject: [PATCH 2/2] Add WPILIB_DLLEXPORT to DARE function declarations + +--- + math/discrete_algebraic_riccati_equation.h | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/math/discrete_algebraic_riccati_equation.h b/math/discrete_algebraic_riccati_equation.h +index df7a58b2b8..55b8442bf4 100644 +--- a/math/discrete_algebraic_riccati_equation.h ++++ b/math/discrete_algebraic_riccati_equation.h @@ -4,6 +4,7 @@ #include @@ -26,3 +35,6 @@ index df7a58b2b..55b8442bf 100644 Eigen::MatrixXd DiscreteAlgebraicRiccatiEquation( const Eigen::Ref& A, const Eigen::Ref& B, +-- +2.36.1 + diff --git a/upstream_utils/fmt-dont-throw-on-write-failure.patch b/upstream_utils/fmt_patches/0001-Don-t-throw-on-write-failure.patch similarity index 62% rename from upstream_utils/fmt-dont-throw-on-write-failure.patch rename to upstream_utils/fmt_patches/0001-Don-t-throw-on-write-failure.patch index 6be3639810..c76453e214 100644 --- a/upstream_utils/fmt-dont-throw-on-write-failure.patch +++ b/upstream_utils/fmt_patches/0001-Don-t-throw-on-write-failure.patch @@ -1,7 +1,18 @@ -diff --git a/wpiutil/src/main/native/fmtlib/include/fmt/format-inl.h b/wpiutil/src/main/native/fmtlib/include/fmt/format-inl.h -index 2c51c50ae..cc89abdd3 100644 ---- a/wpiutil/src/main/native/fmtlib/include/fmt/format-inl.h -+++ b/wpiutil/src/main/native/fmtlib/include/fmt/format-inl.h +From e92e91d28f2475b38f32f92d24b65eec195254a6 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Wed, 18 May 2022 10:21:49 -0700 +Subject: [PATCH] Don't throw on write failure + +--- + include/fmt/format-inl.h | 3 +-- + include/fmt/xchar.h | 3 +-- + src/os.cc | 3 +-- + 3 files changed, 3 insertions(+), 6 deletions(-) + +diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h +index 2c51c50a..cc89abdd 100644 +--- a/include/fmt/format-inl.h ++++ b/include/fmt/format-inl.h @@ -92,8 +92,7 @@ FMT_FUNC void report_error(format_func func, int error_code, // A wrapper around fwrite that throws on error. inline void fwrite_fully(const void* ptr, size_t size, size_t count, @@ -12,10 +23,10 @@ index 2c51c50ae..cc89abdd3 100644 } #ifndef FMT_STATIC_THOUSANDS_SEPARATOR -diff --git a/wpiutil/src/main/native/fmtlib/include/fmt/xchar.h b/wpiutil/src/main/native/fmtlib/include/fmt/xchar.h -index 55825077f..9acb893fa 100644 ---- a/wpiutil/src/main/native/fmtlib/include/fmt/xchar.h -+++ b/wpiutil/src/main/native/fmtlib/include/fmt/xchar.h +diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h +index 55825077..9acb893f 100644 +--- a/include/fmt/xchar.h ++++ b/include/fmt/xchar.h @@ -207,8 +207,7 @@ inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) { wmemory_buffer buffer; detail::vformat_to(buffer, fmt, args); @@ -26,10 +37,10 @@ index 55825077f..9acb893fa 100644 } inline void vprint(wstring_view fmt, wformat_args args) { -diff --git a/wpiutil/src/main/native/fmtlib/src/os.cpp b/wpiutil/src/main/native/fmtlib/src/os.cpp -index 04b4dc506..4eb3e1fdd 100644 ---- a/wpiutil/src/main/native/fmtlib/src/os.cpp -+++ b/wpiutil/src/main/native/fmtlib/src/os.cpp +diff --git a/src/os.cc b/src/os.cc +index 04b4dc50..4eb3e1fd 100644 +--- a/src/os.cc ++++ b/src/os.cc @@ -277,8 +277,7 @@ std::size_t file::read(void* buffer, std::size_t count) { std::size_t file::write(const void* buffer, std::size_t count) { rwresult result = 0; @@ -40,3 +51,6 @@ index 04b4dc506..4eb3e1fdd 100644 } file file::dup(int fd) { +-- +2.36.1 + diff --git a/upstream_utils/update_drake.py b/upstream_utils/update_drake.py index 069d3a8c55..4b4b11c3fb 100755 --- a/upstream_utils/update_drake.py +++ b/upstream_utils/update_drake.py @@ -3,7 +3,7 @@ import os import shutil -from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, apply_patches +from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches def main(): @@ -11,6 +11,14 @@ def main(): "v0.37.0") wpimath = os.path.join(root, "wpimath") + prefix = os.path.join(root, "upstream_utils/drake_patches") + am_patches(repo, [ + os.path.join(prefix, "0001-Replace-Eigen-Dense-with-Eigen-Core.patch"), + os.path.join( + prefix, + "0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch") + ]) + # Delete old install for d in [ "src/main/native/cpp/drake", "src/main/native/include/drake", @@ -61,11 +69,6 @@ def main(): os.path.join(wpimath, "src/test/native/include") ]) - apply_patches(root, [ - "upstream_utils/drake-replace-dense-with-core.patch", - "upstream_utils/drake-dllexport-dare.patch" - ]) - if __name__ == "__main__": main() diff --git a/upstream_utils/update_fmt.py b/upstream_utils/update_fmt.py index f752b3d371..aa446d4724 100755 --- a/upstream_utils/update_fmt.py +++ b/upstream_utils/update_fmt.py @@ -3,13 +3,18 @@ import os import shutil -from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, apply_patches +from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, am_patches def main(): root, repo = setup_upstream_repo("https://github.com/fmtlib/fmt", "8.1.1") wpiutil = os.path.join(root, "wpiutil") + # Apply patches to original git repo + prefix = os.path.join(root, "upstream_utils/fmt_patches") + am_patches( + repo, [os.path.join(prefix, "0001-Don-t-throw-on-write-failure.patch")]) + # Delete old install for d in ["src/main/native/fmtlib/src", "src/main/native/fmtlib/include"]: shutil.rmtree(os.path.join(wpiutil, d), ignore_errors=True) @@ -31,9 +36,6 @@ def main(): comment_out_invalid_includes( f, [os.path.join(wpiutil, "src/main/native/fmtlib/include")]) - apply_patches(root, - ["upstream_utils/fmt-dont-throw-on-write-failure.patch"]) - if __name__ == "__main__": main()