From 7c8097dbbfcb9c102a0d3cf014f4ac9b7cfaa0da Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 5 Jul 2024 20:06:43 +0200 Subject: [PATCH] build - reuse the same `date` across builds (#220076) --- build/gulpfile.cli.js | 3 --- build/gulpfile.compile.js | 6 ++++++ build/gulpfile.reh.js | 4 ++-- build/gulpfile.vscode.js | 4 ++-- build/gulpfile.vscode.web.js | 4 ++-- build/lib/date.js | 38 ++++++++++++++++++++-------------- build/lib/date.ts | 40 +++++++++++++++++++++--------------- 7 files changed, 59 insertions(+), 40 deletions(-) diff --git a/build/gulpfile.cli.js b/build/gulpfile.cli.js index 86646fdb274..592fc74516c 100644 --- a/build/gulpfile.cli.js +++ b/build/gulpfile.cli.js @@ -5,8 +5,6 @@ 'use strict'; -//@ts-check - const es = require('event-stream'); const gulp = require('gulp'); const path = require('path'); @@ -24,7 +22,6 @@ const createReporter = require('./lib/reporter').createReporter; const root = 'cli'; const rootAbs = path.resolve(__dirname, '..', root); const src = `${root}/src`; -const targetCliPath = path.join(root, 'target', 'debug', process.platform === 'win32' ? 'code.exe' : 'code'); const platformOpensslDirName = process.platform === 'win32' ? ( diff --git a/build/gulpfile.compile.js b/build/gulpfile.compile.js index c4947e76cbf..de8f3c4fb57 100644 --- a/build/gulpfile.compile.js +++ b/build/gulpfile.compile.js @@ -3,18 +3,24 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +//@ts-check 'use strict'; const gulp = require('gulp'); const util = require('./lib/util'); +const date = require('./lib/date'); const task = require('./lib/task'); const compilation = require('./lib/compilation'); const optimize = require('./lib/optimize'); +/** + * @param {boolean} disableMangle + */ function makeCompileBuildTask(disableMangle) { return task.series( util.rimraf('out-build'), util.buildWebNodePaths('out-build'), + date.writeISODate('out-build'), compilation.compileApiProposalNamesTask, compilation.compileTask('src', 'out-build', true, { disableMangle }), optimize.optimizeLoaderTask('out-build', 'out-build', true) diff --git a/build/gulpfile.reh.js b/build/gulpfile.reh.js index 07bf9ff825f..d7a814b9a1b 100644 --- a/build/gulpfile.reh.js +++ b/build/gulpfile.reh.js @@ -18,7 +18,7 @@ const rename = require('gulp-rename'); const replace = require('gulp-replace'); const filter = require('gulp-filter'); const { getProductionDependencies } = require('./lib/dependencies'); -const { date } = require('./lib/date'); +const { readISODate } = require('./lib/date'); const vfs = require('vinyl-fs'); const packageJson = require('../package.json'); const flatmap = require('gulp-flatmap'); @@ -301,7 +301,7 @@ function packageTask(type, platform, arch, sourceFolderName, destinationFolderNa let productJsonContents; const productJsonStream = gulp.src(['product.json'], { base: '.' }) - .pipe(json({ commit, date, version })) + .pipe(json({ commit, date: readISODate('out-build'), version })) .pipe(es.through(function (file) { productJsonContents = file.contents.toString(); this.emit('data', file); diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index 8923954e12e..b3b35466af0 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -15,7 +15,7 @@ const replace = require('gulp-replace'); const filter = require('gulp-filter'); const util = require('./lib/util'); const { getVersion } = require('./lib/getVersion'); -const { date } = require('./lib/date'); +const { readISODate } = require('./lib/date'); const task = require('./lib/task'); const buildfile = require('../src/buildfile'); const optimize = require('./lib/optimize'); @@ -259,7 +259,7 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op let productJsonContents; const productJsonStream = gulp.src(['product.json'], { base: '.' }) - .pipe(json({ commit, date, checksums, version })) + .pipe(json({ commit, date: readISODate('out-build'), checksums, version })) .pipe(es.through(function (file) { productJsonContents = file.contents.toString(); this.emit('data', file); diff --git a/build/gulpfile.vscode.web.js b/build/gulpfile.vscode.web.js index ad01b6cfb42..0424b12fa45 100644 --- a/build/gulpfile.vscode.web.js +++ b/build/gulpfile.vscode.web.js @@ -12,7 +12,7 @@ const util = require('./lib/util'); const { getVersion } = require('./lib/getVersion'); const task = require('./lib/task'); const optimize = require('./lib/optimize'); -const { date } = require('./lib/date'); +const { readISODate } = require('./lib/date'); const product = require('../product.json'); const rename = require('gulp-rename'); const filter = require('gulp-filter'); @@ -94,7 +94,7 @@ const createVSCodeWebProductConfigurationPatcher = (product) => { ...product, version, commit, - date + date: readISODate('out-build') }); return content.replace('/*BUILD->INSERT_PRODUCT_CONFIGURATION*/', () => productConfiguration.substr(1, productConfiguration.length - 2) /* without { and }*/); } diff --git a/build/lib/date.js b/build/lib/date.js index a3e2554c016..77fff0e5073 100644 --- a/build/lib/date.js +++ b/build/lib/date.js @@ -4,21 +4,29 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); -exports.date = void 0; -function getRoundedBuildDate() { - const now = new Date(); - const minutes = now.getMinutes(); - if (minutes >= 30) { - now.setHours(now.getHours() + 1); - } - now.setMinutes(0, 0, 0); - return now; -} +exports.writeISODate = writeISODate; +exports.readISODate = readISODate; +const path = require("path"); +const fs = require("fs"); +const root = path.join(__dirname, '..', '..'); /** - * An attempt to produce a stable date for the build that can be - * used across processes and build steps that run in parallel almost - * at the same time. The current time is rounded up or down to the - * closest hour. + * Writes a `outDir/date` file with the contents of the build + * so that other tasks during the build process can use it and + * all use the same date. */ -exports.date = getRoundedBuildDate().toISOString(); +function writeISODate(outDir) { + const result = () => new Promise((resolve, _) => { + const outDirectory = path.join(root, outDir); + fs.mkdirSync(outDirectory, { recursive: true }); + const date = new Date().toISOString(); + fs.writeFileSync(path.join(outDirectory, 'date'), date, 'utf8'); + resolve(); + }); + result.taskName = 'build-date-file'; + return result; +} +function readISODate(outDir) { + const outDirectory = path.join(root, outDir); + return fs.readFileSync(path.join(outDirectory, 'date'), 'utf8'); +} //# sourceMappingURL=date.js.map \ No newline at end of file diff --git a/build/lib/date.ts b/build/lib/date.ts index a68a4caf3df..998e89f8e6a 100644 --- a/build/lib/date.ts +++ b/build/lib/date.ts @@ -3,23 +3,31 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -function getRoundedBuildDate() { - const now = new Date(); +import * as path from 'path'; +import * as fs from 'fs'; - const minutes = now.getMinutes(); - if (minutes >= 30) { - now.setHours(now.getHours() + 1); - } - - now.setMinutes(0, 0, 0); - - return now; -} +const root = path.join(__dirname, '..', '..'); /** - * An attempt to produce a stable date for the build that can be - * used across processes and build steps that run in parallel almost - * at the same time. The current time is rounded up or down to the - * closest hour. + * Writes a `outDir/date` file with the contents of the build + * so that other tasks during the build process can use it and + * all use the same date. */ -export const date = getRoundedBuildDate().toISOString(); +export function writeISODate(outDir: string) { + const result = () => new Promise((resolve, _) => { + const outDirectory = path.join(root, outDir); + fs.mkdirSync(outDirectory, { recursive: true }); + + const date = new Date().toISOString(); + fs.writeFileSync(path.join(outDirectory, 'date'), date, 'utf8'); + + resolve(); + }); + result.taskName = 'build-date-file'; + return result; +} + +export function readISODate(outDir: string): string { + const outDirectory = path.join(root, outDir); + return fs.readFileSync(path.join(outDirectory, 'date'), 'utf8'); +}