Skip to content

Commit 5c38c2d

Browse files
authored
Merge pull request #1 from Masterkatze/sniper
Use sniper docker container
2 parents 625cf58 + 98938c5 commit 5c38c2d

9 files changed

Lines changed: 53 additions & 39 deletions

File tree

.github/workflows/cibuild.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@ jobs:
1717
run:
1818
shell: bash
1919

20+
container:
21+
image: 'registry.gitlab.steamos.cloud/steamrt/sniper/sdk:latest'
22+
2023
steps:
2124
- uses: actions/checkout@v4
2225
with:
2326
submodules: recursive
2427

28+
- name: Set ownership
29+
run: |
30+
# Fix for "detected dubious ownership in repository"
31+
chown -R $(id -u):$(id -g) $PWD
32+
2533
- name: Set reusable strings
2634
run: |
2735
preset_name=linux-release
28-
workspace_dir=${{ github.workspace }}
36+
workspace_dir="$GITHUB_WORKSPACE"
2937
source_dir=${workspace_dir}
3038
build_dir=${workspace_dir}/build/$preset_name
3139
install_dir=$build_dir/install
@@ -34,11 +42,6 @@ jobs:
3442
echo "install_dir=$install_dir" >> "$GITHUB_ENV"
3543
echo "preset_name=$preset_name" >> "$GITHUB_ENV"
3644
37-
- name: Install packages
38-
run: |
39-
sudo apt update
40-
sudo apt install libelf-dev ninja-build -y
41-
4245
- name: Git fetch tags
4346
run: git fetch origin --tags
4447

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "external/CLI11"]
22
path = external/CLI11
33
url = https://github.com/CLIUtils/CLI11.git
4+
[submodule "fmt"]
5+
path = external/fmt
6+
url = https://github.com/fmtlib/fmt

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
cmake_minimum_required(VERSION 3.31)
1+
cmake_minimum_required(VERSION 3.25)
22

33
project(gamedata-gen LANGUAGES CXX)
44

55
find_package(PkgConfig)
66

7-
set(CMAKE_CXX_STANDARD 23)
7+
set(CMAKE_CXX_STANDARD 20)
88
set(CMAKE_CXX_STANDARD_REQUIRED ON)
99

1010
pkg_check_modules(libelf libelf REQUIRED IMPORTED_TARGET)
1111

1212
add_subdirectory(external/CLI11)
13+
add_subdirectory(external/fmt)
1314

1415
add_executable(gamedata-gen)
1516

@@ -30,6 +31,7 @@ target_link_libraries(gamedata-gen
3031
PRIVATE
3132
PkgConfig::libelf
3233
CLI11::CLI11
34+
fmt::fmt
3335
)
3436

