Skip to content

Commit

Permalink
Preparation for the release (#1861)
Browse files Browse the repository at this point in the history
* Preparations for the major.minor.patch engine naming

* Make archive cache file depend only on the ArchiveScanner's INTERNAL_VER

* Also try to read the content cache from the existing(old) directory in case the file at new location cannot be read
  • Loading branch information
lhog authored Dec 29, 2024
1 parent 7545315 commit 2bfae9e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 46 deletions.
2 changes: 1 addition & 1 deletion rts/Game/GameVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const std::string& GetMajor()

const std::string& GetMinor()
{
static const std::string minor = "0";
static const std::string minor = SPRING_VERSION_ENGINE_MINOR;
return minor;
}

Expand Down
58 changes: 40 additions & 18 deletions rts/System/FileSystem/ArchiveScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,13 @@ static std::atomic<uint32_t> numScannedArchives{0};

CArchiveScanner::CArchiveScanner()
{
Clear();
// the "cache" dir is created in DataDirLocater
ReadCacheData(cachefile = FileSystem::EnsurePathSepAtEnd(FileSystem::GetCacheDir()) + IntToString(INTERNAL_VER, "ArchiveCache%i.lua"));
ScanAllDirs();
ReadCache();
}


CArchiveScanner::~CArchiveScanner()
{
if (!isDirty)
return;

WriteCacheData(GetFilepath());
WriteCache();
}

uint32_t CArchiveScanner::GetNumScannedArchives()
Expand All @@ -421,7 +415,7 @@ void CArchiveScanner::Clear()
brokenArchives.reserve(16);
brokenArchivesIndex.clear();
brokenArchivesIndex.reserve(16);
cachefile.clear();
cacheFile.clear();
numFilesHashed.store(0);
}

Expand All @@ -431,13 +425,10 @@ void CArchiveScanner::Reload()
std::lock_guard<decltype(scannerMutex)> lck(scannerMutex);

// dtor
if (isDirty)
WriteCacheData(GetFilepath());
WriteCache();

// ctor
Clear();
ReadCacheData(cachefile = FileSystem::EnsurePathSepAtEnd(FileSystem::GetCacheDir()) + IntToString(INTERNAL_VER, "ArchiveCache%i.lua"));
ScanAllDirs();
ReadCache();
}

void CArchiveScanner::ScanAllDirs()
Expand Down Expand Up @@ -617,6 +608,35 @@ std::string CArchiveScanner::SearchMapFile(const IArchive* ar, std::string& erro
}


void CArchiveScanner::ReadCache()
{
Clear();

const std::array<std::string, 2> cachePaths {
FileSystem::EnsurePathSepAtEnd(FileSystem::GetCacheDir() ) + IntToString(INTERNAL_VER, "ArchiveCache%i.lua"),
FileSystem::EnsurePathSepAtEnd(FileSystem::GetOldCacheDir()) + IntToString(INTERNAL_VER, "ArchiveCache%i.lua")
};

for (const auto& cachePath : cachePaths) {
if (ReadCacheData(cachePath)) {
break;
}
}

// file to write to in WriteCache()
cacheFile = cachePaths.front();

ScanAllDirs();
}

void CArchiveScanner::WriteCache()
{
if (!isDirty)
return;

WriteCacheData(GetFilepath());
}

