|
| 1 | +#!/usr/bin/env perl |
| 2 | +# Patches absolute Windows paths in a Tauri-generated .nsi script so it can |
| 3 | +# be rebuilt on macOS/Linux with makensis. |
| 4 | +# |
| 5 | +# Usage: perl patch-nsis-paths.pl <installer.nsi> <local-artifact-root> |
| 6 | +# |
| 7 | +# The script extracts the CI checkout root from MAINBINARYSRCPATH, then |
| 8 | +# replaces all occurrences with the local artifact root, converting |
| 9 | +# backslashes to forward slashes. |
| 10 | + |
| 11 | +use strict; |
| 12 | +use warnings; |
| 13 | + |
| 14 | +my $nsi_file = $ARGV[0] or die "Usage: $0 <installer.nsi> <local-artifact-root>\n"; |
| 15 | +my $local_root = $ARGV[1] or die "Usage: $0 <installer.nsi> <local-artifact-root>\n"; |
| 16 | + |
| 17 | +open my $fh, '<', $nsi_file or die "Cannot open $nsi_file: $!"; |
| 18 | +my $content = do { local $/; <$fh> }; |
| 19 | +close $fh; |
| 20 | + |
| 21 | +# Extract CI checkout root from MAINBINARYSRCPATH. |
| 22 | +# The path looks like: "D:\a\mouseterm\mouseterm\standalone\src-tauri\target\...\mouseterm.exe" |
| 23 | +# We want everything before \standalone\src-tauri\ |
| 24 | +my $ci_root; |
| 25 | +if ($content =~ /MAINBINARYSRCPATH\s+"(.+?)\\standalone\\src-tauri\\/) { |
| 26 | + $ci_root = $1; |
| 27 | +} else { |
| 28 | + die "Could not extract CI checkout root from MAINBINARYSRCPATH in $nsi_file\n"; |
| 29 | +} |
| 30 | +print "CI checkout root: $ci_root\n"; |
| 31 | +print "Local artifact root: $local_root\n"; |
| 32 | + |
| 33 | +# Count occurrences before replacement |
| 34 | +my $count = 0; |
| 35 | +while ($content =~ /\Q$ci_root\E/g) { $count++ } |
| 36 | +print "Found $count path(s) to replace\n"; |
| 37 | + |
| 38 | +# Replace all occurrences of ci_root...<rest-of-path> with local_root/<rest>, |
| 39 | +# converting backslashes to forward slashes in the <rest> portion. |
| 40 | +$content =~ s/\Q$ci_root\E([^"]*)/ |
| 41 | + my $rest = $1; |
| 42 | + $rest =~ s{\\}{\/}g; |
| 43 | + "$local_root$rest" |
| 44 | +/ge; |
| 45 | + |
| 46 | +open my $out, '>', $nsi_file or die "Cannot write $nsi_file: $!"; |
| 47 | +print $out $content; |
| 48 | +close $out; |
| 49 | + |
| 50 | +print "Done. Patched $count path(s).\n"; |
0 commit comments