diff --git a/do/build.go b/do/build.go index b1d43cc3443..00fd8fea1b7 100644 --- a/do/build.go +++ b/do/build.go @@ -191,9 +191,10 @@ func buildLzsa() { msbuildPath := detectMsbuildPathMust() runExeLoggedMust(msbuildPath, `vs2022\MakeLZSA.sln`, `/t:MakeLZSA:Rebuild`, `/p:Configuration=Release;Platform=Win32`, `/m`) - path := filepath.Join("out", "rel32", "MakeLZSA.exe") - signMust(path) - logf("build and signed '%s'\n", path) + dir := filepath.Join("out", "rel32") + files := []string{"MakeLZSA.exe"} + signFilesMust(dir, files) + logf("built and signed '%s'\n", filepath.Join(dir, files[0])) } func buildConfigPath() string { @@ -414,23 +415,6 @@ func createManifestMust() { // } // } -func signFilesMust(dir string) { - if true { - logf("signFilesMust: '%s' DISABLED\n", dir) - return - } - logf("signFilesMust: '%s'\n", dir) - //listFilesInDir(dir) - - if fileExists(filepath.Join(dir, "SumatraPDF.exe")) { - signMust(filepath.Join(dir, "SumatraPDF.exe")) - } - signMust(filepath.Join(dir, "libmupdf.dll")) - signMust(filepath.Join(dir, "PdfFilter.dll")) - signMust(filepath.Join(dir, "PdfPreview.dll")) - signMust(filepath.Join(dir, "SumatraPDF-dll.exe")) -} - const ( kPlatformIntel32 = "Win32" kPlatformIntel64 = "x64" @@ -556,7 +540,7 @@ func buildCi() { // code ql is just a regular build, I assume intercepted by // by their tooling // buildSmoke() runs genHTMLDocsForApp() so no need to do it here - buildSmoke() + buildSmoke(false) default: panic("unkown value from getGitHubEventType()") } @@ -662,7 +646,7 @@ func buildCodeQL() { // smoke build is meant to be run locally to check that we can build everything // it does full installer build of 64-bit release build // We don't build other variants for speed. It takes about 5 mins locally -func buildSmoke() { +func buildSmoke(sign bool) { detectSigntoolPath() defer makePrintDuration("smoke build")() removeReleaseBuilds() @@ -672,7 +656,10 @@ func buildSmoke() { panicIf(!fileExists(lzsa), "file '%s' doesn't exist", lzsa) msbuildPath := detectMsbuildPathMust() - runExeLoggedMust(msbuildPath, `vs2022\SumatraPDF.sln`, `/t:SumatraPDF-dll:Rebuild;test_util:Rebuild`, `/p:Configuration=Release;Platform=x64`, `/m`) + sln := `vs2022\SumatraPDF.sln` + t := `/t:SumatraPDF-dll:Rebuild;test_util:Rebuild` + p := `/p:Configuration=Release;Platform=x64` + runExeLoggedMust(msbuildPath, sln, t, p, `/m`) outDir := filepath.Join("out", "rel64") runTestUtilMust(outDir) @@ -681,11 +668,14 @@ func buildSmoke() { cmd.Dir = outDir runCmdLoggedMust(cmd) } - signFilesMust(outDir) + if sign { + files := []string{"SumatraPDF.exe", "SumatraPDF-dll.exe", "libmupdf.dll", "PdfFilter.dll", "PdfPreview.dll"} + signFilesMust(outDir, files) + } } // func buildJustPortableExe(dir, config, platform string) { -// msbuildPath := detectMsbuildPath() +// msbuildPath := detectMsbuildPathMust() // slnPath := filepath.Join("vs2022", "SumatraPDF.sln") // p := fmt.Sprintf(`/p:Configuration=%s;Platform=%s`, config, platform) @@ -785,17 +775,166 @@ func buildCiDaily(signAndUpload bool) { ratio := float64(origSize) / float64(compressedSize) logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) + if signAndUpload { + // we skip the upload phase + waitForEnter("Press Enter to sign and upload the binaries\n") + signAndUploadFromArchiveMust(ver, archivePath) + return + } + { logf("Uploading %s to %s ", archivePath, archiveKey) timeStart := time.Now() mc.UploadFile(archiveKey, archivePath, true) logf(" took %s\n", time.Since(timeStart)) } - if !signAndUpload { +} + +// /software/sumatrapdf/prerel-unsigned/16878.zip => "16878" +func verFromUnsignedArchiveKey(key string) string { + parts := strings.Split(key, "/") + if len(parts) < 2 { + return "" + } + // "18078.zip" => "18078" + ver := parts[len(parts)-1] + return strings.TrimSuffix(ver, ".zip") +} + +// returns "16878" or "" if no unsigned builds +func getLatestPreRelUnsignedVersion() string { + mc := newMinioR2Client() + objectsCh := mc.ListObjects(unsignedKeyPrefix) + maxVer := 0 + for f := range objectsCh { + must(f.Err) + ver := verFromUnsignedArchiveKey(f.Key) + n, err := strconv.Atoi(ver) + must(err) + if n > maxVer { + maxVer = n + } + } + if maxVer == 0 { + return "" + } + panicIf(maxVer < 16878 || maxVer > 99999) + return strconv.Itoa(maxVer) +} + +// /software/sumatrapdf/prerel/16766/SumatraPDF-prerel-32.exe +func verFromSignedKey(key string) string { + panicIf(!strings.Contains(key, "/prerel/")) + parts := strings.Split(key, "/") + if len(parts) < 3 { + return "" + } + // "18078" => "18078" + ver := parts[len(parts)-2] + return ver +} + +func getLastestPreRelVersion() string { + mc := newMinioR2Client() + objectsCh := mc.ListObjects("software/sumatrapdf/prerel/") + maxVer := 0 + for f := range objectsCh { + must(f.Err) + ver := verFromSignedKey(f.Key) + n, err := strconv.Atoi(ver) + must(err) + if n > maxVer { + maxVer = n + } + } + if maxVer == 0 { + return "" + } + panicIf(maxVer < 16878 || maxVer > 99999) + return strconv.Itoa(maxVer) +} + +// download latest daily build, sign it and upload as pre-release +func signAndUploadLatestPreRelease() { + unsignedVer := getLatestPreRelUnsignedVersion() + if unsignedVer == "" { + logf("no unsigned builds found\n") return } - waitForEnter("Press Enter to sign and upload the binaries\n") - // TODO: implement me + ver := getLastestPreRelVersion() + logf("unsignedVer: %s, ver: %s\n", unsignedVer, ver) + if ver != "" { + panicIf(ver > unsignedVer, "unsignedVer: %s > ver: %s", unsignedVer, ver) + if ver == unsignedVer { + logf("latest signed pre-release build already uploaded\n") + return + } + } + archivePath := filepath.Join("out", unsignedVer+".zip") + must(os.Remove(archivePath)) + key := unsignedArchivePreRelKey(unsignedVer) + mc := newMinioR2Client() + logf("downloading %s to %s...", key, archivePath) + timeStart := time.Now() + mc.DownloadFileAtomically(archivePath, key) + logf(" took %s\n", time.Since(timeStart)) + signAndUploadFromArchiveMust(ver, archivePath) +} + +func signAndUploadFromArchiveMust(ver string, archivePath string) { + outDir := filepath.Join("out", "prerel-unsigned") + recreateDirMust(outDir) + + // extract files from archive + zipData := readFileMust(archivePath) + toSign := []string{} + err := u.IterZipData(zipData, func(f *zip.File, data []byte) error { + relativePath := filepath.FromSlash(f.Name) + if strings.HasSuffix(relativePath, ".exe") { + toSign = append(toSign, relativePath) + } + dstPath := filepath.Join(outDir, relativePath) + must(os.MkdirAll(filepath.Dir(dstPath), 0755)) + must(os.WriteFile(dstPath, data, 0644)) + logf("extracted '%s' => '%s'\n", f.Name, dstPath) + return nil + }) + must(err) + logf("toSign: %v, outDir: %s\n", toSign, outDir) + signFilesMust(outDir, toSign) + + // TODO: create derived files like zip and lzsa + // for _, plat := range []string{kPlatformIntel32, kPlatformIntel64, kPlatformArm64} { + // } + + // build files to upload + + srcDir := outDir + outDir = filepath.Join("out", "prerel-signed") + recreateDirMust(outDir) + for _, plat := range []string{kPlatformIntel32, kPlatformIntel64, kPlatformArm64} { + suffix := getSuffixForPlatform(plat) + fileSuffix := fmt.Sprintf("SumatraPDF-prerel-%s", suffix) + logf("suffix: %s\n", suffix) + { + src := filepath.Join(srcDir, "SumatraPDF.exe") + dst := filepath.Join(outDir, fileSuffix+".exe") + copyFileMust(dst, src) + } + { + src := filepath.Join(srcDir, "SumatraPDF-dll.exe") + dst := filepath.Join(outDir, fileSuffix+"-install.exe") + copyFileMust(dst, src) + } + // TODO: must create this first + if false { + src := filepath.Join(srcDir, "SumatraPDF.zip") + dst := filepath.Join(outDir, fileSuffix+".zip") + copyFileMust(dst, src) + } + } + + // upload files } func waitForEnter(s string) { diff --git a/do/compress.go b/do/compress.go new file mode 100644 index 00000000000..6f380e039b9 --- /dev/null +++ b/do/compress.go @@ -0,0 +1,221 @@ +package main + +import ( + "archive/zip" + "bufio" + "bytes" + "io" + "os" + "path/filepath" + "runtime" + "sync" + "sync/atomic" + + "github.com/andybalholm/brotli" + "github.com/kjk/common/u" + "github.com/klauspost/compress/zstd" + "github.com/ulikunitz/xz/lzma" +) + +func compressFileWithBr(path string) ([]byte, error) { + buf := bytes.Buffer{} + w := brotli.NewWriterLevel(&buf, brotli.BestCompression) + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + + if _, err := io.Copy(w, f); err != nil { + return nil, err + } + if err := w.Close(); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func compressWithZstd(path string) ([]byte, error) { + buf := bytes.Buffer{} + w, err := zstd.NewWriter(&buf, zstd.WithEncoderLevel(zstd.SpeedBestCompression)) + if err != nil { + return nil, err + } + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + + if _, err := io.Copy(w, f); err != nil { + return nil, err + } + if err := w.Close(); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func compressWithLzma2(path string) ([]byte, error) { + buf := bytes.Buffer{} + bw := bufio.NewWriter(&buf) + w, err := lzma.NewWriter2(bw) + if err != nil { + return nil, err + } + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + + if _, err := io.Copy(w, f); err != nil { + return nil, err + } + if err := w.Close(); err != nil { + return nil, err + } + if err := bw.Flush(); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func compressWithLzma2Better(path string) ([]byte, error) { + buf := bytes.Buffer{} + bw := bufio.NewWriter(&buf) + var c lzma.Writer2Config + c.DictCap = (8 * 1024 * 1024) * 16 + if err := c.Verify(); err != nil { + return nil, err + } + w, err := c.NewWriter2(bw) + if err != nil { + return nil, err + } + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + + if _, err := io.Copy(w, f); err != nil { + return nil, err + } + if err := w.Close(); err != nil { + return nil, err + } + if err := bw.Flush(); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func creaZipWithCompressFunction(zipPath string, dir string, fielPaths []string, compressFunc func(string) ([]byte, error), comprSuffix string) error { + os.Remove(zipPath) + w, err := os.Create(zipPath) + if err != nil { + return err + } + zw := zip.NewWriter(w) + defer func() { + err = zw.Close() + }() + var wg sync.WaitGroup + nConcurrent := runtime.NumCPU() + var perr atomic.Pointer[error] + sem := make(chan bool, nConcurrent) + for _, f := range fielPaths { + path := filepath.Join(dir, f) + wg.Add(1) + sem <- true + go func() { + data, err := compressFunc(path) + if err == nil { + zipPath := filepath.ToSlash(f) + comprSuffix + err = addZipDataStore(zw, data, zipPath) + } + if err != nil { + perr.Store(&err) + } + <-sem + wg.Done() + }() + } + wg.Wait() + err = zw.Close() + if err != nil { + return err + } + errVal := perr.Load() + if errVal != nil { + return *errVal + } + return err // from defer +} + +func testCompressOneOff() { + dir := filepath.Join("out", "rel64") + files := []string{"SumatraPDF.exe", "SumatraPDF-dll.exe", "libmupdf.pdb", "SumatraPDF.pdb", "SumatraPDF-dll.pdb"} + origSize := int64(0) + for _, f := range files { + origSize += u.FileSize(filepath.Join(dir, f)) + } + logf("origSize: %s\n", u.FormatSize(origSize)) + + { + archivePath := filepath.Join(dir, "rel64.lzma2.better.zip") + os.Remove(archivePath) + logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) + printDur := measureDuration() + creaZipWithCompressFunction(archivePath, dir, files, compressWithLzma2Better, ".lzma2") + printDur() + compressedSize := u.FileSize(archivePath) + ratio := float64(origSize) / float64(compressedSize) + logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) + } + { + archivePath := filepath.Join(dir, "rel64.lzma2.zip") + os.Remove(archivePath) + logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) + printDur := measureDuration() + creaZipWithCompressFunction(archivePath, dir, files, compressWithLzma2, ".lzma2") + printDur() + compressedSize := u.FileSize(archivePath) + ratio := float64(origSize) / float64(compressedSize) + logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) + } + { + archivePath := filepath.Join(dir, "rel64.br.zip") + os.Remove(archivePath) + logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) + printDur := measureDuration() + creaZipWithCompressFunction(archivePath, dir, files, compressFileWithBr, ".br") + printDur() + compressedSize := u.FileSize(archivePath) + ratio := float64(origSize) / float64(compressedSize) + logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) + } + { + archivePath := filepath.Join(dir, "rel64.zstd.zip") + os.Remove(archivePath) + logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) + printDur := measureDuration() + creaZipWithCompressFunction(archivePath, dir, files, compressWithZstd, ".zstd") + printDur() + compressedSize := u.FileSize(archivePath) + ratio := float64(origSize) / float64(compressedSize) + logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) + } + { + logf("\nCreating rel64.lzsa using\n") + printDur := measureDuration() + archivePath := filepath.Join(dir, "rel64.lzsa") + os.Remove(archivePath) + createLzsaFromFiles("rel64.lzsa", dir, files) + printDur() + compressedSize := u.FileSize(archivePath) + ratio := float64(origSize) / float64(compressedSize) + logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) + } +} diff --git a/do/main.go b/do/main.go index 47a738e1398..1d48f3faef7 100644 --- a/do/main.go +++ b/do/main.go @@ -1,25 +1,16 @@ package main import ( - "archive/zip" - "bufio" - "bytes" "flag" "io" "os" "os/exec" "path/filepath" - "runtime" "strconv" "strings" - "sync" - "sync/atomic" "time" - "github.com/andybalholm/brotli" "github.com/kjk/common/u" - "github.com/klauspost/compress/zstd" - "github.com/ulikunitz/xz/lzma" ) var ( @@ -225,32 +216,33 @@ func main() { ) var ( - flgBuildLogview bool - flgBuildNo int - flgBuildPreRelease bool - flgBuildRelease bool - flgBuildSmoke bool - flgBuildCodeQL bool - flgCheckAccessKeys bool - flgCIBuild bool - flgCIDailyBuild bool - flgClangFormat bool - flgClean bool - flgDiff bool - flgFilesList bool - flgFileUpload string - flgGenDocs bool - flgGenSettings bool - flgGenWebsiteDocs bool - flgLogView bool - flgRegenPremake bool - flgRunTests bool - flgTransDownload bool - flgTriggerCodeQL bool - flgUpdateGoDeps bool - flgUpdateVer string - flgUpload bool - flgWc bool + flgBuildLogview bool + flgBuildNo int + flgBuildPreRelease bool + flgBuildRelease bool + flgBuildSmoke bool + flgBuildCodeQL bool + flgCheckAccessKeys bool + flgCIBuild bool + flgCIDailyBuild bool + flgClangFormat bool + flgClean bool + flgDiff bool + flgFilesList bool + flgFileUpload string + flgGenDocs bool + flgGenSettings bool + flgGenWebsiteDocs bool + flgLogView bool + flgRegenPremake bool + flgRunTests bool + flgTransDownload bool + flgTriggerCodeQL bool + flgUpdateGoDeps bool + flgUpdateVer string + flgUpload bool + flgWc bool + flgSignUploadPreRelease bool ) { @@ -260,6 +252,7 @@ func main() { flag.BoolVar(&flgCIBuild, "ci", false, "run CI steps") flag.BoolVar(&flgCIDailyBuild, "ci-daily", false, "run CI daily steps") flag.BoolVar(&flgBuildSmoke, "build-smoke", false, "run smoke build (installer for 64bit release)") + flag.BoolVar(&flgSignUploadPreRelease, "sign-upload-pre-rel", false, "sign and upload pre-release") flag.BoolVar(&flgBuildPreRelease, "build-pre-rel", false, "build pre-release") flag.BoolVar(&flgBuildRelease, "build-release", false, "build release") flag.BoolVar(&flgBuildCodeQL, "build-codeql", false, "build for codeql") @@ -410,6 +403,11 @@ func main() { opts.upload = true } + if flgSignUploadPreRelease { + signAndUploadLatestPreRelease() + return + } + if flgBuildRelease { // only when building locally, not on GitHub CI opts.verifyTranslationUpToDate = true @@ -446,7 +444,7 @@ func main() { } if flgBuildSmoke { - buildSmoke() + buildSmoke(false) // TODO: flgSign return } @@ -593,206 +591,3 @@ func printBuildNoInfo(buildNo int) { s := lines[n] logf("%d: %s\n", buildNo, s) } - -func compressFileWithBr(path string) ([]byte, error) { - buf := bytes.Buffer{} - w := brotli.NewWriterLevel(&buf, brotli.BestCompression) - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - - if _, err := io.Copy(w, f); err != nil { - return nil, err - } - if err := w.Close(); err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -func compressWithZstd(path string) ([]byte, error) { - buf := bytes.Buffer{} - w, err := zstd.NewWriter(&buf, zstd.WithEncoderLevel(zstd.SpeedBestCompression)) - if err != nil { - return nil, err - } - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - - if _, err := io.Copy(w, f); err != nil { - return nil, err - } - if err := w.Close(); err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -func compressWithLzma2(path string) ([]byte, error) { - buf := bytes.Buffer{} - bw := bufio.NewWriter(&buf) - w, err := lzma.NewWriter2(bw) - if err != nil { - return nil, err - } - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - - if _, err := io.Copy(w, f); err != nil { - return nil, err - } - if err := w.Close(); err != nil { - return nil, err - } - if err := bw.Flush(); err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -func compressWithLzma2Better(path string) ([]byte, error) { - buf := bytes.Buffer{} - bw := bufio.NewWriter(&buf) - var c lzma.Writer2Config - c.DictCap = (8 * 1024 * 1024) * 16 - if err := c.Verify(); err != nil { - return nil, err - } - w, err := c.NewWriter2(bw) - if err != nil { - return nil, err - } - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - - if _, err := io.Copy(w, f); err != nil { - return nil, err - } - if err := w.Close(); err != nil { - return nil, err - } - if err := bw.Flush(); err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -func creaZipWithCompressFunction(zipPath string, dir string, fielPaths []string, compressFunc func(string) ([]byte, error), comprSuffix string) error { - os.Remove(zipPath) - w, err := os.Create(zipPath) - if err != nil { - return err - } - zw := zip.NewWriter(w) - defer func() { - err = zw.Close() - }() - var wg sync.WaitGroup - nConcurrent := runtime.NumCPU() - var perr atomic.Pointer[error] - sem := make(chan bool, nConcurrent) - for _, f := range fielPaths { - path := filepath.Join(dir, f) - wg.Add(1) - sem <- true - go func() { - data, err := compressFunc(path) - if err == nil { - zipPath := filepath.ToSlash(f) + comprSuffix - err = addZipDataStore(zw, data, zipPath) - } - if err != nil { - perr.Store(&err) - } - <-sem - wg.Done() - }() - } - wg.Wait() - err = zw.Close() - if err != nil { - return err - } - errVal := perr.Load() - if errVal != nil { - return *errVal - } - return err // from defer -} - -func testCompressOneOff() { - dir := filepath.Join("out", "rel64") - files := []string{"SumatraPDF.exe", "SumatraPDF-dll.exe", "libmupdf.pdb", "SumatraPDF.pdb", "SumatraPDF-dll.pdb"} - origSize := int64(0) - for _, f := range files { - origSize += u.FileSize(filepath.Join(dir, f)) - } - logf("origSize: %s\n", u.FormatSize(origSize)) - - { - archivePath := filepath.Join(dir, "rel64.lzma2.better.zip") - os.Remove(archivePath) - logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) - printDur := measureDuration() - creaZipWithCompressFunction(archivePath, dir, files, compressWithLzma2Better, ".lzma2") - printDur() - compressedSize := u.FileSize(archivePath) - ratio := float64(origSize) / float64(compressedSize) - logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) - } - { - archivePath := filepath.Join(dir, "rel64.lzma2.zip") - os.Remove(archivePath) - logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) - printDur := measureDuration() - creaZipWithCompressFunction(archivePath, dir, files, compressWithLzma2, ".lzma2") - printDur() - compressedSize := u.FileSize(archivePath) - ratio := float64(origSize) / float64(compressedSize) - logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) - } - { - archivePath := filepath.Join(dir, "rel64.br.zip") - os.Remove(archivePath) - logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) - printDur := measureDuration() - creaZipWithCompressFunction(archivePath, dir, files, compressFileWithBr, ".br") - printDur() - compressedSize := u.FileSize(archivePath) - ratio := float64(origSize) / float64(compressedSize) - logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) - } - { - archivePath := filepath.Join(dir, "rel64.zstd.zip") - os.Remove(archivePath) - logf("\nCreating %s (%d threads)\n", archivePath, runtime.NumCPU()) - printDur := measureDuration() - creaZipWithCompressFunction(archivePath, dir, files, compressWithZstd, ".zstd") - printDur() - compressedSize := u.FileSize(archivePath) - ratio := float64(origSize) / float64(compressedSize) - logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) - } - { - logf("\nCreating rel64.lzsa using\n") - printDur := measureDuration() - archivePath := filepath.Join(dir, "rel64.lzsa") - os.Remove(archivePath) - createLzsaFromFiles("rel64.lzsa", dir, files) - printDur() - compressedSize := u.FileSize(archivePath) - ratio := float64(origSize) / float64(compressedSize) - logf("compressedSize: %s, ratio: %.2f\n", u.FormatSize(compressedSize), ratio) - } -} diff --git a/do/sign.go b/do/sign.go index 7bb1525578c..a81d52ad2f7 100644 --- a/do/sign.go +++ b/do/sign.go @@ -1,28 +1,15 @@ package main import ( - "fmt" "os" "os/exec" - "path/filepath" - "strings" "time" ) -func runCmdLoggedRedacted(cmd *exec.Cmd, redact string) error { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - s := cmd.String() - s = strings.ReplaceAll(s, redact, "***") - fmt.Printf("> %s\n", s) - return cmd.Run() -} - func runCmdLogged(cmd *exec.Cmd) error { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - s := cmd.String() - fmt.Printf("> %s\n", s) + logf("> %s\n", cmd.String()) return cmd.Run() } @@ -32,13 +19,15 @@ func runCmdLogged(cmd *exec.Cmd) error { // signtool args (https://msdn.microsoft.com/en-us/library/windows/desktop/aa387764(v=vs.85).aspx): // // /as : append signature +// /n ${name} : name of the certificate, must be installed in the cert store // /fd ${alg} : specify digest algo, default is sha1, SHA256 is recommended // /t ${url} : timestamp server // /tr ${url} : timestamp rfc 3161 server // /td ${alg} : for /tr, must be after /tr -// /du ${url} : URL for expanded description of the signed content. +// /du ${url} : URL for expanded description of the signed content +// /v : verbose // /debug : show debugging info -func signMust(path string) { +func signFilesMust(dir string, files []string) { // the sign tool is finicky, so copy the cert to the same dir as // the exe we're signing @@ -47,34 +36,30 @@ func signMust(path string) { var err error for i := 0; i < 3; i++ { signtoolPath := detectSigntoolPath() - fileDir := filepath.Dir(path) - fileName := filepath.Base(path) + + signServer := "http://time.certum.pl/" //signServer := "http://timestamp.verisign.com/scripts/timstamp.dll" //signServer := "http://timestamp.sectigo.com" - signServer := "http://time.certum.pl/" //desc := "https://www.sumatrapdfreader.org" + + // TODO: sign with sha1 for pre-win-7. We don't support win7 anymore + { - // sign with sha1 for pre-win-7 - // TODO: remove it? We no longer support pre-win7 - cmd := exec.Command(signtoolPath, "sign", "/t", signServer, + // TODO: add "/du", desc, + // sign with sha256 for win7+ ater Jan 2016 + args := []string{"sign", + "/t", signServer, "/n", "Open Source Developer, Krzysztof Kowalczyk", - //"/du", desc, "/fd", "sha256", - fileName) - cmd.Dir = fileDir + "/debug", + "/v", + } + args = append(args, files...) + cmd := exec.Command(signtoolPath, args...) + cmd.Dir = dir err = runCmdLogged(cmd) } - if false && err == nil { - certPwd := "" - // double-sign with sha2 for win7+ ater Jan 2016 - cmd := exec.Command(signtoolPath, "sign", "/fd", "sha256", "/tr", signServer, - "/td", "sha256", "/f", "cert.pfx", - "/p", certPwd, "/as", fileName) - cmd.Dir = fileDir - err = runCmdLoggedRedacted(cmd, certPwd) - } - if err == nil { return } diff --git a/do/util.go b/do/util.go index 758090feee4..ca77d9af40d 100644 --- a/do/util.go +++ b/do/util.go @@ -287,3 +287,10 @@ func copyFileMust(dst, src string) { err = os.WriteFile(dst, d, 0644) must(err) } + +func recreateDirMust(dir string) { + err := os.RemoveAll(dir) + must(err) + err = os.MkdirAll(dir, 0755) + must(err) +}