Skip to content

Commit

Permalink
Merge remote-tracking branch 'nihonium-gl/fxcode-update-1.63.1' into …
Browse files Browse the repository at this point in the history
…master-pub
  • Loading branch information
blattersturm committed Dec 16, 2021
2 parents a8628c8 + 234012e commit 1069d71
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
22 changes: 13 additions & 9 deletions code/tools/ci/build_sdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function End-Section
$ErrorActionPreference = "Stop"
$SaveDir = "C:\f\save"

$FXCodeSubmoduleName = "ext/sdk/resources/sdk-root/fxcode"
$FXCodeSubmodulePath = "$WorkDir\ext\sdk\resources\sdk-root\fxcode"
$LastFXCodeCommitPath = "$SaveDir\.fxcodecommit"
$LastFXCodeCommit = ""

Expand Down Expand Up @@ -47,13 +47,6 @@ Push-Location $WorkDir
$SubModules = git submodule | ForEach-Object { New-Object PSObject -Property @{ Hash = $_.Substring(1).Split(' ')[0]; Name = $_.Substring(1).Split(' ')[1] } }

foreach ($submodule in $SubModules) {
if ($submodule.Name -eq $FXCodeSubmoduleName) {
if ($submodule.Hash -ne $LastFXCodeCommit) {
$ShouldBuildFXCode = $true
$submodule.Hash | Out-File -Encoding ascii -NoNewline $LastFXCodeCommitPath
}
}

$SubmodulePath = git config -f .gitmodules --get "submodule.$($submodule.Name).path"

if ((Test-Path $SubmodulePath) -and (Get-ChildItem $SubmodulePath).Length -gt 0) {
Expand Down Expand Up @@ -83,11 +76,22 @@ Pop-Location

End-Section "update_submodules"

# Check if FXCode needs building
Push-Location $FXCodeSubmodulePath
$FXCodeSubmoduleCommit = git rev-parse HEAD

if ($FXCodeSubmoduleCommit -ne $LastFXCodeCommit) {
$LastFXCodeCommit = $FXCodeSubmoduleCommit
$ShouldBuildFXCode = $true
$LastFXCodeCommit | Out-File -Encoding ascii -NoNewline $LastFXCodeCommitPath
}
Pop-Location

# start building SDK
# copied from run_postbuild.ps1
Push-Location $WorkDir\ext\sdk-build
if (!(Test-Path sdk-root\.commit) -or $SDKCommit -ne (Get-Content sdk-root\.commit)) {
.\build.cmd --build-fxcode=$ShouldBuildFXCode
.\build.cmd --build-fxcode=$ShouldBuildFXCode --fxcode-commit=$LastFXCodeCommit
if (!$?) {
throw "Build failed!";
}
Expand Down
14 changes: 13 additions & 1 deletion ext/sdk-build/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const path = require('path');
const { Color, getArg, exec, printError, logPrefix, pathExists, rmdir, yarn, del, print, xcopy, move } = require('./utils');
const { Color, getArg, exec, printError, logPrefix, pathExists, rmdir, yarn, del, print, xcopy, move, rewriteFile } = require('./utils');

const ShouldBuildFXCode = (getArg('--build-fxcode') || '').toLowerCase() === 'true';
const FXCodeCommitHash = getArg('--fxcode-commit') || 'unknown';

const SevenZip = path.join(__dirname, '../../code/tools/ci/7z');

Expand Down Expand Up @@ -80,6 +81,17 @@ async function buildFXCode() {
await yarn(name, cwd, 'install', '--frozen-lockfile');
await yarn(name, cwd, 'rebuild-native-modules');
await yarn(name, cwd, 'build');

// Writing date and commit hash
function rewriter(content) {
return content
.replaceAll('@@COMMIT@@', FXCodeCommitHash)
.replaceAll('@@DATE@@', new Date().toISOString());
}

print(name, 'Writing variables');
await rewriteFile(path.join(FXCode, 'out-fxdk-pkg/out/vs/fxdk/browser/workbench/workbench.js'), rewriter);
print(name, 'Done writing variables');
}

async function packFXCode() {
Expand Down
24 changes: 24 additions & 0 deletions ext/sdk-build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ async function pathExists(cwd, ...args) {
}
}

async function statSafe(cwd, ...args) {
try {
return await fs.promises.stat(path.join(cwd, ...args));
} catch (e) {
return null;
}
}

function rmdir(name, cwd, dirPath) {
return exec({
name,
Expand Down Expand Up @@ -147,6 +155,21 @@ function move(name, from, to) {
});
}

async function rewriteFile(filePath, rewriter) {
const fileStat = await statSafe(filePath);

if (!fileStat) {
throw new Error(`Failed to rewrite ${filePath}, file does not exist`);
}
if (fileStat.isDirectory()) {
throw new Error(`Failed to rewrite ${filePath}, not a file`);
}

const content = (await fs.promises.readFile(filePath)).toString();

await fs.promises.writeFile(filePath, rewriter(content));
}

module.exports = {
Color,
print,
Expand All @@ -161,4 +184,5 @@ module.exports = {
yarn,
xcopy,
move,
rewriteFile,
};
2 changes: 1 addition & 1 deletion ext/sdk/resources/sdk-root/fxcode
Submodule fxcode updated 1448 files

0 comments on commit 1069d71

Please sign in to comment.