forked from wpilibsuite/allwpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[upstream-utils][mpack] Add upstream util for mpack (wpilibsuite#4500)
- Loading branch information
1 parent
4ba16db
commit fa44a07
Showing
6 changed files
with
278 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
upstream_utils/mpack_patches/0001-Don-t-emit-inline-defs.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
From 05864e768ca1458c1e24f433d091306a7d47562b Mon Sep 17 00:00:00 2001 | ||
From: PJ Reiniger <[email protected]> | ||
Date: Sat, 29 Oct 2022 12:09:03 -0400 | ||
Subject: [PATCH 1/3] Don't emit inline defs | ||
|
||
--- | ||
src/mpack/mpack-platform.c | 2 +- | ||
1 file changed, 1 insertion(+), 1 deletion(-) | ||
|
||
diff --git a/src/mpack/mpack-platform.c b/src/mpack/mpack-platform.c | ||
index 6599e1f..d4a2fa3 100644 | ||
--- a/src/mpack/mpack-platform.c | ||
+++ b/src/mpack/mpack-platform.c | ||
@@ -24,7 +24,7 @@ | ||
// standalone definitions of all (non-static) inline functions in MPack. | ||
|
||
#define MPACK_INTERNAL 1 | ||
-#define MPACK_EMIT_INLINE_DEFS 1 | ||
+#define MPACK_EMIT_INLINE_DEFS 0 | ||
|
||
#include "mpack-platform.h" | ||
#include "mpack.h" |
24 changes: 24 additions & 0 deletions
24
upstream_utils/mpack_patches/0002-Update-amalgamation-script.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
From d4d045c843d4b4de747d800e570c32cff3759a80 Mon Sep 17 00:00:00 2001 | ||
From: PJ Reiniger <[email protected]> | ||
Date: Sat, 29 Oct 2022 12:16:36 -0400 | ||
Subject: [PATCH 2/3] Update amalgamation script | ||
|
||
--- | ||
tools/amalgamate.sh | 4 ++-- | ||
1 file changed, 2 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/tools/amalgamate.sh b/tools/amalgamate.sh | ||
index 2e24e27..4dfe999 100755 | ||
--- a/tools/amalgamate.sh | ||
+++ b/tools/amalgamate.sh | ||
@@ -74,8 +74,8 @@ echo -e "#endif\n" >> $HEADER | ||
|
||
# assemble source | ||
echo -e "#define MPACK_INTERNAL 1" >> $SOURCE | ||
-echo -e "#define MPACK_EMIT_INLINE_DEFS 1\n" >> $SOURCE | ||
-echo -e "#include \"mpack.h\"\n" >> $SOURCE | ||
+echo -e "#define MPACK_EMIT_INLINE_DEFS 0\n" >> $SOURCE | ||
+echo -e "#include \"wpi/mpack.h\"\n" >> $SOURCE | ||
for f in $SOURCES; do | ||
echo -e "\n/* $f.c */" >> $SOURCE | ||
sed -e 's@^#include ".*@/* & */@' -e '0,/^ \*\/$/d' src/$f >> $SOURCE |
158 changes: 158 additions & 0 deletions
158
upstream_utils/mpack_patches/0003-Use-namespace-for-C.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
From 37854ea8a4a4b387940719c40bd32792f1e6e027 Mon Sep 17 00:00:00 2001 | ||
From: PJ Reiniger <[email protected]> | ||
Date: Sat, 29 Oct 2022 12:22:50 -0400 | ||
Subject: [PATCH 3/3] Use namespace for C++ | ||
|
||
--- | ||
src/mpack/mpack-common.c | 2 ++ | ||
src/mpack/mpack-expect.c | 2 ++ | ||
src/mpack/mpack-node.c | 2 ++ | ||
src/mpack/mpack-platform.c | 2 ++ | ||
src/mpack/mpack-platform.h | 2 +- | ||
src/mpack/mpack-reader.c | 2 ++ | ||
src/mpack/mpack-writer.c | 2 ++ | ||
src/mpack/mpack-writer.h | 3 ++- | ||
8 files changed, 15 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/src/mpack/mpack-common.c b/src/mpack/mpack-common.c | ||
index 2c133a3..dc7207f 100644 | ||
--- a/src/mpack/mpack-common.c | ||
+++ b/src/mpack/mpack-common.c | ||
@@ -24,6 +24,7 @@ | ||
#include "mpack-common.h" | ||
|
||
MPACK_SILENCE_WARNINGS_BEGIN | ||
+namespace mpack { | ||
|
||
const char* mpack_error_to_string(mpack_error_t error) { | ||
#if MPACK_STRINGS | ||
@@ -748,4 +749,5 @@ void mpack_print_file_callback(void* context, const char* data, size_t count) { | ||
} | ||
#endif | ||
|
||
+} // namespace mpack | ||
MPACK_SILENCE_WARNINGS_END | ||
diff --git a/src/mpack/mpack-expect.c b/src/mpack/mpack-expect.c | ||
index 81576d1..6232a67 100644 | ||
--- a/src/mpack/mpack-expect.c | ||
+++ b/src/mpack/mpack-expect.c | ||
@@ -24,6 +24,7 @@ | ||
#include "mpack-expect.h" | ||
|
||
MPACK_SILENCE_WARNINGS_BEGIN | ||
+namespace mpack { | ||
|
||
#if MPACK_EXPECT | ||
|
||
@@ -880,4 +881,5 @@ size_t mpack_expect_key_cstr(mpack_reader_t* reader, const char* keys[], bool fo | ||
|
||
#endif | ||
|
||
+} // namespace mpack | ||
MPACK_SILENCE_WARNINGS_END | ||
diff --git a/src/mpack/mpack-node.c b/src/mpack/mpack-node.c | ||
index 3d4b0f4..aba9897 100644 | ||
--- a/src/mpack/mpack-node.c | ||
+++ b/src/mpack/mpack-node.c | ||
@@ -24,6 +24,7 @@ | ||
#include "mpack-node.h" | ||
|
||
MPACK_SILENCE_WARNINGS_BEGIN | ||
+namespace mpack { | ||
|
||
#if MPACK_NODE | ||
|
||
@@ -2401,4 +2402,5 @@ mpack_node_t mpack_node_map_value_at(mpack_node_t node, size_t index) { | ||
|
||
#endif | ||
|
||
+} // namespace mpack | ||
MPACK_SILENCE_WARNINGS_END | ||
diff --git a/src/mpack/mpack-platform.c b/src/mpack/mpack-platform.c | ||
index d4a2fa3..75d2de3 100644 | ||
--- a/src/mpack/mpack-platform.c | ||
+++ b/src/mpack/mpack-platform.c | ||
@@ -30,6 +30,7 @@ | ||
#include "mpack.h" | ||
|
||
MPACK_SILENCE_WARNINGS_BEGIN | ||
+namespace mpack { | ||
|
||
#if MPACK_DEBUG | ||
|
||
@@ -218,4 +219,5 @@ void* mpack_realloc(void* old_ptr, size_t used_size, size_t new_size) { | ||
} | ||
#endif | ||
|
||
+} // namespace mpack | ||
MPACK_SILENCE_WARNINGS_END | ||
diff --git a/src/mpack/mpack-platform.h b/src/mpack/mpack-platform.h | ||
index 79604c9..27a2f9e 100644 | ||
--- a/src/mpack/mpack-platform.h | ||
+++ b/src/mpack/mpack-platform.h | ||
@@ -1043,7 +1043,7 @@ void mpack_assert_fail(const char* message); | ||
*/ | ||
|
||
#ifdef __cplusplus | ||
- #define MPACK_EXTERN_C_BEGIN extern "C" { | ||
+ #define MPACK_EXTERN_C_BEGIN namespace mpack { | ||
#define MPACK_EXTERN_C_END } | ||
#else | ||
#define MPACK_EXTERN_C_BEGIN /*nothing*/ | ||
diff --git a/src/mpack/mpack-reader.c b/src/mpack/mpack-reader.c | ||
index c6d2223..a135879 100644 | ||
--- a/src/mpack/mpack-reader.c | ||
+++ b/src/mpack/mpack-reader.c | ||
@@ -24,6 +24,7 @@ | ||
#include "mpack-reader.h" | ||
|
||
MPACK_SILENCE_WARNINGS_BEGIN | ||
+namespace mpack { | ||
|
||
#if MPACK_READER | ||
|
||
@@ -1284,4 +1285,5 @@ void mpack_print_stdfile_to_callback(FILE* file, mpack_print_callback_t callback | ||
|
||
#endif | ||
|
||
+} // namespace mpack | ||
MPACK_SILENCE_WARNINGS_END | ||
diff --git a/src/mpack/mpack-writer.c b/src/mpack/mpack-writer.c | ||
index 4d052b1..9630d9e 100644 | ||
--- a/src/mpack/mpack-writer.c | ||
+++ b/src/mpack/mpack-writer.c | ||
@@ -24,6 +24,7 @@ | ||
#include "mpack-writer.h" | ||
|
||
MPACK_SILENCE_WARNINGS_BEGIN | ||
+namespace mpack { | ||
|
||
#if MPACK_WRITER | ||
|
||
@@ -1772,4 +1773,5 @@ void mpack_complete_array(mpack_writer_t* writer) { | ||
#endif // MPACK_BUILDER | ||
#endif // MPACK_WRITER | ||
|
||
+} // namespace mpack | ||
MPACK_SILENCE_WARNINGS_END | ||
diff --git a/src/mpack/mpack-writer.h b/src/mpack/mpack-writer.h | ||
index c239ee6..abeee1a 100644 | ||
--- a/src/mpack/mpack-writer.h | ||
+++ b/src/mpack/mpack-writer.h | ||
@@ -1168,6 +1168,7 @@ MPACK_EXTERN_C_END | ||
|
||
#if defined(__cplusplus) || defined(MPACK_DOXYGEN) | ||
|
||
+namespace mpack { | ||
/** | ||
* @name C++ write overloads | ||
* @{ | ||
@@ -1304,7 +1305,7 @@ MPACK_INLINE void mpack_write_kv(mpack_writer_t* writer, const char *key, const | ||
/** | ||
* @} | ||
*/ | ||
- | ||
+} // namespace mpack | ||
#endif /* __cplusplus */ | ||
|
||
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import shutil | ||
import subprocess | ||
|
||
from upstream_utils import ( | ||
get_repo_root, | ||
clone_repo, | ||
walk_cwd_and_copy_if, | ||
git_am, | ||
) | ||
|
||
|
||
def main(): | ||
upstream_root = clone_repo("https://github.com/ludocode/mpack", "v1.1") | ||
wpilib_root = get_repo_root() | ||
wpiutil = os.path.join(wpilib_root, "wpiutil") | ||
|
||
# Delete old install | ||
for d in [ | ||
"src/main/native/thirdparty/mpack/src", | ||
"src/main/native/thirdparty/mpack/include", | ||
]: | ||
shutil.rmtree(os.path.join(wpiutil, d), ignore_errors=True) | ||
|
||
# Apply patches to upstream Git repo | ||
os.chdir(upstream_root) | ||
|
||
for f in [ | ||
"0001-Don-t-emit-inline-defs.patch", | ||
"0002-Update-amalgamation-script.patch", | ||
"0003-Use-namespace-for-C.patch", | ||
]: | ||
git_am( | ||
os.path.join(wpilib_root, "upstream_utils/mpack_patches", f), | ||
) | ||
|
||
# Run the amalgmation script | ||
subprocess.check_call(["bash", "tools/amalgamate.sh"]) | ||
|
||
# Copy the files | ||
amalgamation_source_dir = os.path.join( | ||
".", ".build", "amalgamation", "src", "mpack" | ||
) | ||
os.chdir(amalgamation_source_dir) | ||
|
||
walk_cwd_and_copy_if( | ||
lambda dp, f: f.endswith(".h"), | ||
os.path.join(wpiutil, "src/main/native/thirdparty/mpack/include/wpi"), | ||
) | ||
walk_cwd_and_copy_if( | ||
lambda dp, f: f.endswith(".c"), | ||
os.path.join(wpiutil, "src/main/native/thirdparty/mpack/src"), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters