Skip to content

Commit 412618d

Browse files
authored
Update doo files without rebuilding to avoid Z3 timeout issues (#6337)
## Problem During minor version patches, the current version bump process rebuilds standard libraries with the new version. However, when the build machine has a different version of Z3, the standard libraries sometimes timeout, making the build process non-deterministic. ## Solution This PR modifies the version bump script to update doo files without rebuilding them: 1. **For standard library doo files**: Instead of running `make -C Source/DafnyStandardLibraries update-binary`, the script now: - Unzips each doo file (which are actually zip archives) - Updates the `dafny_version` field in the `manifest.toml` file - Rezips the file 2. **For test doo files**: Instead of rebuilding from source, the script updates the version in the existing doo files using the same approach. ## Files Modified - `Scripts/bump_version_number.js`: Added `updateDooVersion` function and replaced rebuild logic - `docs/dev/VERSIONBUMP.md`: Updated documentation to reflect the new approach ## Testing - Tested in test mode with version 4.10.2 - Verified that doo files are correctly updated with new version numbers - All existing functionality for updating other version references remains intact ## ⚠️ Important Note **This PR was created using Amazon Q and requires careful review.** ## Benefits - Makes version bumps more deterministic - Avoids Z3 timeout issues on machines with different Z3 versions - Faster version bump process (no compilation required) - Maintains the same end result (updated version numbers in doo files)
1 parent 5b388dd commit 412618d

File tree

2 files changed

+64
-21
lines changed

2 files changed

+64
-21
lines changed

Scripts/bump_version_number.js

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,35 @@ async function synchronizeRepositoryWithNewVersionNumber() {
4343
} else {
4444
await bumpVersionNumber(version);
4545
}
46-
//# * Compile Dafny to ensure you have the right version number.
47-
await execute("make exe");
48-
49-
//# * Compile the standard libraries and update their binaries which are checked in
50-
await executeWithTimeout("make -C Source/DafnyStandardLibraries update-binary", 50*minutes);
46+
//# * Update standard library doo files instead of rebuilding to avoid Z3 timeout issues
47+
const standardLibraryDir = "Source/DafnyStandardLibraries/binaries";
48+
const standardLibraryDooFiles = fs.readdirSync(standardLibraryDir)
49+
.filter(file => file.endsWith('.doo'))
50+
.map(file => `${standardLibraryDir}/${file}`);
51+
52+
for (const dooFile of standardLibraryDooFiles) {
53+
await updateDooVersion(dooFile, version);
54+
}
5155

5256
// Verify that binaries have been updated.
5357
await sanityCheckStandardLibraries(version);
5458

55-
//# * Recompile Dafny so that standard libraries are in the executable.
56-
await execute("make exe");
57-
5859
//# * In the test directory `Source/IntegrationTests/TestFiles/LitTests/LitTest`,
59-
await execute(
60-
//# * Rebuild `pythonmodule/multimodule/PythonModule1.doo` from `pythonmodule/multimodule/dafnysource/helloworld.dfy`
61-
`bash Scripts/dafny build -t:lib ${TestDirectory}/pythonmodule/multimodule/dafnysource/helloworld.dfy -o ${TestDirectory}/pythonmodule/multimodule/PythonModule1.doo`,
62-
//# * Rebuild `pythonmodule/nestedmodule/SomeNestedModule.doo` from `pythonmodule/nestedmodule/dafnysource/SomeNestedModule.dfy`
63-
`bash Scripts/dafny build -t:lib ${TestDirectory}/pythonmodule/nestedmodule/dafnysource/SomeNestedModule.dfy -o ${TestDirectory}/pythonmodule/nestedmodule/SomeNestedModule.doo`,
64-
//# * Rebuild `gomodule/multimodule/test.doo` from `gomodule/multimodule/dafnysource/helloworld.dfy`
65-
`bash Scripts/dafny build -t:lib ${TestDirectory}/gomodule/multimodule/dafnysource/helloworld.dfy -o ${TestDirectory}/gomodule/multimodule/test.doo`);
60+
//# * Update test doo files instead of rebuilding
61+
//# * Update `pythonmodule/multimodule/PythonModule1.doo` version
62+
//# * Update `pythonmodule/nestedmodule/SomeNestedModule.doo` version
63+
//# * Update `gomodule/multimodule/test.doo` version
64+
const testDooFiles = [
65+
`${TestDirectory}/pythonmodule/multimodule/PythonModule1.doo`,
66+
`${TestDirectory}/pythonmodule/nestedmodule/SomeNestedModule.doo`,
67+
`${TestDirectory}/gomodule/multimodule/test.doo`
68+
];
69+
70+
for (const dooFile of testDooFiles) {
71+
if (fs.existsSync(dooFile)) {
72+
await updateDooVersion(dooFile, version);
73+
}
74+
}
6675

6776
//# * Search for `dafny_version = ` in checked-in `.dtr` files of the `<TestDirectory>`
6877
//# and update the version number.
@@ -100,6 +109,41 @@ async function synchronizeRepositoryWithNewVersionNumber() {
100109
`Source/DafnyRuntime/DafnyRuntime.csproj`, existingVersion);
101110
}
102111

