From f64643cf3c3128f4ac14f63356cd0e6c130db1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Thu, 29 Aug 2024 11:32:30 +0200 Subject: [PATCH 1/5] First steps for finalize() support in Meson --------- Co-authored-by: PerseoGI --- recipes/meson/all/conanfile.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/recipes/meson/all/conanfile.py b/recipes/meson/all/conanfile.py index 788b38338e98b..93f3bcea25b3d 100644 --- a/recipes/meson/all/conanfile.py +++ b/recipes/meson/all/conanfile.py @@ -30,6 +30,8 @@ def requirements(self): def package_id(self): self.info.clear() + # Make package_id based on Conan version less than 2.7 + # if it was possible, something like self.info.settings(?).conan_has_finalize = conan_version >= "2.7.0" def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) @@ -39,19 +41,25 @@ def package(self): copy(self, "*", src=self.source_folder, dst=os.path.join(self.package_folder, "bin")) rmdir(self, os.path.join(self.package_folder, "bin", "test cases")) + cmd_bytecode_wrapper = "set PYTHONDONTWRITEBYTECODE=1" if conan_version < "2.7.0" else "" + bytecode_wrapper = "export PYTHONDONTWRITEBYTECODE=1" if conan_version < "2.7.0" else "" + # create wrapper scripts - save(self, os.path.join(self.package_folder, "bin", "meson.cmd"), textwrap.dedent("""\ + save(self, os.path.join(self.package_folder, "bin", "meson.cmd"), textwrap.dedent(f"""\ @echo off - set PYTHONDONTWRITEBYTECODE=1 + {cmd_bytecode_wrapper} CALL python %~dp0/meson.py %* """)) - save(self, os.path.join(self.package_folder, "bin", "meson"), textwrap.dedent("""\ + save(self, os.path.join(self.package_folder, "bin", "meson"), textwrap.dedent(f"""\ #!/usr/bin/env bash meson_dir=$(dirname "$0") - export PYTHONDONTWRITEBYTECODE=1 + {bytecode_wrapper} exec "$meson_dir/meson.py" "$@" """)) + def finalize(self): + copy(self, "*", src=self.immutable_package_folder, dst=self.package_folder) + @staticmethod def _chmod_plus_x(filename): if os.name == "posix": From 3ebddc23b2e69c99bf8b99faff719c56abdda1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Thu, 29 Aug 2024 13:02:13 +0200 Subject: [PATCH 2/5] Modify wrapper in finalize to support old versions cleanly --- .../all/test_package/traits/defaults.h | 58 -------------- .../jwt-cpp/all/test_package/traits/traits.h | 76 ------------------- recipes/meson/all/conanfile.py | 18 +++-- 3 files changed, 10 insertions(+), 142 deletions(-) delete mode 100644 recipes/jwt-cpp/all/test_package/traits/defaults.h delete mode 100644 recipes/jwt-cpp/all/test_package/traits/traits.h diff --git a/recipes/jwt-cpp/all/test_package/traits/defaults.h b/recipes/jwt-cpp/all/test_package/traits/defaults.h deleted file mode 100644 index 7ec119bedd233..0000000000000 --- a/recipes/jwt-cpp/all/test_package/traits/defaults.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H -#define JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H - -#include "traits.h" - -namespace jwt { - /** - * \brief a class to store a generic [picojson](https://github.com/kazuho/picojson) value as claim - * - * This type is the specialization of the \ref basic_claim class which - * uses the standard template types. - */ - using claim = basic_claim; - - /** - * Create a verifier using the default clock - * \return verifier instance - */ - inline verifier verify() { - return verify(default_clock{}); - } - - /** - * Return a builder instance to create a new token - */ - inline builder create() { return builder(); } - -#ifndef JWT_DISABLE_BASE64 - /** - * Decode a token - * \param token Token to decode - * \return Decoded token - * \throw std::invalid_argument Token is not in correct format - * \throw std::runtime_error Base64 decoding failed or invalid json - */ - inline decoded_jwt decode(const std::string& token) { - return decoded_jwt(token); - } -#endif - - /** - * Decode a token - * \tparam Decode is callabled, taking a string_type and returns a string_type. - * It should ensure the padding of the input and then base64url decode and - * return the results. - * \param token Token to decode - * \param decode The token to parse - * \return Decoded token - * \throw std::invalid_argument Token is not in correct format - * \throw std::runtime_error Base64 decoding failed or invalid json - */ - template - decoded_jwt decode(const std::string& token, Decode decode) { - return decoded_jwt(token, decode); - } -} // namespace jwt - -#endif // JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H diff --git a/recipes/jwt-cpp/all/test_package/traits/traits.h b/recipes/jwt-cpp/all/test_package/traits/traits.h deleted file mode 100644 index 099f0dc26ce34..0000000000000 --- a/recipes/jwt-cpp/all/test_package/traits/traits.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef JWT_CPP_PICOJSON_TRAITS_H -#define JWT_CPP_PICOJSON_TRAITS_H - -#ifndef PICOJSON_USE_INT64 -#define PICOJSON_USE_INT64 -#endif -#include - -#ifndef JWT_DISABLE_PICOJSON -#define JWT_DISABLE_PICOJSON -#endif -#include "jwt-cpp/jwt.h" - -namespace jwt { - namespace traits { - struct kazuho_picojson { - using value_type = picojson::value; - using object_type = picojson::object; - using array_type = picojson::array; - using string_type = std::string; - using number_type = double; - using integer_type = int64_t; - using boolean_type = bool; - - static json::type get_type(const picojson::value& val) { - using json::type; - if (val.is()) return type::boolean; - if (val.is()) return type::integer; - if (val.is()) return type::number; - if (val.is()) return type::string; - if (val.is()) return type::array; - if (val.is()) return type::object; - - throw std::logic_error("invalid type"); - } - - static picojson::object as_object(const picojson::value& val) { - if (!val.is()) throw std::bad_cast(); - return val.get(); - } - - static std::string as_string(const picojson::value& val) { - if (!val.is()) throw std::bad_cast(); - return val.get(); - } - - static picojson::array as_array(const picojson::value& val) { - if (!val.is()) throw std::bad_cast(); - return val.get(); - } - - static int64_t as_int(const picojson::value& val) { - if (!val.is()) throw std::bad_cast(); - return val.get(); - } - - static bool as_bool(const picojson::value& val) { - if (!val.is()) throw std::bad_cast(); - return val.get(); - } - - static double as_number(const picojson::value& val) { - if (!val.is()) throw std::bad_cast(); - return val.get(); - } - - static bool parse(picojson::value& val, const std::string& str) { - return picojson::parse(val, str).empty(); - } - - static std::string serialize(const picojson::value& val) { return val.serialize(); } - }; - } // namespace traits -} // namespace jwt - -#endif diff --git a/recipes/meson/all/conanfile.py b/recipes/meson/all/conanfile.py index 93f3bcea25b3d..43dbd7aaf59ab 100644 --- a/recipes/meson/all/conanfile.py +++ b/recipes/meson/all/conanfile.py @@ -2,7 +2,7 @@ import textwrap from conan import ConanFile, conan_version -from conan.tools.files import copy, get, rmdir, save +from conan.tools.files import copy, get, rmdir, save, replace_in_file from conan.tools.layout import basic_layout from conan.tools.scm import Version @@ -30,8 +30,6 @@ def requirements(self): def package_id(self): self.info.clear() - # Make package_id based on Conan version less than 2.7 - # if it was possible, something like self.info.settings(?).conan_has_finalize = conan_version >= "2.7.0" def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) @@ -41,24 +39,28 @@ def package(self): copy(self, "*", src=self.source_folder, dst=os.path.join(self.package_folder, "bin")) rmdir(self, os.path.join(self.package_folder, "bin", "test cases")) - cmd_bytecode_wrapper = "set PYTHONDONTWRITEBYTECODE=1" if conan_version < "2.7.0" else "" - bytecode_wrapper = "export PYTHONDONTWRITEBYTECODE=1" if conan_version < "2.7.0" else "" - # create wrapper scripts save(self, os.path.join(self.package_folder, "bin", "meson.cmd"), textwrap.dedent(f"""\ @echo off - {cmd_bytecode_wrapper} + set PYTHONDONTWRITEBYTECODE=1 CALL python %~dp0/meson.py %* """)) save(self, os.path.join(self.package_folder, "bin", "meson"), textwrap.dedent(f"""\ #!/usr/bin/env bash meson_dir=$(dirname "$0") - {bytecode_wrapper} + export PYTHONDONTWRITEBYTECODE=1 exec "$meson_dir/meson.py" "$@" """)) def finalize(self): copy(self, "*", src=self.immutable_package_folder, dst=self.package_folder) + replace_in_file(self, os.path.join(self.package_folder, "bin", "meson.cmd"), + "set PYTHONDONTWRITEBYTECODE=1", + "") + + replace_in_file(self, os.path.join(self.package_folder, "bin", "meson"), + "export PYTHONDONTWRITEBYTECODE=1", + "") @staticmethod def _chmod_plus_x(filename): From 93d10159886d73336b299f20087b094386f420da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Thu, 29 Aug 2024 15:38:03 +0200 Subject: [PATCH 3/5] Discard changes to recipes/jwt-cpp/all/test_package/traits/defaults.h --- .../all/test_package/traits/defaults.h | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 recipes/jwt-cpp/all/test_package/traits/defaults.h diff --git a/recipes/jwt-cpp/all/test_package/traits/defaults.h b/recipes/jwt-cpp/all/test_package/traits/defaults.h new file mode 100644 index 0000000000000..7ec119bedd233 --- /dev/null +++ b/recipes/jwt-cpp/all/test_package/traits/defaults.h @@ -0,0 +1,58 @@ +#ifndef JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H +#define JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H + +#include "traits.h" + +namespace jwt { + /** + * \brief a class to store a generic [picojson](https://github.com/kazuho/picojson) value as claim + * + * This type is the specialization of the \ref basic_claim class which + * uses the standard template types. + */ + using claim = basic_claim; + + /** + * Create a verifier using the default clock + * \return verifier instance + */ + inline verifier verify() { + return verify(default_clock{}); + } + + /** + * Return a builder instance to create a new token + */ + inline builder create() { return builder(); } + +#ifndef JWT_DISABLE_BASE64 + /** + * Decode a token + * \param token Token to decode + * \return Decoded token + * \throw std::invalid_argument Token is not in correct format + * \throw std::runtime_error Base64 decoding failed or invalid json + */ + inline decoded_jwt decode(const std::string& token) { + return decoded_jwt(token); + } +#endif + + /** + * Decode a token + * \tparam Decode is callabled, taking a string_type and returns a string_type. + * It should ensure the padding of the input and then base64url decode and + * return the results. + * \param token Token to decode + * \param decode The token to parse + * \return Decoded token + * \throw std::invalid_argument Token is not in correct format + * \throw std::runtime_error Base64 decoding failed or invalid json + */ + template + decoded_jwt decode(const std::string& token, Decode decode) { + return decoded_jwt(token, decode); + } +} // namespace jwt + +#endif // JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H From f270492eb4971c275d89aea5876e4c0adbdf27af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Thu, 29 Aug 2024 15:38:07 +0200 Subject: [PATCH 4/5] Discard changes to recipes/jwt-cpp/all/test_package/traits/traits.h --- .../jwt-cpp/all/test_package/traits/traits.h | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 recipes/jwt-cpp/all/test_package/traits/traits.h diff --git a/recipes/jwt-cpp/all/test_package/traits/traits.h b/recipes/jwt-cpp/all/test_package/traits/traits.h new file mode 100644 index 0000000000000..099f0dc26ce34 --- /dev/null +++ b/recipes/jwt-cpp/all/test_package/traits/traits.h @@ -0,0 +1,76 @@ +#ifndef JWT_CPP_PICOJSON_TRAITS_H +#define JWT_CPP_PICOJSON_TRAITS_H + +#ifndef PICOJSON_USE_INT64 +#define PICOJSON_USE_INT64 +#endif +#include + +#ifndef JWT_DISABLE_PICOJSON +#define JWT_DISABLE_PICOJSON +#endif +#include "jwt-cpp/jwt.h" + +namespace jwt { + namespace traits { + struct kazuho_picojson { + using value_type = picojson::value; + using object_type = picojson::object; + using array_type = picojson::array; + using string_type = std::string; + using number_type = double; + using integer_type = int64_t; + using boolean_type = bool; + + static json::type get_type(const picojson::value& val) { + using json::type; + if (val.is()) return type::boolean; + if (val.is()) return type::integer; + if (val.is()) return type::number; + if (val.is()) return type::string; + if (val.is()) return type::array; + if (val.is()) return type::object; + + throw std::logic_error("invalid type"); + } + + static picojson::object as_object(const picojson::value& val) { + if (!val.is()) throw std::bad_cast(); + return val.get(); + } + + static std::string as_string(const picojson::value& val) { + if (!val.is()) throw std::bad_cast(); + return val.get(); + } + + static picojson::array as_array(const picojson::value& val) { + if (!val.is()) throw std::bad_cast(); + return val.get(); + } + + static int64_t as_int(const picojson::value& val) { + if (!val.is()) throw std::bad_cast(); + return val.get(); + } + + static bool as_bool(const picojson::value& val) { + if (!val.is()) throw std::bad_cast(); + return val.get(); + } + + static double as_number(const picojson::value& val) { + if (!val.is()) throw std::bad_cast(); + return val.get(); + } + + static bool parse(picojson::value& val, const std::string& str) { + return picojson::parse(val, str).empty(); + } + + static std::string serialize(const picojson::value& val) { return val.serialize(); } + }; + } // namespace traits +} // namespace jwt + +#endif From 146b5103b94e1a1cca7cd0853b40e567cc5b20a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Thu, 19 Sep 2024 09:05:15 +0200 Subject: [PATCH 5/5] Cealnup --- recipes/meson/all/conanfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/meson/all/conanfile.py b/recipes/meson/all/conanfile.py index 43dbd7aaf59ab..1f193b4c68fed 100644 --- a/recipes/meson/all/conanfile.py +++ b/recipes/meson/all/conanfile.py @@ -40,12 +40,12 @@ def package(self): rmdir(self, os.path.join(self.package_folder, "bin", "test cases")) # create wrapper scripts - save(self, os.path.join(self.package_folder, "bin", "meson.cmd"), textwrap.dedent(f"""\ + save(self, os.path.join(self.package_folder, "bin", "meson.cmd"), textwrap.dedent("""\ @echo off set PYTHONDONTWRITEBYTECODE=1 CALL python %~dp0/meson.py %* """)) - save(self, os.path.join(self.package_folder, "bin", "meson"), textwrap.dedent(f"""\ + save(self, os.path.join(self.package_folder, "bin", "meson"), textwrap.dedent("""\ #!/usr/bin/env bash meson_dir=$(dirname "$0") export PYTHONDONTWRITEBYTECODE=1