diff options
Diffstat (limited to 'scripts/build-windows.ps1')
-rw-r--r-- | scripts/build-windows.ps1 | 155 |
1 files changed, 114 insertions, 41 deletions
diff --git a/scripts/build-windows.ps1 b/scripts/build-windows.ps1 index 9d4219ffb..3904c1bf9 100644 --- a/scripts/build-windows.ps1 +++ b/scripts/build-windows.ps1 | |||
@@ -1,45 +1,79 @@ | |||
1 | # INTRO: | 1 | # INTRO: |
2 | # This file is used to build ferdium on windows. | 2 | # This file is used to build ferdium on windows. |
3 | # It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning) | 3 | # It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning) |
4 | # It will install the system dependencies except for node (which is still verified) | 4 | # It will install the system dependencies except for node and python (which are still verified) |
5 | # I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed | 5 | # I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed independently |
6 | # This file can live anywhere in your PATH | 6 | # This file can live anywhere in your PATH |
7 | 7 | ||
8 | #CHECK PYTHON | ||
9 | #CHECK NODE.JS | ||
10 | #CHECK NPM | ||
11 | #CHECK MSVS_VERSION and MSVS Tools | ||
12 | |||
13 | $USERHOME = "${env:HOMEDRIVE}${env:HOMEPATH}" | 8 | $USERHOME = "${env:HOMEDRIVE}${env:HOMEPATH}" |
14 | 9 | ||
15 | $env:ELECTRON_CACHE = $USERHOME + '/.cache/electron' | 10 | $env:ELECTRON_CACHE = $USERHOME + '/.cache/electron' |
16 | $env:ELECTRON_BUILDER_CACHE = $USERHOME + '/.cache/electron-builder' | 11 | $env:ELECTRON_BUILDER_CACHE = $USERHOME + '/.cache/electron-builder' |
17 | $env:CSC_IDENTITY_AUTO_DISCOVERY = $false | 12 | $env:CSC_IDENTITY_AUTO_DISCOVERY = $false |
18 | |||
19 | $env:CI = $true | 13 | $env:CI = $true |
20 | 14 | ||
21 | $EXPECTED_NODE_VERSION = (Get-Content .\.nvmrc) | 15 | # ----------------------------------------------------------------------------- |
22 | $ACTUAL_NODE_VERSION = (node -v) | 16 | # Utility functions |
23 | 17 | ||
24 | if ( "v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) | 18 | Function fail_with_docs {Param ($1) |
25 | { | 19 | Write-Host "*************** FAILING ***************" |
26 | Write-Host "You are not running the expected version of node!" | 20 | Write-Host "$1" |
27 | Write-Host " expected: [v$EXPECTED_NODE_VERSION]" | 21 | Write-Host "" |
28 | Write-Host " actual : [$ACTUAL_NODE_VERSION]" | 22 | Write-Host "Please read the developer documentation in CONTRIBUTING.md" |
29 | exit 1 | 23 | exit 1 |
30 | } | 24 | } |
31 | 25 | ||
32 | if ( $env:CLEAN -eq "true" ) | 26 | Function Test-CommandExists { Param ($command, $1) |
27 | $oldPreference = $ErrorActionPreference | ||
28 | $ErrorActionPreference = "stop" | ||
29 | |||
30 | try { | ||
31 | if(Get-Command $command){RETURN} | ||
32 | } Catch { | ||
33 | fail_with_docs $1 | ||
34 | } | ||
35 | Finally {$ErrorActionPreference=$oldPreference} | ||
36 | } | ||
37 | |||
38 | # ----------------------------------------------------------------------------- | ||
39 | # Checking the developer environment | ||
40 | # Check for installed programmes | ||
41 | Test-CommandExists node "Node is not installed" | ||
42 | Test-CommandExists npm "npm is not installed" | ||
43 | Test-CommandExists python "Python is not installed" | ||
44 | # NEEDS proper way to CHECK MSVS Tools | ||
45 | |||
46 | # Check node version | ||
47 | $EXPECTED_NODE_VERSION = (cat .nvmrc) | ||
48 | $ACTUAL_NODE_VERSION = (node -v) | ||
49 | if ("v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) { | ||
50 | fail_with_docs "You are not running the expected version of node! | ||
51 | expected: [v$EXPECTED_NODE_VERSION] | ||
52 | actual : [$ACTUAL_NODE_VERSION]" | ||
53 | } | ||
54 | |||
55 | # Check if the 'recipes' folder is present either as a git submodule or a symbolic link | ||
56 | if (-not (Test-Path -Path "recipes/package.json" -PathType Leaf)) { | ||
57 | fail_with_docs "'recipes' folder is missing or submodule has not been checked out" | ||
58 | } | ||
59 | |||
60 | # This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule) | ||
61 | # TODO: Implement this | ||
62 | |||
63 | # ----------------------------------------------------------------------------- | ||
64 | # If you are moving to a new version of node or any other system dependency, then cleaning is recommended | ||
65 | # so that there's no irregular results due to cached modules | ||
66 | if ($env:CLEAN -eq "true") | ||
33 | { | 67 | { |
34 | $NPM_PATH = "$USERHOME\.npm" | 68 | $NPM_PATH = "$USERHOME\.npm" |
35 | $NODE_GYP = "$USERHOME\.node-gyp" | 69 | $NODE_GYP = "$USERHOME\.node-gyp" |
36 | 70 | ||
37 | Write-Host "Cleaning!" | 71 | Write-Host "Cleaning!" |
38 | npm cache clean --force | 72 | npm cache clean --force |
39 | Remove-Item -Path $NPM_PATH -Recurse | 73 | Remove-Item -Path $NPM_PATH -Recurse -ErrorAction SilentlyContinue |
40 | Remove-Item -Path $NODE_GYP -Recurse | 74 | Remove-Item -Path $NODE_GYP -Recurse -ErrorAction SilentlyContinue |
41 | 75 | ||
42 | if ( Test-Path -Path ".\pnpm-lock.yaml" -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) | 76 | if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) |
43 | { | 77 | { |
44 | $PNPM_STORE = "$USERHOME\.pnpm-store" | 78 | $PNPM_STORE = "$USERHOME\.pnpm-store" |
45 | $PNPM_STATE = "$USERHOME\.pnpm-state" | 79 | $PNPM_STATE = "$USERHOME\.pnpm-state" |
@@ -50,16 +84,54 @@ if ( $env:CLEAN -eq "true" ) | |||
50 | Remove-Item -Path $PNPM_STATE -Recurse | 84 | Remove-Item -Path $PNPM_STATE -Recurse |
51 | } | 85 | } |
52 | 86 | ||
53 | git -C recipes clean -fxd | 87 | git -C recipes clean -fxd # Clean recipes folder/submodule |
54 | git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it | 88 | git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it |
55 | } | 89 | } |
56 | 90 | ||
57 | # Ensure that the system dependencies are at the correct version | 91 | # ----------------------------------------------------------------------------- |
58 | npm i -gf npm@8.7.0 | 92 | # Ensure that the system dependencies are at the correct version - fail if not |
59 | npm i -gf pnpm@6.32.8 | 93 | # Check python version |
94 | $EXPECTED_PYTHON_VERSION = "3.10.4" | ||
95 | $ACTUAL_PYTHON_VERSION = (python --version).trim("Python ") | ||
96 | if ([System.Version]$ACTUAL_PYTHON_VERSION -le [System.Version]$EXPECTED_PYTHON_VERSION) { | ||
97 | fail_with_docs "You are not running the expected version of Python! | ||
98 | expected: [$EXPECTED_PYTHON_VERSION] | ||
99 | actual : [$ACTUAL_PYTHON_VERSION]" | ||
100 | } | ||
101 | |||
102 | # TODO: Needs proper way to check MSVS Tools | ||
103 | # Check MSVS Tools through MSVS_VERSION | ||
104 | $EXPECTED_MSVST_VERSION = "2015" | ||
105 | $ACTUAL_MSVST_VERSION = (npm config get msvs_version) | ||
106 | if ([double]$ACTUAL_MSVST_VERSION -le [double]$EXPECTED_MSVST_VERSION) { | ||
107 | fail_with_docs "You are not running the expected version of MSVS Tools! | ||
108 | expected: [$EXPECTED_MSVST_VERSION] | ||
109 | actual : [$ACTUAL_MSVST_VERSION]" | ||
110 | } | ||
111 | |||
112 | # ----------------------------------------------------------------------------- | ||
113 | # Ensure that the system dependencies are at the correct version - recover if not | ||
114 | # Check npm version | ||
115 | $EXPECTED_NPM_VERSION = (Get-Content package.json | ConvertFrom-Json).engines.npm | ||
116 | $ACTUAL_NPM_VERSION = (npm -v) | ||
117 | if ($EXPECTED_NPM_VERSION -ne $ACTUAL_NPM_VERSION) { | ||
118 | Write-Host "You are not running the expected version of npm! | ||
119 | expected: [$EXPECTED_NPM_VERSION] | ||
120 | actual : [$ACTUAL_NPM_VERSION]" | ||
121 | Write-Host "Changing version of npm to [$EXPECTED_NPM_VERSION]" | ||
122 | npm i -gf npm@$EXPECTED_NPM_VERSION | ||
123 | } | ||
60 | 124 | ||
125 | # Check pnpm version | ||
126 | $EXPECTED_PNPM_VERSION = (Get-Content recipes\package.json | ConvertFrom-Json).engines.pnpm | ||
127 | ACTUAL_PNPM_VERSION=$(pnpm --version) | ||
128 | if ($ACTUAL_PNPM_VERSION -ne $EXPECTED_PNPM_VERSION) { | ||
129 | npm i -gf pnpm@$EXPECTED_PNPM_VERSION | ||
130 | } | ||
131 | |||
132 | # ----------------------------------------------------------------------------- | ||
61 | # This is useful if we move from 'npm' to 'pnpm' for the main repo as well | 133 | # This is useful if we move from 'npm' to 'pnpm' for the main repo as well |
62 | if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) | 134 | if ((Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm)) |
63 | { | 135 | { |
64 | $BASE_CMD="pnpm" | 136 | $BASE_CMD="pnpm" |
65 | $env:EXEC_CMD="pnpm dlx" | 137 | $env:EXEC_CMD="pnpm dlx" |
@@ -74,27 +146,28 @@ else | |||
74 | & $BASE_CMD i | 146 | & $BASE_CMD i |
75 | & $BASE_CMD run prepare-code | 147 | & $BASE_CMD run prepare-code |
76 | 148 | ||
77 | # Check if the 'recipes' folder is present either as a git submodule or a symbolic link | 149 | # ----------------------------------------------------------------------------- |
78 | if (-not (Test-Path -Path ".\recipes\package.json")) | 150 | Write-Host "\n*************** Building recipes ***************\n" |
79 | { | ||
80 | try { | ||
81 | git submodule update --init --recursive --remote --rebase --force | ||
82 | } catch { | ||
83 | Write-Host "FAILING since 'recipes' folder/submodule has not been checked out" | ||
84 | exit 1 | ||
85 | } | ||
86 | } | ||
87 | |||
88 | # Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm | 151 | # Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm |
89 | Set-Location recipes | 152 | Push-Location recipes |
90 | pnpm i | 153 | pnpm i |
91 | pnpm run package | 154 | pnpm run package |
92 | Set-Location .. | 155 | Pop-Location |
93 | 156 | ||
157 | # ----------------------------------------------------------------------------- | ||
158 | Write-Host "\n*************** Building app ***************\n" | ||
94 | $TARGET_ARCH="x64" | 159 | $TARGET_ARCH="x64" |
95 | & $BASE_CMD run build -- --$TARGET_ARCH --dir | 160 | & $BASE_CMD run build -- --$TARGET_ARCH --dir |
96 | 161 | ||
162 | Write-Host "*************** App successfully built! ***************" | ||
163 | |||
97 | # Final check to ensure that the version built is the same as the latest commit | 164 | # Final check to ensure that the version built is the same as the latest commit |
98 | # TODO: Need to make this an assertion similar to tthe unix-equivalent | 165 | $VERSION_BUILT_HASH = (Get-Content "build/buildInfo.json" | ConvertFrom-Json).gitHashShort |
99 | Get-Content "build/buildInfo.json" | ConvertFrom-Json | 166 | $GIT_BUILT_HASH = (git rev-parse --short HEAD) |
100 | git log -1 | 167 | if ($VERSION_BUILT_HASH -ne $GIT_BUILT_HASH) |
168 | { | ||
169 | Write-Host "The built version is not on the latest commit!" | ||
170 | Write-Host " latest commit : [$GIT_BUILT_HASH]" | ||
171 | Write-Host " actual build : [$VERSION_BUILT_HASH]" | ||
172 | exit 1 | ||
173 | } | ||