Skip to content

Commit

Permalink
build: semver versioning
Browse files Browse the repository at this point in the history
Xref: #1037
  • Loading branch information
ckerr committed Oct 5, 2022
1 parent fff4c87 commit 4a57cf5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 40 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Expand Up @@ -69,17 +69,20 @@ tr_auto_option(WITH_SYSTEMD "Add support for systemd startup notificatio

set(TR_NAME ${PROJECT_NAME})

# convention: -TR MAJOR MINOR MAINT STATUS - (each a single char)
# STATUS: "X" for prerelease beta builds,
# "Z" for unsupported trunk builds,
# "0" for stable, supported releases
# convention: -TR MAJOR MINOR PATCH TYPE - (each a single char)
# MAJOR: https://semver.org/ major in https://en.wikipedia.org/wiki/Base62
# MINOR: https://semver.org/ minor in https://en.wikipedia.org/wiki/Base62
# PATCH: https://semver.org/ patch in https://en.wikipedia.org/wiki/Base62
# TYPE: '0' for stable releases, X' for beta releases, 'Z' for dev builds
#
# these should be the only two lines you need to change
set(TR_USER_AGENT_PREFIX "3.00+")
set(TR_USER_AGENT_PREFIX "3.0.0+")
set(TR_PEER_ID_PREFIX "-TR300Z-")

string(REGEX MATCH "^([0-9]+)\\.([0-9]+).*" TR_VERSION "${TR_USER_AGENT_PREFIX}")
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*" TR_VERSION "${TR_USER_AGENT_PREFIX}")
set(TR_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(TR_VERSION_MINOR "${CMAKE_MATCH_2}")
set(TR_VERSION_PATCH "${CMAKE_MATCH_3}")

if(TR_PEER_ID_PREFIX MATCHES "X-$")
set(TR_BETA_RELEASE 1)
Expand Down
2 changes: 1 addition & 1 deletion dist/msi/CMakeLists.txt
Expand Up @@ -9,7 +9,7 @@ else()
endif()

set(VERSION "${TR_USER_AGENT_PREFIX}")
set(VERSION_MSI "${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.0")
set(VERSION_MSI "${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_PATCH}")
set(VERSION_FULL "${TR_USER_AGENT_PREFIX} (${TR_VCS_REVISION})")

set(MSI_FILENAME_VERSION "${VERSION}")
Expand Down
72 changes: 44 additions & 28 deletions libtransmission/clients.cc
Expand Up @@ -47,7 +47,7 @@ constexpr std::pair<char*, size_t> buf_append(char* buf, size_t buflen, T t, Arg
return buf_append(buf, buflen, args...);
}

constexpr std::string_view charint(uint8_t chr)
constexpr std::string_view base62str(uint8_t chr)
{
// clang-format off
auto constexpr Strings = std::array<std::string_view, 256>{
Expand All @@ -60,10 +60,10 @@ constexpr std::string_view charint(uint8_t chr)
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "10"sv, "11"sv, "12"sv, "13"sv, "14"sv,
"15"sv, "16"sv, "17"sv, "18"sv, "19"sv, "20"sv, "21"sv, "22"sv, "23"sv, "24"sv,
"25"sv, "26"sv, "27"sv, "28"sv, "29"sv, "30"sv, "31"sv, "32"sv, "33"sv, "34"sv,
"35"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "10"sv, "11"sv, "12"sv,
"13"sv, "14"sv, "15"sv, "16"sv, "17"sv, "18"sv, "19"sv, "20"sv, "21"sv, "22"sv,
"23"sv, "24"sv, "25"sv, "26"sv, "27"sv, "28"sv, "29"sv, "30"sv, "31"sv, "32"sv,
"33"sv, "34"sv, "35"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
"35"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "36"sv, "37"sv, "38"sv,
"39"sv, "40"sv, "41"sv, "42"sv, "43"sv, "44"sv, "45"sv, "46"sv, "47"sv, "48"sv,
"49"sv, "50"sv, "51"sv, "52"sv, "53"sv, "54"sv, "55"sv, "56"sv, "57"sv, "58"sv,
"59"sv, "60"sv, "61"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
"x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv, "x"sv,
Expand All @@ -89,7 +89,7 @@ int strint(char const* pch, int span, int base = 10)
return tr_parseNum<int>(sv, nullptr, base).value_or(0);
}

constexpr std::string_view getMnemonicEnd(uint8_t ch)
constexpr std::string_view utSuffix(uint8_t ch)
{
switch (ch)
{
Expand Down Expand Up @@ -243,12 +243,12 @@ using format_func = void (*)(char* buf, size_t buflen, std::string_view name, tr

constexpr void three_digit_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', charint(id[4]), '.', charint(id[5]));
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), '.', base62str(id[5]));
}

constexpr void four_digit_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', charint(id[4]), '.', charint(id[5]), '.', charint(id[6]));
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), '.', base62str(id[5]), '.', base62str(id[6]));
}