3537
install(

external/fmt

Submodule fmt added at 77c0fc0

src/formatter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "formatter.hpp"
22

3+
#include <algorithm>
4+
35
bool shouldSkipWindowsFunction(const ClassInfo &classInfo, std::size_t vtableIndex, std::size_t functionIndex, const FunctionInfo &functionInfo)
46
{
57
if (functionInfo.name.starts_with('~'))

src/main.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#include "writer.hpp"
55

66
#include "CLI/CLI.hpp"
7+
#include <fmt/core.h>
78

89
#include <sys/mman.h>
910
#include <sys/stat.h>
1011
#include <fcntl.h>
12+
#include <unistd.h>
1113

1214
#include <cassert>
1315
#include <cstring>
@@ -20,13 +22,13 @@ class mmapReader
2022
auto fd = ::open(path.c_str(), O_RDONLY);
2123
if(fd == -1)
2224
{
23-
throw std::runtime_error(std::format("Failed to open file \"{}\": {} (errno={}) ", path, strerror(errno), errno));
25+
throw std::runtime_error(fmt::format("Failed to open file \"{}\": {} (errno={}) ", path, strerror(errno), errno));
2426
}
2527

2628
struct stat sb {};
2729
if(fstat(fd, &sb) == -1)
2830
{
29-
throw std::runtime_error(std::format("stat failed for file \"{}\": {} (errno={}) ", path, strerror(errno), errno));
31+
throw std::runtime_error(fmt::format("stat failed for file \"{}\": {} (errno={}) ", path, strerror(errno), errno));
3032
}
3133

3234
auto file_size = static_cast<std::size_t>(sb.st_size);
@@ -46,7 +48,7 @@ class mmapReader
4648
{
4749
if(data == MAP_FAILED)
4850
{
49-
throw std::runtime_error(std::format("mmap failed for file \"{}\": {} (errno={}) ", path, strerror(errno), errno));
51+
throw std::runtime_error(fmt::format("mmap failed for file \"{}\": {} (errno={}) ", path, strerror(errno), errno));
5052
}
5153
}
5254

@@ -66,26 +68,26 @@ class mmapReader
6668
auto res = madvise(reinterpret_cast<void*>(m_data), m_mem_size, MADV_DONTNEED | MADV_FREE);
6769
if(res == -1)
6870
{
69-
std::cout << std::format("madvise failed: {} (errno={}) ", strerror(errno), errno);
71+
std::cout << fmt::format("madvise failed: {} (errno={}) ", strerror(errno), errno);
7072
}
7173

7274
res = munmap(reinterpret_cast<void*>(m_data), m_mem_size);
7375
if(res != 0)
7476
{
75-
std::cout << std::format("munmap failed with result {}: {} (errno={}) ", res, strerror(errno), errno);
77+
std::cout << fmt::format("munmap failed with result {}: {} (errno={}) ", res, strerror(errno), errno);
7678
}
7779
}
7880

7981
auto res = posix_fadvise(m_fd, 0, static_cast<off_t>(m_file_size), POSIX_FADV_DONTNEED); //POSIX_FADV_NOREUSE
8082
if(res != 0)
8183
{
82-
std::cout << std::format("posix_fadvise failed: {} (errno={}) ", strerror(errno), errno);
84+
std::cout << fmt::format("posix_fadvise failed: {} (errno={}) ", strerror(errno), errno);
8385
}
8486

8587
res = ::close(m_fd);
8688
if(res == -1)
8789
{
88-
std::cout << std::format("Failed to close file descriptor {}: {} (errno={}) ", m_fd, strerror(errno), errno);
90+
std::cout << fmt::format("Failed to close file descriptor {}: {} (errno={}) ", m_fd, strerror(errno), errno);
8991
}
9092
}
9193

@@ -136,7 +138,7 @@ int main(int argc, char *argv[])
136138

137139
if (outputDirectoryPaths.empty() && !dumpOffsets && !dumpSignatures)
138140
{
139-
std::cerr << std::format("Specify either --output or one of --dump_* options") << std::endl;
141+
std::cerr << fmt::format("Specify either --output or one of --dump_* options") << std::endl;
140142
return EXIT_FAILURE;
141143
}
142144

@@ -155,7 +157,7 @@ int main(int argc, char *argv[])
155157

156158
if (!programInfo.error.empty())
157159
{
158-
std::cerr << std::format("Failed to process input file '{}': {}", libraryPath, programInfo.error) << std::endl;
160+
std::cerr << fmt::format("Failed to process input file '{}': {}", libraryPath, programInfo.error) << std::endl;
159161
return EXIT_FAILURE;
160162
}
161163

@@ -196,7 +198,7 @@ int main(int argc, char *argv[])
196198
for (const auto& function : vtable.functions)
197199
{
198200
std::string shortName = function->shortName.empty() ? "?" : function->shortName;
199-
std::cout << std::format(" [{}] {} ({}::{})", function->id, function->name, function->nameSpace, shortName) << std::endl;
201+
std::cout << fmt::format(" [{}] {} ({}::{})", function->id, function->name, function->nameSpace, shortName) << std::endl;
200202
}
201203
}
202204
}
@@ -223,7 +225,7 @@ int main(int argc, char *argv[])
223225
windowsIndex = std::to_string(function.windowsIndex.value());
224226
}
225227

226-
std::cout << std::format("{}::{} {} {} {}", outClass.name, function.name, (function.isMulti ? " [Multi]" : ""), linuxIndex, windowsIndex) << std::endl;
228+
std::cout << fmt::format("{}::{} {} {} {}", outClass.name, function.name, (function.isMulti ? " [Multi]" : ""), linuxIndex, windowsIndex) << std::endl;
227229
}
228230
}
229231
}
@@ -240,7 +242,7 @@ int main(int argc, char *argv[])
240242
auto demangledSymbol = demangleSymbol(symbol.name.c_str());
241243
auto demangledSymbolText = demangledSymbol ? &*demangledSymbol : symbol.name.c_str();
242244

