From 8a11043f374f96380e80ae1953ed25fd6a27d469 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 16 Oct 2023 08:35:48 -0700 Subject: [PATCH] Release build integration Summary: This is the immediate follow-up from the previous diff which aims to integrate the MacOS app into our release build script, meta only. Reviewed By: antonk52, aigoncharov Differential Revision: D50301369 fbshipit-source-id: 23a4842666c3a7aa9616c6237e16b71bae87ba36 --- .../scripts/build-flipper-server-release.tsx | 73 +++++++++++++++---- desktop/scripts/package.json | 1 + desktop/yarn.lock | 49 ++++++++++++- 3 files changed, 109 insertions(+), 14 deletions(-) diff --git a/desktop/scripts/build-flipper-server-release.tsx b/desktop/scripts/build-flipper-server-release.tsx index 673472f73..e31fe87d8 100644 --- a/desktop/scripts/build-flipper-server-release.tsx +++ b/desktop/scripts/build-flipper-server-release.tsx @@ -36,6 +36,7 @@ import {homedir} from 'os'; import {need as pkgFetch} from 'pkg-fetch'; import {exec} from 'child_process'; import fetch from '@adobe/node-fetch-retry'; +import plist from 'simple-plist'; // This needs to be tested individually. As of 2022Q2, node17 is not supported. const SUPPORTED_NODE_PLATFORM = 'node16'; @@ -458,11 +459,13 @@ async function buildServerRelease() { platforms.push(BuildPlatform.WINDOWS); } - await Promise.all( - platforms.map((platform) => - bundleServerReleaseForPlatform(dir, versionNumber, platform), - ), - ); + // Instead of parallel builds, these have to be done sequential. + // As we are building a native app, the resulting binary will be + // different per platform meaning that there's a risk of overriding + // intermediate artefacts if done in parallel. + for (const platform of platforms) { + await bundleServerReleaseForPlatform(dir, versionNumber, platform); + } } function nodeArchFromBuildPlatform(platform: BuildPlatform): string { @@ -653,9 +656,11 @@ async function installNodeBinary(outputPath: string, platform: BuildPlatform) { platform === BuildPlatform.MAC_X64 ) { if (process.platform === 'darwin') { - await setRuntimeAppIcon(outputPath); + await setRuntimeAppIcon(outputPath).catch(() => { + console.warn('⚠️ Unable to update runtime icon'); + }); } else { - console.warn("⚠️ Skipping icon update as it's only supported on macOS."); + console.warn("⚠️ Skipping icon update as it's only supported on macOS"); } } @@ -721,24 +726,62 @@ async function setUpWindowsBundle(outputDir: string) { async function setUpMacBundle( outputDir: string, + platform: BuildPlatform, versionNumber: string, ): Promise<{nodePath: string; resourcesPath: string}> { console.log(`⚙️ Creating Mac bundle in ${outputDir}`); - await fs.copy(path.join(staticDir, 'flipper-server-app-template'), outputDir); + + let appTemplate = path.join(staticDir, 'flipper-server-app-template'); + if (isFB) { + appTemplate = path.join( + staticDir, + 'facebook', + 'flipper-server-app-template', + platform, + ); + console.info('⚙️ Using internal template from: ' + appTemplate); + } + + await fs.copy(appTemplate, outputDir); + + function replacePropertyValue( + obj: any, + targetValue: string, + replacementValue: string, + ): any { + if (typeof obj === 'object' && !Array.isArray(obj) && obj !== null) { + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + obj[key] = replacePropertyValue( + obj[key], + targetValue, + replacementValue, + ); + } + } + } else if (typeof obj === 'string' && obj === targetValue) { + obj = replacementValue; + } + return obj; + } console.log(`⚙️ Writing plist`); - const pListPath = path.join( + const plistPath = path.join( outputDir, 'Flipper.app', 'Contents', 'Info.plist', ); - const pListContents = await fs.readFile(pListPath, 'utf-8'); - const updatedPlistContents = pListContents.replace( + + /* eslint-disable node/no-sync*/ + const pListContents: Record = plist.readFileSync(plistPath); + replacePropertyValue( + pListContents, '{flipper-server-version}', versionNumber, ); - await fs.writeFile(pListPath, updatedPlistContents, 'utf-8'); + plist.writeBinaryFileSync(plistPath, pListContents); + /* eslint-enable node/no-sync*/ const resourcesOutputDir = path.join( outputDir, @@ -747,6 +790,10 @@ async function setUpMacBundle( 'Resources', 'server', ); + + if (!(await fs.exists(resourcesOutputDir))) { + await fs.mkdir(resourcesOutputDir); + } const nodeOutputPath = path.join( outputDir, 'Flipper.app', @@ -780,7 +827,7 @@ async function bundleServerReleaseForPlatform( platform === BuildPlatform.MAC_X64 || platform === BuildPlatform.MAC_AARCH64 ) { - outputPaths = await setUpMacBundle(outputDir, versionNumber); + outputPaths = await setUpMacBundle(outputDir, platform, versionNumber); } else if (platform === BuildPlatform.LINUX) { await setUpLinuxBundle(outputDir); } else if (platform === BuildPlatform.WINDOWS) { diff --git a/desktop/scripts/package.json b/desktop/scripts/package.json index e57d2e733..4b9166b86 100644 --- a/desktop/scripts/package.json +++ b/desktop/scripts/package.json @@ -35,6 +35,7 @@ "pkg-fetch": "3.4.1", "promisify-child-process": "^4.1.0", "semver": "^7.5.4", + "simple-plist": "^1.3.1", "socket.io": "^4.5.0", "tar": "6.1.15", "tmp": "^0.2.1", diff --git a/desktop/yarn.lock b/desktop/yarn.lock index 52f5a990e..a9d3ac175 100644 --- a/desktop/yarn.lock +++ b/desktop/yarn.lock @@ -4781,6 +4781,11 @@ "@typescript-eslint/types" "5.55.0" eslint-visitor-keys "^3.3.0" +"@xmldom/xmldom@^0.8.8": + version "0.8.10" + resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.8.10.tgz#a1337ca426aa61cef9fe15b5b28e340a72f6fa99" + integrity sha512-2WALfTl4xo2SkGCYRt6rDTFfk9R1czmBvUQy12gK2KuRKIpWEhcbbzy8EZXtz/jkRqHX8bFEc6FC1HjX4TUWYw== + "@xobotyi/scrollbar-width@^1.9.5": version "1.9.5" resolved "https://registry.yarnpkg.com/@xobotyi/scrollbar-width/-/scrollbar-width-1.9.5.tgz#80224a6919272f405b87913ca13b92929bdf3c4d" @@ -5713,6 +5718,11 @@ base@^0.11.1: mixin-deep "^1.2.0" pascalcase "^0.1.1" +big-integer@1.6.x: + version "1.6.51" + resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.51.tgz#0df92a5d9880560d3ff2d5fd20245c889d130686" + integrity sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg== + bl@^1.0.0: version "1.2.3" resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.3.tgz#1e8dd80142eac80d7158c9dccc047fb620e035e7" @@ -5787,6 +5797,20 @@ boxen@^5.0.0: widest-line "^3.1.0" wrap-ansi "^7.0.0" +bplist-creator@0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/bplist-creator/-/bplist-creator-0.1.0.tgz#018a2d1b587f769e379ef5519103730f8963ba1e" + integrity sha512-sXaHZicyEEmY86WyueLTQesbeoH/mquvarJaQNbjuOQO+7gbFcDEWqKmcWA4cOTLzFlfgvkiVxolk1k5bBIpmg== + dependencies: + stream-buffers "2.2.x" + +bplist-parser@0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/bplist-parser/-/bplist-parser-0.3.1.tgz#e1c90b2ca2a9f9474cc72f6862bbf3fee8341fd1" + integrity sha512-PyJxiNtA5T2PlLIeBot4lbp7rj4OadzjnMZD/G5zuBNt8ei/yCU7+wW0h2bag9vr8c+/WuRWmSxbqAl9hL1rBA== + dependencies: + big-integer "1.6.x" + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -12527,6 +12551,15 @@ plist@^3.0.1, plist@^3.0.4: base64-js "^1.5.1" xmlbuilder "^9.0.7" +plist@^3.0.5: + version "3.1.0" + resolved "https://registry.yarnpkg.com/plist/-/plist-3.1.0.tgz#797a516a93e62f5bde55e0b9cc9c967f860893c9" + integrity sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ== + dependencies: + "@xmldom/xmldom" "^0.8.8" + base64-js "^1.5.1" + xmlbuilder "^15.1.1" + posix-character-classes@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" @@ -14289,6 +14322,15 @@ signal-exit@^3.0.3, signal-exit@^3.0.7: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +simple-plist@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/simple-plist/-/simple-plist-1.3.1.tgz#16e1d8f62c6c9b691b8383127663d834112fb017" + integrity sha512-iMSw5i0XseMnrhtIzRb7XpQEXepa9xhWxGUojHBL43SIpQuDQkh3Wpy67ZbDzZVr6EKxvwVChnVpdl8hEVLDiw== + dependencies: + bplist-creator "0.1.0" + bplist-parser "0.3.1" + plist "^3.0.5" + sisteransi@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" @@ -14581,6 +14623,11 @@ stop-iteration-iterator@^1.0.0: dependencies: internal-slot "^1.0.4" +stream-buffers@2.2.x: + version "2.2.0" + resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4" + integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg== + string-convert@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/string-convert/-/string-convert-0.2.1.tgz#6982cc3049fbb4cd85f8b24568b9d9bf39eeff97" @@ -15806,7 +15853,7 @@ xml-name-validator@^4.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835" integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw== -xmlbuilder@>=11.0.1: +xmlbuilder@>=11.0.1, xmlbuilder@^15.1.1: version "15.1.1" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-15.1.1.tgz#9dcdce49eea66d8d10b42cae94a79c3c8d0c2ec5" integrity sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==