-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_headers.cpp
More file actions
executable file
·71 lines (60 loc) · 2.31 KB
/
gen_headers.cpp
File metadata and controls
executable file
·71 lines (60 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// gen_headers.cpp
// Usage: gen_headers <headers_dir> <out_AllHeaders.h>
// Generates a single umbrella header that #includes every SGNV*.h in headers_dir (non-recursive).
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
namespace fs = std::filesystem;
static bool has_ext(const fs::path& p, const char* ext) {
return p.has_extension() && p.extension().string() == ext;
}
static bool starts_with(const std::string& s, const char* prefix) {
return s.rfind(prefix, 0) == 0;
}
int main(int argc, char** argv) {
if (argc < 3) {
std::cerr << "usage: gen_headers <headers_dir> <out_AllHeaders.h>\n";
return 2;
}
fs::path headersDir = fs::u8path(argv[1]);
fs::path outFile = fs::u8path(argv[2]);
if (!fs::exists(headersDir) || !fs::is_directory(headersDir)) {
std::cerr << "gen_headers: headers_dir not found: " << headersDir << "\n";
return 2;
}
std::vector<std::string> rels;
for (const auto& de : fs::directory_iterator(headersDir)) {
if (!de.is_regular_file()) continue;
const auto& p = de.path();
if (!has_ext(p, ".h")) continue;
const std::string fname = p.filename().string();
// Include only SGNV*.h to avoid noise
if (!starts_with(fname, "SGNV")) continue;
// Produce include relative to CWD where AllHeaders.h will live.
// Caller passes headersDir relative to that CWD, so keep the same.
fs::path incPath = fs::path(argv[1]) / fname;
rels.push_back(incPath.generic_string());
}
std::sort(rels.begin(), rels.end());
rels.erase(std::unique(rels.begin(), rels.end()), rels.end());
std::ofstream os(outFile, std::ios::binary);
if (!os) {
std::cerr << "gen_headers: cannot open output: " << outFile << "\n";
return 2;
}
os << "// Auto-generated by gen_headers. Do not edit.\n";
os << "#pragma once\n\n";
for (const auto& inc : rels) {
os << "#include \"" << inc << "\"\n";
}
os.flush();
if (!os) {
std::cerr << "gen_headers: write failed: " << outFile << "\n";
return 2;
}
std::cout << "Generated AllHeaders.h with " << rels.size() << " headers.\n";
return 0;
}