112+
async function updateDooVersion(dooPath, newVersion) {
113+
const tempDir = `${dooPath}_temp`;
114+
115+
try {
116+
// Create temp directory
117+
await execAsync(`mkdir -p "${tempDir}"`);
118+
119+
// Unzip doo file
120+
await execAsync(`unzip -o "${dooPath}" -d "${tempDir}"`);
121+
122+
// Read manifest.toml
123+
const manifestPath = `${tempDir}/manifest.toml`;
124+
let manifestContent = await fs.promises.readFile(manifestPath, 'utf-8');
125+
126+
// Update version
127+
manifestContent = manifestContent.replace(
128+
/dafny_version = "(\d+\.\d+\.\d+)\.0"/,
129+
`dafny_version = "${newVersion}.0"`
130+
);
131+
132+
// Write updated manifest
133+
await fs.promises.writeFile(manifestPath, manifestContent);
134+
135+
// Rezip
136+
const fileName = dooPath.split('/').pop();
137+
await execAsync(`cd "${tempDir}" && zip -r "../${fileName}_new" *`);
138+
await execAsync(`mv "${tempDir}/../${fileName}_new" "${dooPath}"`);
139+
140+
console.log(`Updated ${dooPath} to version ${newVersion}`);
141+
} finally {
142+
// Cleanup
143+
await execAsync(`rm -rf "${tempDir}"`).catch(() => {});
144+
}
145+
}
146+
103147
// Unzips the file Source/DafnyStandardLibraries/binaries/DafnyStandardLibraries.doo (it's actually a zip file)
104148
// Fetch the content of Source/DafnyStandardLibraries/binaries/DafnyStandardLibraries/manifest.toml
105149
// Verify that dafny_version = "Major.Minor.Patch.0" corresponds ot the version that is provided

docs/dev/VERSIONBUMP.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ verifies that this file is in sync with that script.
2323

2424
Assuming `<TestDirectory>` to be `Source/IntegrationTests/TestFiles/LitTests/LitTest`,
2525
perform the following:
26-
* Compile Dafny to ensure you have the right version number.
27-
* Compile the standard libraries and update their binaries which are checked in
28-
* Recompile Dafny so that standard libraries are in the executable.
26+
* Update standard library doo files instead of rebuilding to avoid Z3 timeout issues
2927
* In the test directory `Source/IntegrationTests/TestFiles/LitTests/LitTest`,
30-
* Rebuild `pythonmodule/multimodule/PythonModule1.doo` from `pythonmodule/multimodule/dafnysource/helloworld.dfy`
31-
* Rebuild `pythonmodule/nestedmodule/SomeNestedModule.doo` from `pythonmodule/nestedmodule/dafnysource/SomeNestedModule.dfy`
32-
* Rebuild `gomodule/multimodule/test.doo` from `gomodule/multimodule/dafnysource/helloworld.dfy`
28+
* Update test doo files instead of rebuilding
29+
* Update `pythonmodule/multimodule/PythonModule1.doo` version
30+
* Update `pythonmodule/nestedmodule/SomeNestedModule.doo` version
31+
* Update `gomodule/multimodule/test.doo` version
3332
* Search for `dafny_version = ` in checked-in `.dtr` files of the `<TestDirectory>`
3433
and update the version number.
3534
Except for the file NoGood.dtr which is not valid.

0 commit comments

Comments
 (0)