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

[spdx] Fix several bugs #1377

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ namespace vcpkg
inline constexpr StringLiteral CMakeVariableFeatures = "FEATURES";
inline constexpr StringLiteral CMakeVariableFilename = "FILENAME";
inline constexpr StringLiteral CMakeVariableGit = "GIT";
inline constexpr StringLiteral CMakeVariableGitlabUrl = "GITLAB_URL";
inline constexpr StringLiteral CMakeVariableHashAdditionalFiles = "VCPKG_HASH_ADDITIONAL_FILES";
inline constexpr StringLiteral CMakeVariableHostTriplet = "_HOST_TRIPLET";
inline constexpr StringLiteral CMakeVariableLoadVcvarsEnv = "VCPKG_LOAD_VCVARS_ENV";
Expand Down
6 changes: 5 additions & 1 deletion include/vcpkg/spdx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

namespace vcpkg
{
StringView extract_first_cmake_invocation_args(StringView content, StringView command);
StringView extract_arg_from_cmake_invocation_args(StringView invocation_args, StringView target_arg);
std::string replace_cmake_var(StringView text, StringView var, StringView value);

/// Generate an SDPX 2.2.1 manifest (https://spdx.github.io/spdx-spec)
/// @param action Install action to be represented by this manifest
/// @param relative_paths Must contain relative paths of all files in the port directory (from the port directory)
Expand All @@ -29,5 +33,5 @@ namespace vcpkg
std::string document_namespace,
std::vector<Json::Object>&& resource_docs);

Json::Object run_resource_heuristics(StringView contents, StringView portRawVersion);
Json::Object run_resource_heuristics(StringView contents, StringView version_text);
}
93 changes: 93 additions & 0 deletions src/vcpkg-test/spdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,99 @@

using namespace vcpkg;

TEST_CASE ("replace CMake variable", "[spdx]")
{
static constexpr StringLiteral str{"lorem ip${VERSION}"};
{
auto res = replace_cmake_var(str, "VERSION", "sum");
REQUIRE(res == "lorem ipsum");
}
{
auto res = replace_cmake_var(str, "VERSiON", "sum");
REQUIRE(res == "lorem ip${VERSION}");
}
}

TEST_CASE ("extract first cmake invocation args", "[spdx]")
{
{
auto res = extract_first_cmake_invocation_args("lorem_ipsum()", "lorem_ipsum");
REQUIRE(res.empty());
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipsummmmm() lorem_ipsum(asdf)", "lorem_ipsum");
REQUIRE(res == "asdf");
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipsum(abc)", "lorem_ipsu");
REQUIRE(res.empty());
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipsum(abc", "lorem_ipsum");
REQUIRE(res.empty());
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipsum (abc) ", "lorem_ipsum");
REQUIRE(res == "abc");
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipsum x (abc) ", "lorem_ipsum");
REQUIRE(res.empty());
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipum(abc)", "lorem_ipsum");
REQUIRE(res.empty());
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipsum( )", "lorem_ipsum");
REQUIRE(res == " ");
}
{
auto res = extract_first_cmake_invocation_args("lorem_ipsum_", "lorem_ipsum");
REQUIRE(res.empty());
}
}

TEST_CASE ("extract arg from cmake invocation args", "[spdx]")
{
{
auto res = extract_arg_from_cmake_invocation_args("loremipsum", "lorem");
REQUIRE(res.empty());
}
{
auto res = extract_arg_from_cmake_invocation_args("loremipsum lorem value", "lorem");
REQUIRE(res == "value");
}
{
auto res = extract_arg_from_cmake_invocation_args("loremipsum lorem value ", "lorem");
REQUIRE(res == "value");
}
{
auto res = extract_arg_from_cmake_invocation_args("lorem", "lorem");
REQUIRE(res.empty());
}
{
auto res = extract_arg_from_cmake_invocation_args("lorem \"", "lorem");
REQUIRE(res.empty());
}
{
auto res = extract_arg_from_cmake_invocation_args("lorem ", "lorem");
REQUIRE(res.empty());
}
{
auto res = extract_arg_from_cmake_invocation_args("lorem ipsum", "lorem");
REQUIRE(res == "ipsum");
}
{
auto res = extract_arg_from_cmake_invocation_args("lorem \"ipsum", "lorem");
REQUIRE(res.empty());
}
{
auto res = extract_arg_from_cmake_invocation_args("lorem \"ipsum\"", "lorem");
REQUIRE(res == "ipsum");
}
}

TEST_CASE ("spdx maximum serialization", "[spdx]")
{
PackageSpec spec{"zlib", Test::ARM_UWP};
Expand Down
Loading
Loading