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

fix jwt-cpp on_test #5366

Merged
merged 3 commits into from
Sep 29, 2024
Merged
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
50 changes: 40 additions & 10 deletions packages/j/jwt-cpp/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,62 @@ package("jwt-cpp")
add_versions("v0.7.0", "b9eb270e3ba8221e4b2bc38723c9a1cb4fa6c241a42908b9a334daff31137406")
add_versions("v0.6.0", "0227bd6e0356b211341075c7997c837f0b388c01379bd256aa525566a5553f03")

add_configs("picojson", {description = "Use picojson", default = true, type = "boolean"})
add_configs("picojson", {description = "Provide the picojson template specialiaze", default = false, type = "boolean"})
add_configs("base64", {description = "Include the base64 implementation from this library", default = true, type = "boolean"})
add_configs("ssl", {description = "Select ssl library", default = "openssl", type = "string", values = {"openssl", "openssl3", "libressl", "wolfssl"}})

add_deps("openssl")
add_deps("cmake")

on_load(function (package)
package:add("deps", package:config("ssl"))
if package:gitref() or package:version():le("0.7.0") then
package:add("deps", "nlohmann_json", {configs = {cmake = true}})
end

if package:config("picojson") then
package:add("deps", "picojson")
else
package:add("defines", "JWT_DISABLE_PICOJSON")
end

if not package:config("base64") then
package:add("defines", "JWT_DISABLE_BASE64")
end
end)

on_install("windows", "linux", "macosx", "bsd", "mingw", "msys", "android", "cross", function (package)
if package:config("picojson") then
io.replace("include/jwt-cpp/jwt.h", "picojson/picojson.h", "picojson.h", {plain = true})
io.replace("include/jwt-cpp/traits/kazuho-picojson/traits.h", "picojson/picojson.h", "picojson.h", {plain = true})
io.replace("CMakeLists.txt", "find_package(picojson 1.3.0 REQUIRED)", "", {plain = true})
end

local configs = {"-DJWT_BUILD_EXAMPLES=OFF", "-DJWT_EXTERNAL_NLOHMANN_JSON=ON"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DJWT_DISABLE_PICOJSON=" .. (package:config("picojson") and "OFF" or "ON"))
table.insert(configs, "-DJWT_EXTERNAL_PICOJSON=" .. (package:config("picojson") and "ON" or "OFF"))
table.insert(configs, "-DJWT_DISABLE_BASE64=" .. (package:config("base64") and "OFF" or "ON"))

local ssl = package:config("ssl")
if ssl:startswith("openssl") then
local openssl = package:dep(ssl)
if not openssl:is_system() then
table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
end
end
os.cp("include/jwt-cpp", package:installdir("include"))
import("package.tools.cmake").install(package, configs)
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <jwt-cpp/jwt.h>
void test() {
std::string token;
auto decoded = jwt::decode(token);
}
]]}, {configs = {languages = "c++11"}}))
if package:config("picojson") then
assert(package:check_cxxsnippets({test = [[
#include <jwt-cpp/jwt.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide more information about this change? When the picojson feature is disabled with this patch, it will be completely untested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
If I use add_requires("jwt-cpp", {configs = {picojson = false}}), the situation shown in the figure will appear when installing the package

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. In this case, the current port of the package can be enhanced by incorporating additional JSON trait features, such as Boost.JSON or nlohmann_json. These dependencies should be added when the feature is enabled. Otherwise, simply disabling the on_test won't be very effective.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I use nlohmann-json by add_requires in my project code, I just want to be able to install jwt after disabling picojson.
If the programmer actively turns off this picojson config, it means that he is consciously using other json libraries.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need refactor the package

void test() {
std::string token;
auto decoded = jwt::decode(token);
}
]]}, {configs = {languages = "c++11"}}))
else
assert(package:has_cxxincludes("jwt-cpp/jwt.h", {configs = {languages = "c++11"}}))
end
end)
Loading