void no_version_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t /*id*/)
Expand Down Expand Up @@ -338,23 +338,23 @@ constexpr void burst_formatter(char* buf, size_t buflen, std::string_view name,

constexpr void ctorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', charint(id[4]), '.', id[5], id[6]);
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), '.', id[5], id[6]);
}

constexpr void folx_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', 'x');
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', 'x');
}

constexpr void ktorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
if (id[5] == 'D')
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', charint(id[4]), " Dev "sv, charint(id[6]));
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), " Dev "sv, base62str(id[6]));
}
else if (id[5] == 'R')
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', charint(id[4]), " RC "sv, charint(id[6]));
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), " RC "sv, base62str(id[6]));
}
else
{
Expand Down Expand Up @@ -383,7 +383,7 @@ constexpr void mainline_formatter(char* buf, size_t buflen, std::string_view nam

constexpr void mediaget_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', charint(id[4]));
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]));
}

constexpr void mldonkey_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
Expand All @@ -405,7 +405,7 @@ constexpr void opera_formatter(char* buf, size_t buflen, std::string_view name,

constexpr void picotorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', charint(id[3]), '.', id[4], id[5], '.', charint(id[6]));
buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', id[4], id[5], '.', base62str(id[6]));
}

constexpr void plus_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
Expand All @@ -415,32 +415,48 @@ constexpr void plus_formatter(char* buf, size_t buflen, std::string_view name, t

constexpr void qvod_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', charint(id[4]), '.', charint(id[5]), '.', charint(id[6]), '.', charint(id[7]));
buf_append(buf, buflen, name, ' ', base62str(id[4]), '.', base62str(id[5]), '.', base62str(id[6]), '.', base62str(id[7]));
}

constexpr auto trSuffix(uint8_t ch)
{
switch (ch)
{
case 'x':
case 'X':
return " (Beta)"sv;

case 'z':
case 'Z':
return " (Dev)"sv;

default:
return ""sv;
}
}

void transmission_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{

std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ');

if (std::equal(&id[3], &id[6], "000")) // very old client style: -TR0006- is 0.6
{
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("0.{:c}"), id[6]).out = '\0';
}
else if (std::equal(&id[3], &id[5], "00")) // previous client style: -TR0072- is 0.72
else if (std::equal(&id[3], &id[5], "00")) // pre-1.0 style: -TR0072- is 0.72
{
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("0.{:02d}"), strint(&id[5], 2)).out = '\0';
}
else // current client style: -TR111Z- is 1.11+ */
else if (id[3] <= '3') // style up through 3.00: -TR111Z- is 1.11+
{
*fmt::format_to_n(
buf,
buflen - 1,
FMT_STRING("{:d}.{:02d}{:s}"),
strint(&id[3], 1),
strint(&id[4], 2),
(id[6] == 'Z' || id[6] == 'X') ? "+" : "")
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("{:s}.{:02d}{:s}"), base62str(id[3]), strint(&id[4], 2), trSuffix(id[6]))
.out = '\0';
}
else // -TR400X- is 4.0.0 (Beta)"
{
buf_append(buf, buflen, base62str(id[3]), '.', base62str(id[4]), '.', base62str(id[5]), trSuffix(id[6]));
}
}

void utorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
Expand All @@ -457,7 +473,7 @@ void utorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer
strint(&id[4], 1, 16),
'.',
strint(&id[5], 1, 16),
getMnemonicEnd(id[6]));
utSuffix(id[6]));
}
else // uTorrent replaces the trailing dash with an extra digit for longer version numbers
{
Expand All @@ -471,13 +487,13 @@ void utorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer
strint(&id[4], 1, 16),
'.',
strint(&id[5], 2, 10),
getMnemonicEnd(id[7]));
utSuffix(id[7]));
}
}

constexpr void xbt_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
buf_append(buf, buflen, name, ' ', id[3], '.', id[4], '.', id[5], getMnemonicEnd(id[6]));
buf_append(buf, buflen, name, ' ', id[3], '.', id[4], '.', id[5], utSuffix(id[6]));
}