CArchiveScanner::ArchiveInfo& CArchiveScanner::GetAddArchiveInfo(const std::string& lcfn)
{
auto aiIter = archiveInfosIndex.find(lcfn);
Expand Down Expand Up @@ -1031,18 +1051,18 @@ bool CArchiveScanner::GetArchiveChecksum(const std::string& archiveName, Archive
}


void CArchiveScanner::ReadCacheData(const std::string& filename)
bool CArchiveScanner::ReadCacheData(const std::string& filename)
{
std::lock_guard<decltype(scannerMutex)> lck(scannerMutex);
if (!FileSystem::FileExists(filename)) {
LOG_L(L_INFO, "[AS::%s] ArchiveCache %s doesn't exist", __func__, filename.c_str());
return;
return false;
}

LuaParser p(filename, SPRING_VFS_RAW, SPRING_VFS_BASE);
if (!p.Execute()) {
LOG_L(L_ERROR, "[AS::%s] failed to parse ArchiveCache: %s", __func__, p.GetErrorLog().c_str());
return;
return false;
}

const LuaTable& archiveCacheTbl = p.GetRoot();
Expand All @@ -1052,7 +1072,7 @@ void CArchiveScanner::ReadCacheData(const std::string& filename)
// Do not load old version caches
const int ver = archiveCacheTbl.GetInt("internalver", (INTERNAL_VER + 1));
if (ver != INTERNAL_VER)
return;
return false;

for (int i = 1; archivesTbl.KeyExists(i); ++i) {
const LuaTable& curArchiveTbl = archivesTbl.SubTable(i);
Expand Down Expand Up @@ -1109,6 +1129,8 @@ void CArchiveScanner::ReadCacheData(const std::string& filename)
}

isDirty = false;

return true;
}

static inline void SafeStr(FILE* out, const char* prefix, const std::string& str)
Expand Down
9 changes: 6 additions & 3 deletions rts/System/FileSystem/ArchiveScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CArchiveScanner
~CArchiveScanner();

public:
const std::string& GetFilepath() const { return cachefile; }
const std::string& GetFilepath() const { return cacheFile; }

static const char* GetMapHelperContentName() { return "Map Helper v1"; }
static const char* GetSpringBaseContentName() { return "Spring content v1"; }
Expand Down Expand Up @@ -188,6 +188,9 @@ class CArchiveScanner
};

private:
void ReadCache();
void WriteCache();

ArchiveInfo& GetAddArchiveInfo(const std::string& lcfn);
BrokenArchive& GetAddBrokenArchive(const std::string& lcfn);

Expand All @@ -204,7 +207,7 @@ class CArchiveScanner
std::string SearchMapFile(const IArchive* ar, std::string& error);


void ReadCacheData(const std::string& filename);
bool ReadCacheData(const std::string& filename);
void WriteCacheData(const std::string& filename);

IFileFilter* CreateIgnoreFilter(IArchive* ar);
Expand Down Expand Up @@ -247,7 +250,7 @@ class CArchiveScanner
std::vector<ArchiveInfo> archiveInfos;
std::vector<BrokenArchive> brokenArchives;

std::string cachefile;
std::string cacheFile;

bool isDirty = false;
bool isInScan = false;
Expand Down
15 changes: 8 additions & 7 deletions rts/System/FileSystem/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,14 @@ const std::string& FileSystem::GetCacheBaseDir()

const std::string& FileSystem::GetCacheDir()
{
// cache-dir versioning must not be too finegrained,
// we do want to regenerate cache after every commit
//
// release builds must however also *never* use the
// same directory as any previous development build
// (regardless of branch), so keep caches separate
static const std::string cacheType[2] = {"dev-", "rel-"};
static const std::string cacheDir = EnsureNoPathSepAtEnd(GetCacheBaseDir());
return cacheDir;
}

const std::string& FileSystem::GetOldCacheDir()
{
// old code
static const std::string cacheType[2] = { "dev-", "rel-" };
static const std::string cacheVersion = SpringVersion::GetMajor() + cacheType[SpringVersion::IsRelease()] + SpringVersion::GetBranch();
static const std::string cacheDir = EnsurePathSepAtEnd(GetCacheBaseDir()) + cacheVersion;
return cacheDir;
Expand Down
1 change: 1 addition & 0 deletions rts/System/FileSystem/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class FileSystem : public FileSystemAbstraction

static const std::string& GetCacheBaseDir();
static const std::string& GetCacheDir();
static const std::string& GetOldCacheDir();
};

#endif // !FILE_SYSTEM_H
19 changes: 11 additions & 8 deletions rts/System/VersionGenerated.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@
#define VERSION_GENERATED_H

/// examples: "83.0" "83.0.1-13-g1234567 develop"
static const char* SPRING_VERSION_ENGINE = "@SPRING_VERSION_ENGINE@";
static constexpr const char* SPRING_VERSION_ENGINE = "@SPRING_VERSION_ENGINE@";

