Add version utility

This commit is contained in:
DH 2023-11-10 23:41:44 +03:00
parent 74aa1a112e
commit 135c63117b
7 changed files with 156 additions and 22 deletions

View file

@ -12,3 +12,8 @@ add_subdirectory(rpcsx-os)
add_subdirectory(rpcsx-gpu)
add_subdirectory(hw/amdgpu)
add_subdirectory(rx)
target_compile_definitions(rx PRIVATE
RX_TAG=0
RX_TAG_VERSION=0
)

View file

@ -6,6 +6,6 @@ add_executable(rpcsx-gpu
)
target_include_directories(rpcsx-gpu PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(rpcsx-gpu PUBLIC amdgpu::bridge amdgpu::device glfw Vulkan::Vulkan)
target_link_libraries(rpcsx-gpu PUBLIC amdgpu::bridge amdgpu::device glfw Vulkan::Vulkan rx)
set_target_properties(rpcsx-gpu PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
install(TARGETS rpcsx-gpu RUNTIME DESTINATION bin)

View file

@ -1,6 +1,7 @@
#include "amdgpu/RemoteMemory.hpp"
#include "amdgpu/device/gpu-scheduler.hpp"
#include "amdgpu/device/vk.hpp"
#include "rx/Version.hpp"
#include "util/unreachable.hpp"
#include <algorithm>
#include <amdgpu/bridge/bridge.hpp>
@ -30,6 +31,7 @@ extern amdgpu::RemoteMemory g_hostMemory;
static void usage(std::FILE *out, const char *argv0) {
std::fprintf(out, "usage: %s [options...]\n", argv0);
std::fprintf(out, " options:\n");
std::fprintf(out, " --version, -v - print version\n");
std::fprintf(out,
" --cmd-bridge <name> - setup command queue bridge name\n");
std::fprintf(out, " --shm <name> - setup shared memory name\n");
@ -75,10 +77,18 @@ static VkResult _vkCreateDebugUtilsMessengerEXT(
}
int main(int argc, const char *argv[]) {
if (argc == 2 && (argv[1] == std::string_view("-h") ||
argv[1] == std::string_view("--help"))) {
usage(stdout, argv[0]);
return 0;
if (argc == 2) {
if (argv[1] == std::string_view("-h") ||
argv[1] == std::string_view("--help")) {
usage(stdout, argv[0]);
return 0;
}
if (argv[1] == std::string_view("-v") ||
argv[1] == std::string_view("--version")) {
std::printf("v%s\n", rx::getVersion().toString().c_str());
return 0;
}
}
const char *cmdBridgeName = "/rpcsx-gpu-cmds";

View file

@ -9,6 +9,7 @@
#include "thread.hpp"
#include "vfs.hpp"
#include "vm.hpp"
#include <rx/Version.hpp>
#include <atomic>
#include <elf.h>
@ -165,25 +166,26 @@ void setupSigHandlers() {
stack_t oss{};
// if (sigaltstack(nullptr, &oss) < 0 || oss.ss_size == 0) {
auto sigStackSize = std::max<std::size_t>(
SIGSTKSZ, utils::alignUp(64 * 1024 * 1024, sysconf(_SC_PAGE_SIZE)));
auto sigStackSize = std::max<std::size_t>(
SIGSTKSZ, utils::alignUp(64 * 1024 * 1024, sysconf(_SC_PAGE_SIZE)));
stack_t ss{};
ss.ss_sp = malloc(sigStackSize);
if (ss.ss_sp == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
stack_t ss{};
ss.ss_sp = malloc(sigStackSize);
if (ss.ss_sp == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
ss.ss_size = sigStackSize;
ss.ss_flags = 1 << 31;
ss.ss_size = sigStackSize;
ss.ss_flags = 1 << 31;
std::fprintf(stderr, "installing sp [%p, %p]\n", ss.ss_sp, (char *)ss.ss_sp + ss.ss_size);
std::fprintf(stderr, "installing sp [%p, %p]\n", ss.ss_sp,
(char *)ss.ss_sp + ss.ss_size);
if (sigaltstack(&ss, NULL) == -1) {
perror("sigaltstack");
exit(EXIT_FAILURE);
}
if (sigaltstack(&ss, NULL) == -1) {
perror("sigaltstack");
exit(EXIT_FAILURE);
}
// }
struct sigaction act {};
@ -521,6 +523,7 @@ int ps4Exec(orbis::Thread *mainThread,
static void usage(const char *argv0) {
std::printf("%s [<options>...] <virtual path to elf> [args...]\n", argv0);
std::printf(" options:\n");
std::printf(" --version, -v - print version\n");
std::printf(" -m, --mount <host path> <virtual path>\n");
std::printf(" -a, --enable-audio\n");
std::printf(" -o, --override <original module name> <virtual path to "
@ -604,6 +607,12 @@ int main(int argc, const char *argv[]) {
usage(argv[0]);
return 1;
}
if (argv[1] == std::string_view("-v") ||
argv[1] == std::string_view("--version")) {
std::printf("v%s\n", rx::getVersion().toString().c_str());
return 0;
}
}
if (argc < 2) {

View file

@ -1,4 +1,39 @@
project(rx)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE include)
find_package(Git)
add_library(${PROJECT_NAME} OBJECT
src/Version.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC include)
execute_process(COMMAND date +%+4Y%m%d OUTPUT_VARIABLE RAW_VERSION)
string(STRIP "${RAW_VERSION}" RAW_VERSION)
execute_process(COMMAND git log --date=format:%Y%m%d --pretty=format:'%cd' -n 1 OUTPUT_VARIABLE GIT_DATE)
execute_process(COMMAND git log --pretty=format:'%h' -n 1
OUTPUT_VARIABLE GIT_REV)
execute_process(
COMMAND bash git diff --quiet --exit-code
RESULT_VARIABLE GIT_DIRTY ERROR_QUIET)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH)
string(SUBSTRING ${GIT_DATE} 1 8 GIT_DATE)
string(STRIP "${GIT_REV}" GIT_REV)
string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
string(STRIP "${GIT_DIRTY}" GIT_DIRTY)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
target_compile_definitions(${PROJECT_NAME} PRIVATE
RX_RAW_VERSION=${GIT_DATE}
RX_GIT_REV=0x${GIT_REV}
RX_GIT_DIRTY=${GIT_DIRTY}
RX_GIT_BRANCH=${GIT_BRANCH}
)

64
rx/include/rx/Version.hpp Normal file
View file

@ -0,0 +1,64 @@
#pragma once
#include <cstdint>
#include <optional>
#include <string>
namespace rx {
enum class VersionTag { Draft, RC, Release };
struct Version {
std::uint32_t raw{};
VersionTag tag{};
std::uint32_t tagVersion{};
std::uint32_t gitTag{};
bool dirty{};
std::string toString() const {
std::string result = std::to_string(raw);
if (tag == VersionTag::Draft && gitTag != 0) {
result += '-';
auto value = gitTag;
char buf[7];
for (int i = 0; i < 7; ++i) {
auto digit = value & 0xf;
value >>= 4;
if (digit >= 10) {
buf[i] = 'a' + (digit - 10);
} else {
buf[i] += '0' + digit;
}
}
for (int i = 0; i < 7; ++i) {
result += buf[6 - i];
}
}
switch (tag) {
case VersionTag::Draft:
result += " Draft";
break;
case VersionTag::RC:
result += " RC";
break;
case VersionTag::Release:
break;
}
if (tagVersion) {
result += std::to_string(tagVersion);
}
if (dirty) {
result += '+';
}
return result;
}
};
Version getVersion();
} // namespace rx

11
rx/src/Version.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "rx/Version.hpp"
rx::Version rx::getVersion() {
return {
.raw = RX_RAW_VERSION,
.tag = static_cast<VersionTag>(RX_TAG),
.tagVersion = RX_TAG_VERSION,
.gitTag = RX_GIT_REV,
.dirty = (RX_GIT_DIRTY != 0),
};
}