constexpr void xfplay_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
Expand All @@ -494,7 +510,7 @@ constexpr void xfplay_formatter(char* buf, size_t buflen, std::string_view name,

void xtorrent_formatter(char* buf, size_t buflen, std::string_view name, tr_peer_id_t id)
{
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ', charint(id[3]), '.', charint(id[4]), " ("sv);
std::tie(buf, buflen) = buf_append(buf, buflen, name, ' ', base62str(id[3]), '.', base62str(id[4]), " ("sv);
*fmt::format_to_n(buf, buflen - 1, FMT_STRING("{:d}"), strint(&id[5], 2)).out = '\0';
}

Expand Down
3 changes: 2 additions & 1 deletion libtransmission/version.h.in
Expand Up @@ -7,9 +7,10 @@
#define SHORT_VERSION_STRING "${TR_USER_AGENT_PREFIX}"
#define LONG_VERSION_STRING "${TR_USER_AGENT_PREFIX} (${TR_VCS_REVISION})"
#define VERSION_STRING_INFOPLIST ${TR_USER_AGENT_PREFIX}
#define BUILD_STRING_INFOPLIST 14714.${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}
#define BUILD_STRING_INFOPLIST 14714.${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_PATCH}
#define MAJOR_VERSION ${TR_VERSION_MAJOR}
#define MINOR_VERSION ${TR_VERSION_MINOR}
#define PATCH_VERSION ${TR_VERSION_PATCH}

#cmakedefine TR_BETA_RELEASE 1
#cmakedefine TR_NIGHTLY_RELEASE 1
Expand Down
6 changes: 4 additions & 2 deletions tests/libtransmission/clients-test.cc
Expand Up @@ -24,7 +24,7 @@ TEST(Client, clientForId)
std::string_view expected_client;
};

auto constexpr Tests = std::array<LocalTest, 44>{
auto constexpr Tests = std::array<LocalTest, 46>{
{ { "-ADB560-"sv, "Advanced Download Manager 11.5.6"sv },
{ "-AZ8421-"sv, "Azureus / Vuze 8.4.2.1"sv },
{ "-BC0241-"sv, "BitComet 2.41"sv }, // two major, two minor
Expand Down Expand Up @@ -52,7 +52,9 @@ TEST(Client, clientForId)
{ "-TB2137-"sv, "Torch Browser"sv }, // Torch Browser 55.0.0.12137
{ "-TR0006-"sv, "Transmission 0.6"sv },
{ "-TR0072-"sv, "Transmission 0.72"sv },
{ "-TR111Z-"sv, "Transmission 1.11+"sv },
{ "-TR111Z-"sv, "Transmission 1.11 (Dev)"sv },
{ "-TR400X-"sv, "Transmission 4.0.0 (Beta)"sv },
{ "-TR4000-"sv, "Transmission 4.0.0"sv },
{ "-UT341\0-"sv, "\xc2\xb5Torrent 3.4.1"sv },
{ "-UT7a5\0-"sv, "\xc2\xb5Torrent 7.10.5"sv },
{ "-UW110Q-"sv, "\xc2\xb5Torrent Web 1.1.0"sv },
Expand Down
6 changes: 4 additions & 2 deletions update-version-h.sh
Expand Up @@ -17,7 +17,8 @@ user_agent_prefix=$(grep 'set[(]TR_USER_AGENT_PREFIX' CMakeLists.txt | cut -d \"
peer_id_prefix=$(grep 'set[(]TR_PEER_ID_PREFIX' CMakeLists.txt | cut -d \" -f 2)

major_version=$(echo "${user_agent_prefix}" | awk -F . '{print $1}')
minor_version=$(echo "${user_agent_prefix}" | awk -F . '{print $2 + 0}')
minor_version=$(echo "${user_agent_prefix}" | awk -F . '{print $2}')
patch_version=$(echo "${user_agent_prefix}" | awk -F . '{print $3}')

vcs_revision=
vcs_revision_file=REVISION
Expand Down Expand Up @@ -51,9 +52,10 @@ cat > libtransmission/version.h.new << EOF
#define SHORT_VERSION_STRING "${user_agent_prefix}"
#define LONG_VERSION_STRING "${user_agent_prefix} (${vcs_revision})"
#define VERSION_STRING_INFOPLIST ${user_agent_prefix}
#define BUILD_STRING_INFOPLIST 14714.${major_version}.${minor_version}
#define BUILD_STRING_INFOPLIST 14714.${major_version}.${minor_version}.${patch_version}
#define MAJOR_VERSION ${major_version}
#define MINOR_VERSION ${minor_version}
#define PATCH_VERSION ${patch_version}
EOF

# Add a release definition
Expand Down

0 comments on commit 4a57cf5

Please sign in to comment.