11package main
22
33import (
4+ "archive/zip"
5+ "bufio"
6+ "bytes"
47 "flag"
58 "io"
69 "os"
710 "os/exec"
811 "path/filepath"
12+ "runtime"
913 "strconv"
1014 "strings"
15+ "sync"
1116 "time"
1217
18+ "github.com/andybalholm/brotli"
1319 "github.com/kjk/common/u"
20+ "github.com/klauspost/compress/zstd"
21+ "github.com/ulikunitz/xz/lzma"
1422)
1523
1624var (
17- flgSkipSign bool
1825 r2Access string
1926 r2Secret string
2027 b2Access string
@@ -171,7 +178,6 @@ func runCppCheck(all bool) {
171178}
172179
173180type BuildOptions struct {
174- sign bool
175181 upload bool
176182 verifyTranslationUpToDate bool
177183 doCleanCheck bool
@@ -180,7 +186,6 @@ type BuildOptions struct {
180186
181187func ensureBuildOptionsPreRequesites (opts * BuildOptions ) {
182188 logf ("upload: %v\n " , opts .upload )
183- logf ("sign: %v\n " , opts .sign )
184189 logf ("verifyTranslationUpToDate: %v\n " , opts .verifyTranslationUpToDate )
185190
186191 if opts .upload {
@@ -197,10 +202,6 @@ func ensureBuildOptionsPreRequesites(opts *BuildOptions) {
197202 verifyOnReleaseBranchMust ()
198203 os .RemoveAll ("out" )
199204 }
200-
201- if ! opts .sign {
202- flgSkipSign = true
203- }
204205}
205206
206207func main () {
@@ -370,17 +371,13 @@ func main() {
370371 detectVersions ()
371372
372373 if false {
373- testGenUpdateTxt ()
374- return
375- }
376-
377- if false {
378- //buildPreRelease()
379- return
380- }
381-
382- if false {
383- deleteFilesOneOff ()
374+ testCompressOneOff ()
375+ if false {
376+ // make them reachable
377+ testGenUpdateTxt ()
378+ buildPreRelease (kPlatformIntel64 , true )
379+ deleteFilesOneOff ()
380+ }
384381 return
385382 }
386383
@@ -414,16 +411,8 @@ func main() {
414411
415412 opts := & BuildOptions {}
416413
417- if flgCIBuild {
418- // triggered via -ci from .github workflow file
419- // only sign if this is my repo (not a fork)
420- // master branch (not work branches) and on push (not pull requests etc.)
421- opts .sign = isGithubMyMasterBranch ()
422- }
423-
424414 if flgUpload {
425415 // given by me from cmd-line
426- opts .sign = true
427416 opts .upload = true
428417 }
429418
@@ -610,3 +599,141 @@ func printBuildNoInfo(buildNo int) {
610599 s := lines [n ]
611600 logf ("%d: %s\n " , buildNo , s )
612601}
602+
603+ func compressFileWithBrMust (path string ) []byte {
604+ buf := bytes.Buffer {}
605+ w := brotli .NewWriterLevel (& buf , brotli .BestCompression )
606+ f := u .Must2 (os .Open (path ))
607+ u .Must2 (io .Copy (w , f ))
608+ must (f .Close ())
609+ must (w .Close ())
610+ return buf .Bytes ()
611+ }
612+
613+ func compressWithZstdMust (path string ) []byte {
614+ buf := bytes.Buffer {}
615+ w := u .Must2 (zstd .NewWriter (& buf , zstd .WithEncoderLevel (zstd .SpeedBestCompression )))
616+ f := u .Must2 (os .Open (path ))
617+ u .Must2 (io .Copy (w , f ))
618+ must (f .Close ())
619+ must (w .Close ())
620+ return buf .Bytes ()
621+ }
622+
623+ func compressWithLzma2Must (path string ) []byte {
624+ buf := bytes.Buffer {}
625+ bw := bufio .NewWriter (& buf )
626+ w := u .Must2 (lzma .NewWriter2 (bw ))
627+ f := u .Must2 (os .Open (path ))
628+ u .Must2 (io .Copy (w , f ))
629+ must (f .Close ())
630+ must (w .Close ())
631+ must (bw .Flush ())
632+ return buf .Bytes ()
633+ }
634+
635+ func compressWithLzma2BetterMust (path string ) []byte {
636+ buf := bytes.Buffer {}
637+ bw := bufio .NewWriter (& buf )
638+ var c lzma.Writer2Config
639+ c .DictCap = (8 * 1024 * 1024 ) * 16
640+ must (c .Verify ())
641+ w := u .Must2 (c .NewWriter2 (bw ))
642+ f := u .Must2 (os .Open (path ))
643+ u .Must2 (io .Copy (w , f ))
644+ must (f .Close ())
645+ must (w .Close ())
646+ must (bw .Flush ())
647+ return buf .Bytes ()
648+ }
649+
650+ func creaZipWithCompressFunction (zipPath string , files []string , dir string , compressFunc func (string ) []byte , comprSuffix string ) {
651+ os .Remove (zipPath )
652+ w := u .Must2 (os .Create (zipPath ))
653+ zw := zip .NewWriter (w )
654+ defer zw .Close ()
655+ var wg sync.WaitGroup
656+ nConcurrent := runtime .NumCPU ()
657+ sem := make (chan bool , nConcurrent )
658+ for _ , f := range files {
659+ path := filepath .Join (dir , f )
660+ wg .Add (1 )
661+ sem <- true
662+ go func () {
663+ data := compressFunc (path )
664+ addZipDataStoreMust (zw , data , f + comprSuffix )
665+ <- sem
666+ wg .Done ()
667+ }()
668+ }
669+ wg .Wait ()
670+ must (zw .Close ())
671+ }
672+
673+ func testCompressOneOff () {
674+ dir := filepath .Join ("out" , "rel64" )
675+ files := []string {"SumatraPDF.exe" , "SumatraPDF-dll.exe" , "libmupdf.pdb" , "SumatraPDF.pdb" , "SumatraPDF-dll.pdb" }
676+ {
677+ }
678+ origSize := int64 (0 )
679+ for _ , f := range files {
680+ origSize += u .FileSize (filepath .Join (dir , f ))
681+ }
682+ logf ("origSize: %s\n " , u .FormatSize (origSize ))
683+
684+ {
685+ archivePath := filepath .Join (dir , "rel64.lzma2.better.zip" )
686+ os .Remove (archivePath )
687+ logf ("\n Creating %s (%d threads)\n " , archivePath , runtime .NumCPU ())
688+ printDur := measureDuration ()
689+ creaZipWithCompressFunction (archivePath , files , dir , compressWithLzma2BetterMust , ".lzma2" )
690+ printDur ()
691+ compressedSize := u .FileSize (archivePath )
692+ ratio := float64 (origSize ) / float64 (compressedSize )
693+ logf ("compressedSize: %s, ratio: %.2f\n " , u .FormatSize (compressedSize ), ratio )
694+ }
695+ {
696+ archivePath := filepath .Join (dir , "rel64.lzma2.zip" )
697+ os .Remove (archivePath )
698+ logf ("\n Creating %s (%d threads)\n " , archivePath , runtime .NumCPU ())
699+ printDur := measureDuration ()
700+ creaZipWithCompressFunction (archivePath , files , dir , compressWithLzma2Must , ".lzma2" )
701+ printDur ()
702+ compressedSize := u .FileSize (archivePath )
703+ ratio := float64 (origSize ) / float64 (compressedSize )
704+ logf ("compressedSize: %s, ratio: %.2f\n " , u .FormatSize (compressedSize ), ratio )
705+ }
706+ {
707+ archivePath := filepath .Join (dir , "rel64.br.zip" )
708+ os .Remove (archivePath )
709+ logf ("\n Creating %s (%d threads)\n " , archivePath , runtime .NumCPU ())
710+ printDur := measureDuration ()
711+ creaZipWithCompressFunction (archivePath , files , dir , compressFileWithBrMust , ".br" )
712+ printDur ()
713+ compressedSize := u .FileSize (archivePath )
714+ ratio := float64 (origSize ) / float64 (compressedSize )
715+ logf ("compressedSize: %s, ratio: %.2f\n " , u .FormatSize (compressedSize ), ratio )
716+ }
717+ {
718+ archivePath := filepath .Join (dir , "rel64.zstd.zip" )
719+ os .Remove (archivePath )
720+ logf ("\n Creating %s (%d threads)\n " , archivePath , runtime .NumCPU ())
721+ printDur := measureDuration ()
722+ creaZipWithCompressFunction (archivePath , files , dir , compressWithZstdMust , ".zstd" )
723+ printDur ()
724+ compressedSize := u .FileSize (archivePath )
725+ ratio := float64 (origSize ) / float64 (compressedSize )
726+ logf ("compressedSize: %s, ratio: %.2f\n " , u .FormatSize (compressedSize ), ratio )
727+ }
728+ {
729+ logf ("\n Creating rel64.lzsa using\n " )
730+ printDur := measureDuration ()
731+ archivePath := filepath .Join (dir , "rel64.lzsa" )
732+ os .Remove (archivePath )
733+ createLzsaFromFiles ("rel64.lzsa" , files , dir )
734+ printDur ()
735+ compressedSize := u .FileSize (archivePath )
736+ ratio := float64 (origSize ) / float64 (compressedSize )
737+ logf ("compressedSize: %s, ratio: %.2f\n " , u .FormatSize (compressedSize ), ratio )
738+ }
739+ }
0 commit comments