243-
std::cout << std::format("{} {}", demangledSymbolText, symbol.name) << std::endl;
245+
std::cout << fmt::format("{} {}", demangledSymbolText, symbol.name) << std::endl;
244246
}
245247
}
246248

src/reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool LargeNumber::operator!=(const LargeNumber& other) const
4444

4545
std::ostream& operator<<(std::ostream& os, const LargeNumber& number)
4646
{
47-
os << std::format("{:#018x}", static_cast<unsigned long long>(number));
47+
os << fmt::format("{:#018x}", static_cast<unsigned long long>(number));
4848
return os;
4949
}
5050

src/reader.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

3-
#include <format>
3+
#include <fmt/format.h>
4+
45
#include <iostream>
56
#include <string>
67
#include <vector>
@@ -21,11 +22,11 @@ struct LargeNumber
2122
std::ostream& operator<<(std::ostream& os, const LargeNumber& number);
2223

2324
template <>
24-
struct std::formatter<LargeNumber> : formatter<std::string>
25+
struct fmt::formatter<LargeNumber> : formatter<std::string>
2526
{
2627
auto format(LargeNumber number, format_context& ctx) const
2728
{
28-
return formatter<std::string>::format(std::format("{:#018x}", static_cast<unsigned long long>(number)), ctx);
29+
return formatter<std::string>::format(fmt::format("{:#018x}", static_cast<unsigned long long>(number)), ctx);
2930
}
3031
};
3132