/// examples: "83"
static const char* SPRING_VERSION_ENGINE_MAJOR = "@SPRING_VERSION_ENGINE_MAJOR@";
static constexpr const char* SPRING_VERSION_ENGINE_MAJOR = "@SPRING_VERSION_ENGINE_MAJOR@";

/// examples: "83"
static constexpr const char* SPRING_VERSION_ENGINE_MINOR = "@SPRING_VERSION_ENGINE_MINOR@";

/// examples: "0"
static const char* SPRING_VERSION_ENGINE_PATCH_SET = "@SPRING_VERSION_ENGINE_PATCH_SET@";
static constexpr const char* SPRING_VERSION_ENGINE_PATCH_SET = "@SPRING_VERSION_ENGINE_PATCH_SET@";

/// examples: "13"
static const char* SPRING_VERSION_ENGINE_COMMITS = "@SPRING_VERSION_ENGINE_COMMITS@";
static constexpr const char* SPRING_VERSION_ENGINE_COMMITS = "@SPRING_VERSION_ENGINE_COMMITS@";

/// examples: "1234567"
static const char* SPRING_VERSION_ENGINE_HASH = "@SPRING_VERSION_ENGINE_HASH@";
static constexpr const char* SPRING_VERSION_ENGINE_HASH = "@SPRING_VERSION_ENGINE_HASH@";

/// examples: "develop"
static const char* SPRING_VERSION_ENGINE_BRANCH = "@SPRING_VERSION_ENGINE_BRANCH@";
static constexpr const char* SPRING_VERSION_ENGINE_BRANCH = "@SPRING_VERSION_ENGINE_BRANCH@";

/// examples: "what a splendid day, isn't it?"
static const char* SPRING_VERSION_ENGINE_ADDITIONAL = "@SPRING_VERSION_ENGINE_ADDITIONAL@";
static constexpr const char* SPRING_VERSION_ENGINE_ADDITIONAL = "@SPRING_VERSION_ENGINE_ADDITIONAL@";

/// examples: true, false
static bool SPRING_VERSION_ENGINE_RELEASE = @SPRING_VERSION_ENGINE_RELEASE@;
static constexpr bool SPRING_VERSION_ENGINE_RELEASE = @SPRING_VERSION_ENGINE_RELEASE@;

#endif // VERSION_GENERATED_H

Expand Down
23 changes: 14 additions & 9 deletions rts/build/cmake/UtilVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ Set(D10 "[0-9]") # matches a decimal digit
Set(D16 "[0-9a-f]") # matches a (lower-case) hexadecimal digit

# Matches the engine major version part
# Releases that do NOT preserve sync show a change here (see release branch)
Set(VERSION_REGEX_MAJOR "${D10}+")
Set(VERSION_REGEX_MAJOR_MATCH_EXAMPLES "\"83\", \"90\", \"999\"")

# Matches the engine minor version part
Set(VERSION_REGEX_MINOR "${D10}+")
Set(VERSION_REGEX_MINOR_MATCH_EXAMPLES "\"83\", \"90\", \"999\"")

# Matches the engine patchSet version part
# Releases that preserve sync show a change here (see hotfix branch)
Set(VERSION_REGEX_PATCH "${D10}+")
Set(VERSION_REGEX_PATCH_MATCH_EXAMPLES "\"0\", \"5\", \"999\"")

# Matches the engine dev version postfix (".1-<#commits>-g<SHA1> <branch>")
Set(VERSION_REGEX_DEV_POSTFIX "[.]1-(${D10}+)-g(${D16}+) ([^ ]+)")
Set(VERSION_REGEX_DEV_POSTFIX "-(${D10}+)-g(${D16}+) ([^ ]+)")
Set(VERSION_REGEX_DEV_POSTFIX_MATCH_EXAMPLES "\".1-13-g1234aaf develop\", \".1-1354-g1234567 release\"")


