@@ -4,7 +4,7 @@ set -Eeuo pipefail
44
55function unapply_patches() {
66 local -i exit_code=0
7- quiet quilt pop -af || exit_code=$?
7+ quiet quilt pop -af 2>&1 || exit_code=$?
88 case $exit_code in
99 # Sucessfully unapplied.
1010 0) ;;
@@ -15,6 +15,19 @@ function unapply_patches() {
1515 esac
1616}
1717
18+ function apply_patches() {
19+ local -i exit_code=0
20+ quiet quilt push -a 2>&1 || exit_code=$?
21+ case $exit_code in
22+ # Sucessfully applied.
23+ 0) ;;
24+ # No more patches to apply.
25+ 2) ;;
26+ # Some error.
27+ * ) return $exit_code ;;
28+ esac
29+ }
30+
1831function update_vscode() {
1932 pushd lib/vscode
2033 if ! git checkout 2>&1 " $target_vscode_version " ; then
@@ -28,8 +41,8 @@ function update_vscode() {
2841
2942function refresh_patches() {
3043 local -i exit_code=0
31- while quiet quilt push ; ! (( exit_code= $? )) ; do
32- quilt refresh
44+ while quiet quilt push 2>&1 ; ! (( exit_code= $? )) ; do
45+ quilt refresh 2>&1
3346 done
3447 case $exit_code in
3548 # No more patches to apply.
@@ -56,50 +69,41 @@ function get-webview-script-hash() {
5669 local html
5770 html=$( < " $1 " )
5871 local start_tag=' <script async type="module">'
72+ if [[ $file == * /webWorkerExtensionHostIframe.html ]] ; then
73+ start_tag=' <script>'
74+ fi
5975 local end_tag=" </script>"
6076 html=${html##* " $start_tag " }
6177 html=${html%% " $end_tag " * }
6278 echo -n " $html " | openssl sha256 -binary | openssl base64
6379}
6480
81+ function delete_csp() {
82+ quilt delete csp-hashes.diff
83+ }
84+
6585function update_csp() {
66- local current
67- current=$( quilt top 2> /dev/null || echo " " )
68- local patch_action=" "
69- echo " Currently at ${current:- base} "
70- if [[ $current != * /webview.diff ]] ; then
71- echo " Moving to patches/webview.diff..."
72- local -i exit_code=0
73- if quilt applied 2> /dev/null | grep --quiet webview.diff ; then
74- quiet quilt pop webview || exit_code=$?
75- patch_action=pop
76- else
77- quiet quilt push webview || exit_code=$?
78- patch_action=push
79- fi
80- case $exit_code in
81- # Successfully moved.
82- 0) ;;
83- # Some error.
84- * ) return $exit_code ;;
85- esac
86- fi
86+ apply_patches
8787
88- local file=lib/vscode/src/vs/workbench/contrib/webview/browser/pre/index.html
89- local hash
90- hash=$( get-webview-script-hash " $file " )
91- echo " Calculated hash as $hash "
92- # Use octothorpe as a delimiter since the hash may contain a slash.
93- sed -i.bak " s#script-src 'sha256-[^']\+'#script-src 'sha256-$hash '#" " $file "
94- quilt refresh
88+ local files=(
89+ ./lib/vscode/src/vs/workbench/contrib/webview/browser/pre/index.html
90+ ./lib/vscode/src/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html
91+ )
9592
96- if [[ $patch_action != " " ]] ; then
97- echo " Moving back to ${current:- base} ..."
98- case $patch_action in
99- pop) quiet quilt push " $current " ;;
100- push) quiet quilt pop " ${current:- -a} " ;;
101- esac
102- fi
93+ quilt new csp-hashes.diff
94+
95+ local file
96+ for file in " ${files[@]} " ; do
97+ quilt add " $file "
98+
99+ local hash
100+ hash=$( get-webview-script-hash " $file " )
101+ echo " Calculated hash as $hash "
102+ # Use octothorpe as a delimiter since the hash may contain a slash.
103+ sed -i.bak " s#'sha256-[^']\+'#'sha256-$hash '#" " $file "
104+ done
105+
106+ quilt refresh
103107}
104108
105109function add_changelog() {
@@ -120,6 +124,9 @@ function main() {
120124
121125 declare -a steps
122126
127+ # Hashes are always regenerated to avoid having to resolve conflicts..
128+ steps+=(" Revert CSP hashes" " delete_csp" )
129+
123130 # If version is not set, assume we are already at the target version and the
124131 # user is just trying to resolve conflics.
125132 local target_vscode_version
@@ -141,7 +148,7 @@ function main() {
141148
142149 steps+=(
143150 " Update Node version" " update_node"
144- " Update CSP webview hash " " update_csp"
151+ " Regenerate CSP hashes " " update_csp"
145152 " Add changelog note" " add_changelog"
146153 )
147154
0 commit comments