Skip to content

Commit 2f243e3

Browse files
committed
Sort asar header, pass SOURCE_DATE_EPOCH to snap container
1 parent 41ebf35 commit 2f243e3

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

build/azure-pipelines/linux/build-snap.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ sudo apt-get install -y curl apt-transport-https ca-certificates
1717
SNAP_ROOT="$(pwd)/.build/linux/snap/$VSCODE_ARCH"
1818

1919
# Create snap package
20-
BUILD_VERSION="$(git log -1 --pretty=%ct)"
20+
# SOURCE_DATE_EPOCH is provided by the outer pipeline (where git is available);
21+
# the snapcraft container does not include git.
22+
BUILD_VERSION="${SOURCE_DATE_EPOCH:-$(date +%s)}"
2123
SNAP_FILENAME="code-$VSCODE_QUALITY-$VSCODE_ARCH-$BUILD_VERSION.snap"
2224
SNAP_PATH="$SNAP_ROOT/$SNAP_FILENAME"
2325
case $VSCODE_ARCH in

build/azure-pipelines/linux/steps/product-build-linux-compile.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ steps:
357357
- script: |
358358
set -e
359359
npm run gulp "vscode-linux-$(VSCODE_ARCH)-prepare-snap"
360-
sudo -E docker run -e VSCODE_ARCH -e VSCODE_QUALITY -v $(pwd):/work -w /work vscodehub.azurecr.io/vscode-linux-build-agent:snapcraft-x64@sha256:ab4a88c4d85e0d7a85acabba59543f7143f575bab2c0b2b07f5b77d4a7e491ff /bin/bash -c "./build/azure-pipelines/linux/build-snap.sh"
360+
export SOURCE_DATE_EPOCH="$(git log -1 --pretty=%ct)"
361+
sudo -E docker run -e VSCODE_ARCH -e VSCODE_QUALITY -e SOURCE_DATE_EPOCH -v $(pwd):/work -w /work vscodehub.azurecr.io/vscode-linux-build-agent:snapcraft-x64@sha256:ab4a88c4d85e0d7a85acabba59543f7143f575bab2c0b2b07f5b77d4a7e491ff /bin/bash -c "./build/azure-pipelines/linux/build-snap.sh"
361362
362363
SNAP_ROOT="$(pwd)/.build/linux/snap/$(VSCODE_ARCH)"
363364
SNAP_EXTRACTED_PATH=$(find $SNAP_ROOT -maxdepth 1 -type d -name 'code-*')

build/lib/asar.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs:
129129
const finish = () => {
130130
{
131131
const headerPickle = pickle.createEmpty();
132-
headerPickle.writeString(JSON.stringify(filesystem.header));
132+
headerPickle.writeString(JSON.stringify(sortAsarHeader(filesystem.header)));
133133
const headerBuf = headerPickle.toBuffer();
134134

135135
const sizePickle = pickle.createEmpty();
@@ -164,3 +164,22 @@ export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs:
164164
}
165165
});
166166
}
167+
168+
// Recursively sorts directory entries in an asar filesystem header so that
169+
// serialization order does not depend on the order in which files arrived in
170+
// the input stream (which is filesystem-dependent via readdir).
171+
function sortAsarHeader<T>(node: T): T {
172+
if (!node || typeof node !== 'object') {
173+
return node;
174+
}
175+
const obj = node as Record<string, unknown>;
176+
const files = obj['files'];
177+
if (files && typeof files === 'object') {
178+
const sorted: Record<string, unknown> = {};
179+
for (const key of Object.keys(files as Record<string, unknown>).sort()) {
180+
sorted[key] = sortAsarHeader((files as Record<string, unknown>)[key]);
181+
}
182+
obj['files'] = sorted;
183+
}
184+
return node;
185+
}

0 commit comments

Comments
 (0)