Avoid unnecessary recompilation of many C++ files at each build

Only show in developer changelog
This commit is contained in:
Florian Rival
2024-09-09 13:39:34 +02:00
committed by GitHub
parent 852bf78c81
commit 762f7ca19c

View File

@@ -1,11 +1,35 @@
const path = require('path');
const fs = require('fs');
const [gdVersion, prerelease] = require('../../newIDE/electron-app/app/package.json').version.split('-');
const versionPrivContent =
`// This file is automatically synchronizing with newIDE/electron-app/app/package.json version
// Get the version details from the package.json
const [
gdVersion,
prerelease,
] = require('../../newIDE/electron-app/app/package.json').version.split('-');
const versionPrivContent = `// This file is automatically synchronizing with newIDE/electron-app/app/package.json version
// Check GDevelop/scripts/sync-versions.js for more details
#define GD_VERSION_STRING "${gdVersion}-${prerelease || 0}"
`;
fs.writeFileSync(path.join(__dirname, "../../Core/GDCore/Tools/VersionPriv.h"), versionPrivContent, "utf8");
const filePath = path.join(__dirname, '../../Core/GDCore/Tools/VersionPriv.h');
let currentContent;
try {
currentContent = fs.readFileSync(filePath, 'utf8');
} catch (error) {
if (error.code === 'ENOENT') {
// VersionPriv.h does not exist, will be created.
} else {
console.log('❌ Error reading VersionPriv.h file');
throw error; // Rethrow error if not a 'file not found' error
}
}
// Write to the file only if the content has changed to avoid unnecessary recompilation of C++ files.
if (currentContent !== versionPrivContent) {
fs.writeFileSync(filePath, versionPrivContent, 'utf8');
console.log('✅ VersionPriv.h updated with the version number.');
} else {
console.log(' VersionPriv.h is up to date.');
}