55
66import fs from 'fs' ;
77import path from 'path' ;
8- import codesign from 'electron- osx-sign' ;
8+ import { sign , SignOptions } from '@ electron/ osx-sign' ;
99import { spawn } from '@malept/cross-spawn-promise' ;
1010
1111const root = path . dirname ( path . dirname ( __dirname ) ) ;
12+ const baseDir = path . dirname ( __dirname ) ;
13+ const product = JSON . parse ( fs . readFileSync ( path . join ( root , 'product.json' ) , 'utf8' ) ) ;
14+ const helperAppBaseName = product . nameShort ;
15+ const gpuHelperAppName = helperAppBaseName + ' Helper (GPU).app' ;
16+ const rendererHelperAppName = helperAppBaseName + ' Helper (Renderer).app' ;
17+ const pluginHelperAppName = helperAppBaseName + ' Helper (Plugin).app' ;
1218
1319function getElectronVersion ( ) : string {
1420 const npmrc = fs . readFileSync ( path . join ( root , '.npmrc' ) , 'utf8' ) ;
1521 const target = / ^ t a r g e t = " ( .* ) " $ / m. exec ( npmrc ) ! [ 1 ] ;
1622 return target ;
1723}
1824
25+ function getEntitlementsForFile ( filePath : string ) : string {
26+ if ( filePath . includes ( gpuHelperAppName ) ) {
27+ return path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-gpu-entitlements.plist' ) ;
28+ } else if ( filePath . includes ( rendererHelperAppName ) ) {
29+ return path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-renderer-entitlements.plist' ) ;
30+ } else if ( filePath . includes ( pluginHelperAppName ) ) {
31+ return path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-plugin-entitlements.plist' ) ;
32+ }
33+ return path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'app-entitlements.plist' ) ;
34+ }
35+
1936async function main ( buildDir ?: string ) : Promise < void > {
2037 const tempDir = process . env [ 'AGENT_TEMPDIRECTORY' ] ;
2138 const arch = process . env [ 'VSCODE_ARCH' ] ;
@@ -29,60 +46,22 @@ async function main(buildDir?: string): Promise<void> {
2946 throw new Error ( '$AGENT_TEMPDIRECTORY not set' ) ;
3047 }
3148
32- const product = JSON . parse ( fs . readFileSync ( path . join ( root , 'product.json' ) , 'utf8' ) ) ;
33- const baseDir = path . dirname ( __dirname ) ;
3449 const appRoot = path . join ( buildDir , `VSCode-darwin-${ arch } ` ) ;
3550 const appName = product . nameLong + '.app' ;
36- const appFrameworkPath = path . join ( appRoot , appName , 'Contents' , 'Frameworks' ) ;
37- const helperAppBaseName = product . nameShort ;
38- const gpuHelperAppName = helperAppBaseName + ' Helper (GPU).app' ;
39- const rendererHelperAppName = helperAppBaseName + ' Helper (Renderer).app' ;
40- const pluginHelperAppName = helperAppBaseName + ' Helper (Plugin).app' ;
4151 const infoPlistPath = path . resolve ( appRoot , appName , 'Contents' , 'Info.plist' ) ;
4252
43- const defaultOpts : codesign . SignOptions = {
53+ const appOpts : SignOptions = {
4454 app : path . join ( appRoot , appName ) ,
4555 platform : 'darwin' ,
46- entitlements : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'app-entitlements.plist' ) ,
47- 'entitlements-inherit' : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'app-entitlements.plist' ) ,
48- hardenedRuntime : true ,
49- 'pre-auto-entitlements' : false ,
50- 'pre-embed-provisioning-profile' : false ,
56+ optionsForFile : ( filePath ) => ( {
57+ entitlements : getEntitlementsForFile ( filePath ) ,
58+ hardenedRuntime : true ,
59+ } ) ,
60+ preAutoEntitlements : false ,
61+ preEmbedProvisioningProfile : false ,
5162 keychain : path . join ( tempDir , 'buildagent.keychain' ) ,
5263 version : getElectronVersion ( ) ,
5364 identity,
54- 'gatekeeper-assess' : false
55- } ;
56-
57- const appOpts = {
58- ...defaultOpts ,
59- // TODO(deepak1556): Incorrectly declared type in electron-osx-sign
60- ignore : ( filePath : string ) => {
61- return filePath . includes ( gpuHelperAppName ) ||
62- filePath . includes ( rendererHelperAppName ) ||
63- filePath . includes ( pluginHelperAppName ) ;
64- }
65- } ;
66-
67- const gpuHelperOpts : codesign . SignOptions = {
68- ...defaultOpts ,
69- app : path . join ( appFrameworkPath , gpuHelperAppName ) ,
70- entitlements : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-gpu-entitlements.plist' ) ,
71- 'entitlements-inherit' : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-gpu-entitlements.plist' ) ,
72- } ;
73-
74- const rendererHelperOpts : codesign . SignOptions = {
75- ...defaultOpts ,
76- app : path . join ( appFrameworkPath , rendererHelperAppName ) ,
77- entitlements : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-renderer-entitlements.plist' ) ,
78- 'entitlements-inherit' : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-renderer-entitlements.plist' ) ,
79- } ;
80-
81- const pluginHelperOpts : codesign . SignOptions = {
82- ...defaultOpts ,
83- app : path . join ( appFrameworkPath , pluginHelperAppName ) ,
84- entitlements : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-plugin-entitlements.plist' ) ,
85- 'entitlements-inherit' : path . join ( baseDir , 'azure-pipelines' , 'darwin' , 'helper-plugin-entitlements.plist' ) ,
8665 } ;
8766
8867 // Only overwrite plist entries for x64 and arm64 builds,
@@ -111,10 +90,7 @@ async function main(buildDir?: string): Promise<void> {
11190 ] ) ;
11291 }
11392
114- await codesign . signAsync ( gpuHelperOpts ) ;
115- await codesign . signAsync ( rendererHelperOpts ) ;
116- await codesign . signAsync ( pluginHelperOpts ) ;
117- await codesign . signAsync ( appOpts as any ) ;
93+ await sign ( appOpts ) ;
11894}
11995
12096if ( require . main === module ) {
0 commit comments