src/writer.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ Offsets prepareOffsets(std::list<ClassInfo>& classes)
3131
{
3232
if (!function.linuxIndex.has_value())
3333
{
34-
// std::cerr << std::format("Warning: function {} has no linuxIndex value", function.name) << std::endl;
34+
// std::cerr << fmt::format("Warning: function {} has no linuxIndex value", function.name) << std::endl;
3535
continue;
3636
}
3737

3838
if (!function.windowsIndex.has_value())
3939
{
40-
// std::cerr << std::format("Warning: function {} has no windowsIndex value", function.name) << std::endl;
40+
// std::cerr << fmt::format("Warning: function {} has no windowsIndex value", function.name) << std::endl;
4141
continue;
4242
}
4343

@@ -55,21 +55,21 @@ std::optional<int> getOffset(Offsets offsets, const std::string& symbol)
5555
auto functionNameStartPos = symbol.rfind("::");
5656
if (functionNameStartPos == std::string::npos)
5757
{
58-
std::cerr << std::format("Error: incorrect format of symbol {} (missing \'::\' separator)", symbol) << std::endl;
58+
std::cerr << fmt::format("Error: incorrect format of symbol {} (missing \'::\' separator)", symbol) << std::endl;
5959
return std::nullopt;
6060
}
6161

6262
auto systemNameStartPos = symbol.rfind('.');
6363
if (systemNameStartPos == std::string::npos)
6464
{
65-
std::cerr << std::format("Error: incorrect format of symbol {} (missing \'.\' separator)", symbol) << std::endl;
65+
std::cerr << fmt::format("Error: incorrect format of symbol {} (missing \'.\' separator)", symbol) << std::endl;
6666
return std::nullopt;
6767
}
6868

6969
auto namespaceStartPos = symbol.find("::");
7070
if (namespaceStartPos == std::string::npos)
7171
{
72-
std::cerr << std::format("Error: incorrect format of symbol {} (missing \'::\' separator)", symbol) << std::endl;
72+
std::cerr << fmt::format("Error: incorrect format of symbol {} (missing \'::\' separator)", symbol) << std::endl;
7373
return std::nullopt;
7474
}
7575

@@ -81,23 +81,23 @@ std::optional<int> getOffset(Offsets offsets, const std::string& symbol)
8181
auto classVTablesIterator = offsets.find(className);
8282
if (classVTablesIterator == offsets.end())
8383
{
84-
std::cerr << std::format("Error: failed to find class vtable by its name \'{}\')", className) << std::endl;
84+
std::cerr << fmt::format("Error: failed to find class vtable by its name \'{}\')", className) << std::endl;
8585
return std::nullopt;
8686
}
8787
const auto& classVTables = classVTablesIterator->second;
8888

8989
auto classNamespaceIterator = classVTables.find(namespaceName);
9090
if (classNamespaceIterator == classVTables.end())
9191
{
92-
std::cerr << std::format("Error: failed to find class namespace by its name \'{}\')", namespaceName) << std::endl;
92+
std::cerr << fmt::format("Error: failed to find class namespace by its name \'{}\')", namespaceName) << std::endl;
9393
return std::nullopt;
9494
}
9595
const auto& classNamespace = classNamespaceIterator->second;
9696

9797
auto functionIterator = classNamespace.find(functionName);
9898
if (functionIterator == classNamespace.end())
9999
{
100-
std::cerr << std::format("Error: failed to find function by its name \'{}\'", functionName) << std::endl;
100+
std::cerr << fmt::format("Error: failed to find function by its name \'{}\'", functionName) << std::endl;
101101
return std::nullopt;
102102
}
103103
const auto& function = functionIterator->second;
@@ -126,14 +126,14 @@ int writeGamedataFile(std::list<ClassInfo>& classes, const std::vector<std::file
126126

127127
if (inputFileExtension != inputFileExtensionString)
128128
{
129-
std::cerr << std::format("Error: input file {} doesn't contain correct file extension {}", inputFilePath.string(), inputFileExtension.string()) << std::endl;
129+
std::cerr << fmt::format("Error: input file {} doesn't contain correct file extension {}", inputFilePath.string(), inputFileExtension.string()) << std::endl;
130130
return EXIT_FAILURE;
131131
}
132132

133133
std::ifstream inputStream(inputFilePath);
134134
if (!inputStream)
135135
{
136-
std::cerr << std::format("Error: input file {} open failed - {}", inputFilePath.string(), std::strerror(errno)) << std::endl;
136+
std::cerr << fmt::format("Error: input file {} open failed - {}", inputFilePath.string(), std::strerror(errno)) << std::endl;
137137
return EXIT_FAILURE;
138138
}
139139

@@ -144,7 +144,7 @@ int writeGamedataFile(std::list<ClassInfo>& classes, const std::vector<std::file
144144

145145
if (!std::filesystem::exists(outputFileDir))
146146
{
147-
std::cerr << std::format("Error: failed to create {} directory", outputFileDir.string(), std::strerror(errno)) << std::endl;
147+
std::cerr << fmt::format("Error: failed to create {} directory", outputFileDir.string(), std::strerror(errno)) << std::endl;
148148
return EXIT_FAILURE;
149149
}
150150

@@ -153,7 +153,7 @@ int writeGamedataFile(std::list<ClassInfo>& classes, const std::vector<std::file
153153
std::ofstream outputStream(outputFile);
154154
if (!outputStream)
155155
{
156-
std::cerr << std::format("Error: output file {} open failed - {}", outputFile.string(), std::strerror(errno)) << std::endl;
156+
std::cerr << fmt::format("Error: output file {} open failed - {}", outputFile.string(), std::strerror(errno)) << std::endl;
157157
return EXIT_FAILURE;
158158
}
159159

@@ -169,21 +169,21 @@ int writeGamedataFile(std::list<ClassInfo>& classes, const std::vector<std::file
169169
auto endPos = line.rfind('#');
170170
if (endPos == startPos)
171171
{
172-
std::cerr << std::format("Error: input file {} contains only one \'#\' at line {}", inputFilePath.string(), lineNumber) << std::endl;
172+
std::cerr << fmt::format("Error: input file {} contains only one \'#\' at line {}", inputFilePath.string(), lineNumber) << std::endl;
173173
return EINVAL;
174174
}
175175

176176
auto symbol = line.substr(startPos + 1, endPos - startPos - 1);
177177
if (symbol.empty())
178178
{
179-
std::cerr << std::format("Error: symbol from input file {} at line {} is empty somehow", inputFilePath.string(), lineNumber) << std::endl;
179+
std::cerr << fmt::format("Error: symbol from input file {} at line {} is empty somehow", inputFilePath.string(), lineNumber) << std::endl;
180180
return EINVAL;
181181
}
182182

183183
auto offset = getOffset(offsets, symbol);
184184
if (!offset.has_value())
185185
{
186-
std::cerr << std::format("Error: failed to get offset of symbol {} from input file {} at line {}", symbol, inputFilePath.string(), lineNumber) << std::endl;
186+
std::cerr << fmt::format("Error: failed to get offset of symbol {} from input file {} at line {}", symbol, inputFilePath.string(), lineNumber) << std::endl;
187187
return EINVAL;
188188
}
189189

0 commit comments

Comments
 (0)