Expand All @@ -42,7 +44,7 @@ Set(VERSION_REGEX_DEV_POSTFIX_MATCH_EXAMPLES "\".1-13-g1234aaf develop\", \".1-1
# \\3 : Commits since last release, for example "2302"
# \\4 : First 7 digits of the current commit's SHA1, for example "6d3a71e"
# \\5 : Git branch, for example "develop"
Set(VERSION_REGEX_RELEASE "(${VERSION_REGEX_MAJOR})[.](${VERSION_REGEX_PATCH})")
Set(VERSION_REGEX_RELEASE "(${VERSION_REGEX_MAJOR})[.](${VERSION_REGEX_MINOR})[.](${VERSION_REGEX_PATCH})")
Set(VERSION_REGEX_RELEASE_MATCH_EXAMPLES "\"83.0\", \"84.1\"")
Set(VERSION_REGEX_DEV "${VERSION_REGEX_RELEASE}${VERSION_REGEX_DEV_POSTFIX}")
Set(VERSION_REGEX_DEV_MATCH_EXAMPLES "\"83.0.1-13-g1234aaf develop\", \"84.1.1-1354-g1234567 release\"")
Expand All @@ -55,20 +57,23 @@ Set(VERSION_REGEX_ANY_MATCH_EXAMPLES "83.0" "84.1" "83.0.1-13-g1234aaf develop"
# sample version: "83.2.1-2302-g6d3a71e develop"
# sample output:
# - ${varPrefix}_MAJOR "83"
# - ${varPrefix}_MINOR "1"
# - ${varPrefix}_PATCH_SET "2"
# - ${varPrefix}_COMMITS "2302"
# - ${varPrefix}_HASH "6d3a71e"
# - ${varPrefix}_BRANCH "develop"
Macro (parse_spring_version varPrefix version)
catch_regex_group("${VERSION_REGEX_ANY}" 1 "${varPrefix}_MAJOR" "${version}")
catch_regex_group("${VERSION_REGEX_ANY}" 2 "${varPrefix}_PATCH_SET" "${version}")
catch_regex_group("${VERSION_REGEX_DEV}" 3 "${varPrefix}_COMMITS" "${version}")
catch_regex_group("${VERSION_REGEX_DEV}" 4 "${varPrefix}_HASH" "${version}")
catch_regex_group("${VERSION_REGEX_DEV}" 5 "${varPrefix}_BRANCH" "${version}")
catch_regex_group("${VERSION_REGEX_ANY}" 2 "${varPrefix}_MINOR" "${version}")
catch_regex_group("${VERSION_REGEX_ANY}" 3 "${varPrefix}_PATCH_SET" "${version}")
catch_regex_group("${VERSION_REGEX_DEV}" 4 "${varPrefix}_COMMITS" "${version}")
catch_regex_group("${VERSION_REGEX_DEV}" 5 "${varPrefix}_HASH" "${version}")
catch_regex_group("${VERSION_REGEX_DEV}" 6 "${varPrefix}_BRANCH" "${version}")
EndMacro (parse_spring_version)

Macro (PrintParsedSpringVersion varPrefix)
Message(" major: ${${varPrefix}_MAJOR}")
Message(" minor: ${${varPrefix}_MINOR}")
Message(" patch-set: ${${varPrefix}_PATCH_SET}")
Message(" commits: ${${varPrefix}_COMMITS}")
Message(" hash: ${${varPrefix}_HASH}")
Expand All @@ -85,8 +90,8 @@ EndMacro (PrintParsedSpringVersion)
# - commits "2302"
# - hash "6d3a71e"
# sample output: "0.82.7.1-2302-g6d3a71e"
Macro (create_spring_version_string res_var major patchSet commits hash branch)
Set(${res_var} "${major}.${patchSet}")
Macro (create_spring_version_string res_var major minor patchSet commits hash branch)
Set(${res_var} "${major}.${minor}.${patchSet}")
If (NOT "${commits}" STREQUAL "")
Set(${res_var} "${${res_var}}-${commits}-g${hash} ${branch}")
EndIf ()
Expand Down

0 comments on commit 2bfae9e

Please sign in to comment.