diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6ae0606d6..4561ecd0a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,8 +4,8 @@ on: - pull_request env: - GO_BUILD_CMD: 'go build "-ldflags=-s -w" -trimpath' - GO_BUILD_TEST_CMD: "go test -mod=mod -gcflags=all=-d=checkptr -c -tags functional" + GO_BUILD_CMD: 'go build "-ldflags=-s -w -linkmode=external" -trimpath' + GO_BUILD_TEST_CMD: 'go test -mod=mod "-ldflags=-linkmode=external" -gcflags=all=-d=checkptr -c -tags functional' GOTESTSUM_VERSION: "latest" @@ -319,21 +319,28 @@ jobs: # accept the eula & '${{ github.workspace }}/bin/psexec' -accepteula -nobanner cmd /c "exit 0" + - name: Generate Resource Object Files + shell: pwsh + run: | + go generate -x ./cmd/... + cd test + go generate -x ./... + # run tests - name: Test rego security policy - run: ${{ env.GOTESTSUM_CMD }} -tags=rego -timeout=30m -gcflags=all=-d=checkptr ./pkg/securitypolicy/... + run: ${{ env.GOTESTSUM_CMD }} -ldflags=-linkmode=external -gcflags=all=-d=checkptr -tags=rego -timeout=30m ./pkg/securitypolicy/... - name: Test repo - run: ${{ env.GOTESTSUM_CMD }} -gcflags=all=-d=checkptr -tags admin -timeout=20m ./... + run: ${{ env.GOTESTSUM_CMD }} -ldflags=-linkmode=external -gcflags=all=-d=checkptr -tags=admin -timeout=20m ./... - name: Test lcow tagged packages (shimV2) - run: ${{ env.GOTESTSUM_CMD }} -gcflags=all=-d=checkptr -tags lcow -timeout=10m ./... + run: ${{ env.GOTESTSUM_CMD }} -ldflags=-linkmode=external -gcflags=all=-d=checkptr -tags=lcow -timeout=10m ./... - name: Test wcow tagged packages (shimV2) - run: ${{ env.GOTESTSUM_CMD }} -gcflags=all=-d=checkptr -tags wcow -timeout=10m ./... + run: ${{ env.GOTESTSUM_CMD }} -ldflags=-linkmode=external -gcflags=all=-d=checkptr -tags=wcow -timeout=10m ./... - name: Run non-functional tests - run: ${{ env.GOTESTSUM_CMD }} -mod=mod -gcflags=all=-d=checkptr ./internal/... ./pkg/... ./parity/... + run: ${{ env.GOTESTSUM_CMD }} -ldflags=-linkmode=external -gcflags=all=-d=checkptr -mod=mod -timeout=10m ./internal/... ./pkg/... ./parity/... working-directory: test - name: Build and run containerd-shim-runhcs-v1 tests @@ -537,8 +544,10 @@ jobs: - name: Build the shim working-directory: src/github.com/Microsoft/hcsshim - shell: powershell + shell: pwsh run: | + go generate -x ./cmd/containerd-shim-runhcs-v1 + ${{ env.GO_BUILD_CMD }} -mod vendor -o "${{ github.workspace }}/src/github.com/containerd/containerd/bin/containerd-shim-runhcs-v1.exe" .\cmd\containerd-shim-runhcs-v1 - name: Install gotestsum @@ -655,6 +664,13 @@ jobs: $LASTEXITCODE = 0 } + - name: Generate Resource Object Files + shell: pwsh + run: | + go generate -x ./cmd/... + cd test + go generate -x ./... + - run: ${{ env.GO_BUILD_CMD }} -tags lcow ./... name: Build lcow tagged packages (shimV2) - run: ${{ env.GO_BUILD_CMD }} -tags wcow ./... @@ -693,7 +709,7 @@ jobs: name: Build rootfs.exe - run: ${{ env.GO_BUILD_CMD }} ./internal/tools/securitypolicy name: Build securitypolicy.exe - - run: ${{ env.GO_BUILD_CMD }} ./internal/tools/securitypolicy + - run: go build "-ldflags=-s -w" -trimpath ./internal/tools/securitypolicy name: Build securitypolicy env: GOOS: linux diff --git a/.gitignore b/.gitignore index d8695f7e16..2e6968186a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,11 @@ *.so *.dylib +# manifest related generated files +*.syso +manifest.xml +*.exe.manifest + # Ignore vscode setting files .vscode/ .idea/ diff --git a/cmd/containerd-shim-lcow-v2/containerd-shim-lcow-v2.exe.manifest b/cmd/containerd-shim-lcow-v2/containerd-shim-lcow-v2.exe.manifest deleted file mode 100644 index 9c5ba67277..0000000000 --- a/cmd/containerd-shim-lcow-v2/containerd-shim-lcow-v2.exe.manifest +++ /dev/null @@ -1,17 +0,0 @@ - - - containerd-shim-lcow-v2 - - - - - - - - - - true - - - - diff --git a/cmd/containerd-shim-lcow-v2/main.go b/cmd/containerd-shim-lcow-v2/main.go index 9951144a8a..86f1a02ca7 100644 --- a/cmd/containerd-shim-lcow-v2/main.go +++ b/cmd/containerd-shim-lcow-v2/main.go @@ -23,7 +23,7 @@ import ( ) // Add a manifest to get proper Windows version detection. -//go:generate go tool github.com/josephspurrier/goversioninfo/cmd/goversioninfo -platform-specific +//go:generate pwsh -Command "../../scripts/New-ResourceObjectFile.ps1 -ErrorAction 'Stop' -Destination '.' -Name 'containerd-shim-lcow-v2' -UseVersionFile -Architecture 'all'" func main() { logrus.AddHook(log.NewHook()) diff --git a/cmd/containerd-shim-lcow-v2/resource_windows_386.syso b/cmd/containerd-shim-lcow-v2/resource_windows_386.syso deleted file mode 100644 index 5510dc97e2..0000000000 Binary files a/cmd/containerd-shim-lcow-v2/resource_windows_386.syso and /dev/null differ diff --git a/cmd/containerd-shim-lcow-v2/resource_windows_amd64.syso b/cmd/containerd-shim-lcow-v2/resource_windows_amd64.syso deleted file mode 100644 index 2c00dedb25..0000000000 Binary files a/cmd/containerd-shim-lcow-v2/resource_windows_amd64.syso and /dev/null differ diff --git a/cmd/containerd-shim-lcow-v2/resource_windows_arm.syso b/cmd/containerd-shim-lcow-v2/resource_windows_arm.syso deleted file mode 100644 index 2706f485e1..0000000000 Binary files a/cmd/containerd-shim-lcow-v2/resource_windows_arm.syso and /dev/null differ diff --git a/cmd/containerd-shim-lcow-v2/resource_windows_arm64.syso b/cmd/containerd-shim-lcow-v2/resource_windows_arm64.syso deleted file mode 100644 index 718ad2bfb8..0000000000 Binary files a/cmd/containerd-shim-lcow-v2/resource_windows_arm64.syso and /dev/null differ diff --git a/cmd/containerd-shim-lcow-v2/versioninfo.json b/cmd/containerd-shim-lcow-v2/versioninfo.json deleted file mode 100644 index 11316902d5..0000000000 --- a/cmd/containerd-shim-lcow-v2/versioninfo.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "FixedFileInfo": { - "FileVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "ProductVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "Comments": "", - "CompanyName": "Microsoft", - "FileDescription": "", - "FileVersion": "", - "InternalName": "", - "LegalCopyright": "", - "LegalTrademarks": "", - "OriginalFilename": "containerd-shim-lcow-v2.exe", - "PrivateBuild": "", - "ProductName": "lcow shim", - "ProductVersion": "v1.0.0.0", - "SpecialBuild": "" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - }, - "IconPath": "", - "ManifestPath": "containerd-shim-lcow-v2.exe.manifest" -} - diff --git a/cmd/containerd-shim-runhcs-v1/containerd-shim-runhcs-v1.exe.manifest b/cmd/containerd-shim-runhcs-v1/containerd-shim-runhcs-v1.exe.manifest deleted file mode 100644 index 8eb3d51687..0000000000 --- a/cmd/containerd-shim-runhcs-v1/containerd-shim-runhcs-v1.exe.manifest +++ /dev/null @@ -1,16 +0,0 @@ - - - containerd-shim-runhcs-v1 - - - - - - - - - - true - - - diff --git a/cmd/containerd-shim-runhcs-v1/main.go b/cmd/containerd-shim-runhcs-v1/main.go index 77d51b61ed..d805903ea9 100644 --- a/cmd/containerd-shim-runhcs-v1/main.go +++ b/cmd/containerd-shim-runhcs-v1/main.go @@ -31,7 +31,7 @@ const usage = `` const ttrpcAddressEnv = "TTRPC_ADDRESS" // Add a manifest to get proper Windows version detection. -//go:generate go tool github.com/josephspurrier/goversioninfo/cmd/goversioninfo -platform-specific +//go:generate pwsh -Command "../../scripts/New-ResourceObjectFile.ps1 -ErrorAction 'Stop' -Destination '.' -Name 'containerd-shim-runhcs-v1' -UseVersionFile -Architecture 'all'" // `-ldflags '-X ...'` only works if the variable is uninitialized or set to a constant value. // keep empty and override with data from [internal/version] only if empty to allow diff --git a/cmd/containerd-shim-runhcs-v1/resource_windows_386.syso b/cmd/containerd-shim-runhcs-v1/resource_windows_386.syso deleted file mode 100644 index 7a73623fb6..0000000000 Binary files a/cmd/containerd-shim-runhcs-v1/resource_windows_386.syso and /dev/null differ diff --git a/cmd/containerd-shim-runhcs-v1/resource_windows_amd64.syso b/cmd/containerd-shim-runhcs-v1/resource_windows_amd64.syso deleted file mode 100644 index 491951b90f..0000000000 Binary files a/cmd/containerd-shim-runhcs-v1/resource_windows_amd64.syso and /dev/null differ diff --git a/cmd/containerd-shim-runhcs-v1/resource_windows_arm.syso b/cmd/containerd-shim-runhcs-v1/resource_windows_arm.syso deleted file mode 100644 index 87ee735d86..0000000000 Binary files a/cmd/containerd-shim-runhcs-v1/resource_windows_arm.syso and /dev/null differ diff --git a/cmd/containerd-shim-runhcs-v1/resource_windows_arm64.syso b/cmd/containerd-shim-runhcs-v1/resource_windows_arm64.syso deleted file mode 100644 index 475fb2bdb3..0000000000 Binary files a/cmd/containerd-shim-runhcs-v1/resource_windows_arm64.syso and /dev/null differ diff --git a/cmd/containerd-shim-runhcs-v1/versioninfo.json b/cmd/containerd-shim-runhcs-v1/versioninfo.json deleted file mode 100644 index fee1a0170b..0000000000 --- a/cmd/containerd-shim-runhcs-v1/versioninfo.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "FixedFileInfo": { - "FileVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "ProductVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "Comments": "", - "CompanyName": "Microsoft", - "FileDescription": "", - "FileVersion": "", - "InternalName": "", - "LegalCopyright": "", - "LegalTrademarks": "", - "OriginalFilename": "containerd-shim-runhcs-v1.exe", - "PrivateBuild": "", - "ProductName": "runhcs shim", - "ProductVersion": "v1.0.0.0", - "SpecialBuild": "" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - }, - "IconPath": "", - "ManifestPath": "containerd-shim-runhcs-v1.exe.manifest" -} \ No newline at end of file diff --git a/cmd/ncproxy/main.go b/cmd/ncproxy/main.go index 319b0d2759..e1b033c1cb 100644 --- a/cmd/ncproxy/main.go +++ b/cmd/ncproxy/main.go @@ -8,6 +8,8 @@ import ( "github.com/sirupsen/logrus" ) +//go:generate pwsh -Command "../../scripts/New-ResourceObjectFile.ps1 -ErrorAction 'Stop' -Destination '.' -Name 'ncproxy' -UseVersionFile -Architecture 'all'" + func main() { if err := app().Run(os.Args); err != nil { logrus.Fatal(err) diff --git a/cmd/ncproxy/ncproxy.exe.manifest b/cmd/ncproxy/ncproxy.exe.manifest deleted file mode 100644 index dfe8b5794f..0000000000 --- a/cmd/ncproxy/ncproxy.exe.manifest +++ /dev/null @@ -1,10 +0,0 @@ - - - ncproxy - - - - - - - diff --git a/cmd/ncproxy/resource_windows_386.syso b/cmd/ncproxy/resource_windows_386.syso deleted file mode 100644 index f0d338b8b9..0000000000 Binary files a/cmd/ncproxy/resource_windows_386.syso and /dev/null differ diff --git a/cmd/ncproxy/resource_windows_amd64.syso b/cmd/ncproxy/resource_windows_amd64.syso deleted file mode 100644 index 0d1ac58894..0000000000 Binary files a/cmd/ncproxy/resource_windows_amd64.syso and /dev/null differ diff --git a/cmd/ncproxy/versioninfo.json b/cmd/ncproxy/versioninfo.json deleted file mode 100644 index 1688aeea2f..0000000000 --- a/cmd/ncproxy/versioninfo.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "FixedFileInfo": { - "FileVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "ProductVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "Comments": "", - "CompanyName": "", - "FileDescription": "", - "FileVersion": "", - "InternalName": "", - "LegalCopyright": "", - "LegalTrademarks": "", - "OriginalFilename": "", - "PrivateBuild": "", - "ProductName": "", - "ProductVersion": "v1.0.0.0", - "SpecialBuild": "" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - }, - "IconPath": "", - "ManifestPath": "ncproxy.exe.manifest" -} \ No newline at end of file diff --git a/cmd/runhcs/main.go b/cmd/runhcs/main.go index 16fc198d3a..356e9745e3 100644 --- a/cmd/runhcs/main.go +++ b/cmd/runhcs/main.go @@ -20,7 +20,7 @@ import ( ) // Add a manifest to get proper Windows version detection. -//go:generate go tool github.com/josephspurrier/goversioninfo/cmd/goversioninfo -platform-specific +//go:generate pwsh -Command "../../scripts/New-ResourceObjectFile.ps1 -ErrorAction 'Stop' -Destination '.' -Name 'runhcs' -UseVersionFile -Architecture 'all'" // `-ldflags '-X ...'` only works if the variable is uninitialized or set to a constant value. // keep empty and override with data from [internal/version] only if empty to allow diff --git a/cmd/runhcs/resource_windows_386.syso b/cmd/runhcs/resource_windows_386.syso deleted file mode 100644 index 3aabc3b51b..0000000000 Binary files a/cmd/runhcs/resource_windows_386.syso and /dev/null differ diff --git a/cmd/runhcs/resource_windows_amd64.syso b/cmd/runhcs/resource_windows_amd64.syso deleted file mode 100644 index 628336e15a..0000000000 Binary files a/cmd/runhcs/resource_windows_amd64.syso and /dev/null differ diff --git a/cmd/runhcs/resource_windows_arm.syso b/cmd/runhcs/resource_windows_arm.syso deleted file mode 100644 index 36c921d0bd..0000000000 Binary files a/cmd/runhcs/resource_windows_arm.syso and /dev/null differ diff --git a/cmd/runhcs/resource_windows_arm64.syso b/cmd/runhcs/resource_windows_arm64.syso deleted file mode 100644 index 931ee3b839..0000000000 Binary files a/cmd/runhcs/resource_windows_arm64.syso and /dev/null differ diff --git a/cmd/runhcs/runhcs.exe.manifest b/cmd/runhcs/runhcs.exe.manifest deleted file mode 100644 index 0eee5a83b4..0000000000 --- a/cmd/runhcs/runhcs.exe.manifest +++ /dev/null @@ -1,10 +0,0 @@ - - - runhcs - - - - - - - diff --git a/cmd/runhcs/versioninfo.json b/cmd/runhcs/versioninfo.json deleted file mode 100644 index a9394a4000..0000000000 --- a/cmd/runhcs/versioninfo.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "FixedFileInfo": { - "FileVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "ProductVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "Comments": "", - "CompanyName": "", - "FileDescription": "", - "FileVersion": "", - "InternalName": "", - "LegalCopyright": "", - "LegalTrademarks": "", - "OriginalFilename": "", - "PrivateBuild": "", - "ProductName": "", - "ProductVersion": "v1.0.0.0", - "SpecialBuild": "" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - }, - "IconPath": "", - "ManifestPath": "runhcs.exe.manifest" -} \ No newline at end of file diff --git a/cmd/wclayer/resource_windows_386.syso b/cmd/wclayer/resource_windows_386.syso deleted file mode 100644 index d6c1b22ef9..0000000000 Binary files a/cmd/wclayer/resource_windows_386.syso and /dev/null differ diff --git a/cmd/wclayer/resource_windows_amd64.syso b/cmd/wclayer/resource_windows_amd64.syso deleted file mode 100644 index 421c14c0ce..0000000000 Binary files a/cmd/wclayer/resource_windows_amd64.syso and /dev/null differ diff --git a/cmd/wclayer/resource_windows_arm.syso b/cmd/wclayer/resource_windows_arm.syso deleted file mode 100644 index 9123d7ad33..0000000000 Binary files a/cmd/wclayer/resource_windows_arm.syso and /dev/null differ diff --git a/cmd/wclayer/resource_windows_arm64.syso b/cmd/wclayer/resource_windows_arm64.syso deleted file mode 100644 index 5b65c4f4a8..0000000000 Binary files a/cmd/wclayer/resource_windows_arm64.syso and /dev/null differ diff --git a/cmd/wclayer/versioninfo.json b/cmd/wclayer/versioninfo.json deleted file mode 100644 index f3addb147a..0000000000 --- a/cmd/wclayer/versioninfo.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "FixedFileInfo": { - "FileVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "ProductVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "Comments": "", - "CompanyName": "", - "FileDescription": "", - "FileVersion": "", - "InternalName": "", - "LegalCopyright": "", - "LegalTrademarks": "", - "OriginalFilename": "", - "PrivateBuild": "", - "ProductName": "", - "ProductVersion": "v1.0.0.0", - "SpecialBuild": "" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - }, - "IconPath": "", - "ManifestPath": "wclayer.exe.manifest" -} \ No newline at end of file diff --git a/cmd/wclayer/wclayer.exe.manifest b/cmd/wclayer/wclayer.exe.manifest deleted file mode 100644 index 4b02770c52..0000000000 --- a/cmd/wclayer/wclayer.exe.manifest +++ /dev/null @@ -1,10 +0,0 @@ - - - wclayer - - - - - - - diff --git a/cmd/wclayer/wclayer.go b/cmd/wclayer/wclayer.go index 9b1b125352..80b8e5103e 100644 --- a/cmd/wclayer/wclayer.go +++ b/cmd/wclayer/wclayer.go @@ -13,7 +13,7 @@ import ( ) // Add a manifest to get proper Windows version detection. -//go:generate go tool github.com/josephspurrier/goversioninfo/cmd/goversioninfo -platform-specific +//go:generate pwsh -Command "../../scripts/New-ResourceObjectFile.ps1 -ErrorAction 'Stop' -Destination '.' -Name 'wclayer' -UseVersionFile -Architecture 'all'" var usage = `Windows Container layer utility diff --git a/go.mod b/go.mod index 79893bfdd3..e3f9d4b0c8 100644 --- a/go.mod +++ b/go.mod @@ -16,9 +16,6 @@ tool ( // generate Win32 API code github.com/Microsoft/go-winio/tools/mkwinsyscall - // create syso files for manifesting - github.com/josephspurrier/goversioninfo/cmd/goversioninfo - // mock gRPC client and servers go.uber.org/mock/mockgen ) @@ -73,7 +70,6 @@ require ( cyphar.com/go-pathrs v0.2.4 // indirect github.com/OneOfOne/xxhash v1.2.8 // indirect github.com/agnivade/levenshtein v1.2.0 // indirect - github.com/akavel/rsrc v0.10.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/checkpoint-restore/go-criu/v7 v7.2.0 // indirect @@ -100,7 +96,6 @@ require ( github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/gorilla/mux v1.8.1 // indirect - github.com/josephspurrier/goversioninfo v1.5.0 // indirect github.com/klauspost/compress v1.18.5 // indirect github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect github.com/lestrrat-go/blackmagic v1.0.2 // indirect diff --git a/go.sum b/go.sum index e299a51753..ce144cee6c 100644 --- a/go.sum +++ b/go.sum @@ -377,8 +377,6 @@ github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM= -github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw= -github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= github.com/alecthomas/participle/v2 v2.0.0/go.mod h1:rAKZdJldHu8084ojcWevWAL8KmEU+AT+Olodb+WoN2Y= @@ -766,8 +764,6 @@ github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= -github.com/josephspurrier/goversioninfo v1.5.0 h1:9TJtORoyf4YMoWSOo/cXFN9A/lB3PniJ91OxIH6e7Zg= -github.com/josephspurrier/goversioninfo v1.5.0/go.mod h1:6MoTvFZ6GKJkzcdLnU5T/RGYUbHQbKpYeNP0AgQLd2o= github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA= github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= github.com/jsimonetti/rtnetlink/v2 v2.0.1 h1:xda7qaHDSVOsADNouv7ukSuicKZO7GgVUCXxpaIEIlM= diff --git a/internal/tools/uvmboot/main.go b/internal/tools/uvmboot/main.go index 300c968e30..af8ad8284e 100644 --- a/internal/tools/uvmboot/main.go +++ b/internal/tools/uvmboot/main.go @@ -16,6 +16,8 @@ import ( "github.com/Microsoft/hcsshim/internal/winapi" ) +//go:generate pwsh -Command "../../../scripts/New-ResourceObjectFile.ps1 -ErrorAction 'Stop' -Destination '.' -Name 'uvmboot' -UseVersionFile -Architecture 'all'" + const ( cpusArgName = "cpus" memoryArgName = "memory" diff --git a/internal/tools/uvmboot/resource_windows_386.syso b/internal/tools/uvmboot/resource_windows_386.syso deleted file mode 100644 index b4320575e4..0000000000 Binary files a/internal/tools/uvmboot/resource_windows_386.syso and /dev/null differ diff --git a/internal/tools/uvmboot/resource_windows_amd64.syso b/internal/tools/uvmboot/resource_windows_amd64.syso deleted file mode 100644 index d6100a85b9..0000000000 Binary files a/internal/tools/uvmboot/resource_windows_amd64.syso and /dev/null differ diff --git a/scripts/New-ResourceObjectFile.ps1 b/scripts/New-ResourceObjectFile.ps1 new file mode 100644 index 0000000000..e0f8c9608a --- /dev/null +++ b/scripts/New-ResourceObjectFile.ps1 @@ -0,0 +1,232 @@ +#Requires -Version 7 + +<# +.SYNOPSIS + +Generate *.syso resource files to be linked into Go binaries. + +.DESCRIPTION + +Use RC.exe and then CVTRES.exe to embed the manifest as well as other resource information +into a COFF object file that the go compiler can automatically link into the final binary. +While similar to what github.com/josephspurrier/goversioninfo/cmd/goversioninfo does +(and is intended to also be used in go:generate directives), the resulting object file is +different in structure than the `goversioninfo` output. +Specifically, it has multiple sections (.debug$S, .rsrc$01, and .rsrc$03), and causes `go build` +to fail with "sectnum < 0!" unless the `-ldflags=-linkmode=external` flag is used, +which requires enabling CGO. + +.EXAMPLE + +New-ResourceObjectFile -Destination .\cmd\runhcs -Name runhcs -Version 0.14.0 -Architecture all + +Create resource_windows_amd64.syso and resource_windows_arm64.syso files in the cmd\runhcs directory. + +.LINK + +https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests + +.LINK + +https://learn.microsoft.com/en-us/windows/win32/menurc/about-resource-files + +#> +[CmdletBinding()] +param ( + [ValidateNotNullOrEmpty()] + [ValidateScript( { + return Test-Path -PathType 'Container' -Path $_ -ErrorAction 'Ignore' + }, + ErrorMessage = "Invalid or non-existant path: '{0}'.")] + [Parameter(Mandatory = $true)] + [string] + $Destination, + + # Application name. + [ValidateNotNullOrEmpty()] + [Parameter(Mandatory = $true)] + [string] + $Name, + + # Application version. + [ValidateNotNullOrEmpty()] + [version] + $Version = '1.0.0.0', + + # Read version from internal\version\data\VERSION. + # Falls back on $Version parameter if file is not found. + # + # See internal\version\version.go or Set-VersionInfo.ps1 for more info. + [ValidateNotNullOrEmpty()] + [switch] + $UseVersionFile, + + # Processors architecture to target. + # Use all to generate for all supported architectures. + [ValidateSet('amd64', 'arm64', 'all')] + $Architecture = 'amd64', + + # Visual Studio installation path + [ValidateNotNullOrEmpty()] + [ValidateScript( { + return Test-Path -PathType 'Container' -Path $_ -ErrorAction 'Ignore' + }, + ErrorMessage = "Invalid or non-existant directory: '{0}'.")] + [string] + $VSPath +) + +$root = Split-Path $PSScriptRoot + +function run([string]$cmd) { + Write-Verbose "Running command: $cmd" + $r = & ${env:COMSPEC} /C $cmd 2>&1 + if ( $LASTEXITCODE -ne 0 ) { + Write-Host $r + Write-Error -ErrorAction 'Stop' "Command failed: $cmd" + } + $r +} + +function Get-PackageVersion { + [CmdletBinding()] + param ( + [string] + $file = 'internal\version\data\VERSION' + ) + Write-Verbose "Reading version from version file: $file" + + $vf = Join-Path -Resolve $root $file -ErrorAction 'Ignore' + if ( [string]::IsNullOrEmpty($vf) ) { + Write-Error "Version file $file does not exist" -ErrorAction 'Continue' + return + } + + $s = (Get-Content $vf -ErrorAction 'Ignore').Trim() + if ( [string]::IsNullOrWhiteSpace($s) ) { + Write-Error "Empty version file: ${vf}" -ErrorAction 'Continue' + return + } + + # remove "v" prefix + $s = $s.Trim() -replace '^v', '' + Write-Verbose "Read version from file `"${vf}`": $s" + try { + $v = [semver]$s + } catch { + Write-Error "Invalid version string: $s" -ErrorAction 'Continue' + return + } + [version]::new($v.Major, $v.Minor, $v.Patch, 0) +} + +$Destination = Resolve-Path $Destination -ErrorAction 'Stop' + +$manifestDir = New-Item -ItemType 'Directory' -Force -Path (Join-Path $env:TEMP 'manifest' "$Name-$(New-Guid)") -ErrorAction 'Stop' +$Manifest = Join-Path $manifestDir 'manifest.xml' -ErrorAction 'Stop' + +if ( $UseVersionFile ) { + $v = Get-PackageVersion -ErrorAction 'Continue' + if ( $null -ne $v ) { + # Fall back on default version if file is empty + $Version = $v + } + Write-Verbose "Using version: $Version" +} + +[xml]$m = @' + + + + + + + true + + + + + + + + +'@ + +$m.assembly.assemblyIdentity.SetAttribute('name', "Microsoft.ContainerPlatform.$Name") +$m.assembly.assemblyIdentity.SetAttribute('version', $Version) +if ( $Architecture -ne 'all' ) { + # valid values: x86, amd64, arm, arm64 + $m.assembly.assemblyIdentity.SetAttribute('processorArchitecture', $Architecture.ToLower()) +} + +$m.PreserveWhitespace = $false +$m.Save($Manifest) +Write-Verbose "Wrote manifest file: $Manifest" + +if ( [string]::IsNullOrEmpty($VSPath) ) { + $vswhere = Join-Path -Resolve ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' -ErrorAction 'Stop' + $VSPath = run "`"$vswhere`" -prerelease -latest -property installationPath" +} else { + $VSPath = Resolve-Path $VSPath -ErrorAction 'Stop' +} +Write-Verbose "Using Visual Studio installation: $VSPath" + +$vsdevbat = Join-Path -Resolve $VSPath '\Common7\Tools\vsdevcmd.bat' -ErrorAction 'Ignore' +if ( [string]::IsNullOrEmpty($vsdevbat) ) { + Write-Error -ErrorAction 'Stop' "Missing 'vsdevcmd.bat' tool in valid Visual Studio SDK installation: $VSPath" +} +Write-Verbose "Visual Studio CMD batch file: $vsdevbat" +# surpress output line of "Parsing of manifest successful." +$null = run "cd /d ${manifestDir}&&`"${vsdevbat}`" -no_logo&&mt.exe -nologo -manifest $(Split-Path -Leaf $manifest) -validate_manifest" + +$rc = Join-Path $manifestDir 'resource.rc' -ErrorAction 'Stop' +$vstr = "$($Version.Major), $($Version.Minor), $($Version.Build), 0" + +# TODO: set VER_PRODUCT* fields with package release info +@" +#include + +#pragma code_page(65001) // UTF-8 + +#define VER_FILEDESCRIPTION_STR "Microsoft Container Platform $Name" +#define VER_FILEVERSION $vstr +#define VER_FILEVERSION_STR "$version" + +#define VER_PRODUCTNAME_STR "Microsoft Container Platform" +#define VER_PRODUCTVERSION $vstr +#define VER_PRODUCTVERSION_STR "$version" + +#define VER_INTERNALNAME_STR "${Name}.exe" +#define VER_ORIGINALFILENAME_STR "${Name}.exe" + +#define VER_COMPANYNAME_STR "Microsoft Corporation" + +#define VER_FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#define VER_FILEFLAGS 0 +#define VER_FILEOS VOS_NT_WINDOWS32 +#define VER_FILETYPE VFT_APP +#define VER_FILESUBTYPE VFT2_UNKNOWN + +#define MANIFEST_RESOURCE_ID 1 +MANIFEST_RESOURCE_ID RT_MANIFEST "manifest.xml" + +#include +"@ | Out-File -Encoding 'ascii' -FilePath $rc -ErrorAction 'Stop' + +run "cd /d ${manifestDir}&&`"${vsdevbat}`" -no_logo&&rc.exe /nologo $(Split-Path -Leaf $rc)" + +# Conveniently, the accepted processorArchitecture values match GOARCH values, +# but CVTRES needs its own constants (ARM, ARM64, ARM64EC, ARM64X, EBC, IA64, X64, X86) +foreach ( $p in @{ + 'amd64' = 'X64' + 'arm64' = 'ARM64' + }.GetEnumerator() ) { + $arch = $p.Key + if ( ($Architecture -ne $arch) -and ($Architecture -ne 'all') ) { + continue + } + + $syso = Join-Path $Destination "resource_windows_${arch}.syso" + Write-Verbose "Generating $arch resource file: $syso" + run "cd /d ${manifestDir}&&`"${vsdevbat}`" -no_logo&&CVTRES.exe /NOLOGO /MACHINE:$($p.Value) `"/OUT:${syso}`" resource.res" +} diff --git a/scripts/Set-VersionInfo.ps1 b/scripts/Set-VersionInfo.ps1 index a61cf5d6ff..45a29c612d 100644 --- a/scripts/Set-VersionInfo.ps1 +++ b/scripts/Set-VersionInfo.ps1 @@ -1,4 +1,4 @@ -# Example of who to set the version/git information in ./internal/version so +# Set the version/git information in ./internal/version so # that the binaries will report the appropriate information. $ErrorActionPreference = 'Continue' diff --git a/test/go.mod b/test/go.mod index d8cce74985..0006539432 100644 --- a/test/go.mod +++ b/test/go.mod @@ -2,9 +2,6 @@ module github.com/Microsoft/hcsshim/test go 1.25.0 -// create syso files for manifesting -tool github.com/josephspurrier/goversioninfo/cmd/goversioninfo - require ( github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29 github.com/Microsoft/hcsshim v0.14.0-rc.1 @@ -38,7 +35,6 @@ require ( github.com/Microsoft/didx509go v0.0.3 // indirect github.com/OneOfOne/xxhash v1.2.8 // indirect github.com/agnivade/levenshtein v1.2.0 // indirect - github.com/akavel/rsrc v0.10.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -72,7 +68,6 @@ require ( github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/mux v1.8.1 // indirect - github.com/josephspurrier/goversioninfo v1.5.0 // indirect github.com/klauspost/compress v1.18.5 // indirect github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect github.com/lestrrat-go/blackmagic v1.0.2 // indirect diff --git a/test/go.sum b/test/go.sum index ac6ecbbe00..2228ba1ed0 100644 --- a/test/go.sum +++ b/test/go.sum @@ -14,8 +14,6 @@ github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8 github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q= github.com/agnivade/levenshtein v1.2.0 h1:U9L4IOT0Y3i0TIlUIDJ7rVUziKi/zPbrJGaFrtYH3SY= github.com/agnivade/levenshtein v1.2.0/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU= -github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw= -github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -166,8 +164,6 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/josephspurrier/goversioninfo v1.5.0 h1:9TJtORoyf4YMoWSOo/cXFN9A/lB3PniJ91OxIH6e7Zg= -github.com/josephspurrier/goversioninfo v1.5.0/go.mod h1:6MoTvFZ6GKJkzcdLnU5T/RGYUbHQbKpYeNP0AgQLd2o= github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA= github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= github.com/jsimonetti/rtnetlink/v2 v2.0.1 h1:xda7qaHDSVOsADNouv7ukSuicKZO7GgVUCXxpaIEIlM= diff --git a/test/pkg/manifest/manifest.go b/test/pkg/manifest/manifest.go index fb40921761..64ae11707f 100644 --- a/test/pkg/manifest/manifest.go +++ b/test/pkg/manifest/manifest.go @@ -3,4 +3,4 @@ // This package allows tests can include the .syso to manifest them to pick up the right Windows build package manifest -//go:generate go tool github.com/josephspurrier/goversioninfo/cmd/goversioninfo -platform-specific +//go:generate pwsh -Command "../../../scripts/New-ResourceObjectFile.ps1 -ErrorAction 'Stop' -Destination '.' -Name 'hcsshim-test' -UseVersionFile -Architecture 'all'" diff --git a/test/pkg/manifest/manifest.xml b/test/pkg/manifest/manifest.xml deleted file mode 100644 index 229e61e1fd..0000000000 --- a/test/pkg/manifest/manifest.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - hcsshim-test - - - - - - - diff --git a/test/pkg/manifest/resource_windows_386.syso b/test/pkg/manifest/resource_windows_386.syso deleted file mode 100644 index 497a64fa82..0000000000 Binary files a/test/pkg/manifest/resource_windows_386.syso and /dev/null differ diff --git a/test/pkg/manifest/resource_windows_amd64.syso b/test/pkg/manifest/resource_windows_amd64.syso deleted file mode 100644 index 05db0b5231..0000000000 Binary files a/test/pkg/manifest/resource_windows_amd64.syso and /dev/null differ diff --git a/test/pkg/manifest/resource_windows_arm.syso b/test/pkg/manifest/resource_windows_arm.syso deleted file mode 100644 index c1c2165f3a..0000000000 Binary files a/test/pkg/manifest/resource_windows_arm.syso and /dev/null differ diff --git a/test/pkg/manifest/resource_windows_arm64.syso b/test/pkg/manifest/resource_windows_arm64.syso deleted file mode 100644 index eb5df81f12..0000000000 Binary files a/test/pkg/manifest/resource_windows_arm64.syso and /dev/null differ diff --git a/test/pkg/manifest/versioninfo.json b/test/pkg/manifest/versioninfo.json deleted file mode 100644 index 7c4fddcf92..0000000000 --- a/test/pkg/manifest/versioninfo.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "FixedFileInfo": { - "FileVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "ProductVersion": { - "Major": 1, - "Minor": 0, - "Patch": 0, - "Build": 0 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "Comments": "", - "CompanyName": "", - "FileDescription": "", - "FileVersion": "", - "InternalName": "", - "LegalCopyright": "", - "LegalTrademarks": "", - "OriginalFilename": "", - "PrivateBuild": "", - "ProductName": "", - "ProductVersion": "v1.0.0.0", - "SpecialBuild": "" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - }, - "IconPath": "", - "ManifestPath": "manifest.xml" -} \ No newline at end of file diff --git a/vendor/github.com/akavel/rsrc/AUTHORS b/vendor/github.com/akavel/rsrc/AUTHORS deleted file mode 100644 index 06fb069913..0000000000 --- a/vendor/github.com/akavel/rsrc/AUTHORS +++ /dev/null @@ -1,5 +0,0 @@ -Force Charlie -Mateusz Czapliński -Quentin Renard -shnmng -Thomas Combeléran diff --git a/vendor/github.com/akavel/rsrc/LICENSE.txt b/vendor/github.com/akavel/rsrc/LICENSE.txt deleted file mode 100644 index 5c1511ec15..0000000000 --- a/vendor/github.com/akavel/rsrc/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013-2017 The rsrc Authors. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/akavel/rsrc/binutil/plain.go b/vendor/github.com/akavel/rsrc/binutil/plain.go deleted file mode 100644 index ddf5238b94..0000000000 --- a/vendor/github.com/akavel/rsrc/binutil/plain.go +++ /dev/null @@ -1,13 +0,0 @@ -package binutil - -import ( - "reflect" -) - -func Plain(kind reflect.Kind) bool { - switch kind { - case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128: - return true - } - return false -} diff --git a/vendor/github.com/akavel/rsrc/binutil/sizedfile.go b/vendor/github.com/akavel/rsrc/binutil/sizedfile.go deleted file mode 100644 index 3a6606fd85..0000000000 --- a/vendor/github.com/akavel/rsrc/binutil/sizedfile.go +++ /dev/null @@ -1,35 +0,0 @@ -package binutil - -import ( - "io" - "os" -) - -type SizedReader interface { - io.Reader - Size() int64 -} - -type SizedFile struct { - f *os.File - s *io.SectionReader // helper, for Size() -} - -func (r *SizedFile) Read(p []byte) (n int, err error) { return r.s.Read(p) } -func (r *SizedFile) Size() int64 { return r.s.Size() } -func (r *SizedFile) Close() error { return r.f.Close() } - -func SizedOpen(filename string) (*SizedFile, error) { - f, err := os.Open(filename) - if err != nil { - return nil, err - } - info, err := f.Stat() - if err != nil { - return nil, err - } - return &SizedFile{ - f: f, - s: io.NewSectionReader(f, 0, info.Size()), - }, nil -} diff --git a/vendor/github.com/akavel/rsrc/binutil/walk.go b/vendor/github.com/akavel/rsrc/binutil/walk.go deleted file mode 100644 index 4aa4ad30e8..0000000000 --- a/vendor/github.com/akavel/rsrc/binutil/walk.go +++ /dev/null @@ -1,63 +0,0 @@ -package binutil - -import ( - "errors" - "fmt" - "path" - "reflect" -) - -var ( - WALK_SKIP = errors.New("") -) - -type Walker func(v reflect.Value, path string) error - -func Walk(value interface{}, walker Walker) error { - err := walk(reflect.ValueOf(value), "/", walker) - if err == WALK_SKIP { - err = nil - } - return err -} - -func stopping(err error) bool { - return err != nil && err != WALK_SKIP -} - -func walk(v reflect.Value, spath string, walker Walker) error { - err := walker(v, spath) - if err != nil { - return err - } - v = reflect.Indirect(v) - switch v.Kind() { - case reflect.Slice, reflect.Array: - for i := 0; i < v.Len(); i++ { - err = walk(v.Index(i), spath+fmt.Sprintf("[%d]", i), walker) - if stopping(err) { - return err - } - } - case reflect.Interface: - err = walk(v.Elem(), spath, walker) - if stopping(err) { - return err - } - case reflect.Struct: - //t := v.Type() - for i := 0; i < v.NumField(); i++ { - //f := t.Field(i) //TODO: handle unexported fields - vv := v.Field(i) - err = walk(vv, path.Join(spath, v.Type().Field(i).Name), walker) - if stopping(err) { - return err - } - } - default: - // FIXME: handle other special cases too - // String - return nil - } - return nil -} diff --git a/vendor/github.com/akavel/rsrc/binutil/writer.go b/vendor/github.com/akavel/rsrc/binutil/writer.go deleted file mode 100644 index cd2ef97818..0000000000 --- a/vendor/github.com/akavel/rsrc/binutil/writer.go +++ /dev/null @@ -1,33 +0,0 @@ -package binutil - -import ( - "encoding/binary" - "io" - "reflect" -) - -type Writer struct { - W io.Writer - Offset uint32 //FIXME: int64? - Err error -} - -func (w *Writer) WriteLE(v interface{}) { - if w.Err != nil { - return - } - w.Err = binary.Write(w.W, binary.LittleEndian, v) - if w.Err != nil { - return - } - w.Offset += uint32(reflect.TypeOf(v).Size()) -} - -func (w *Writer) WriteFromSized(r SizedReader) { - if w.Err != nil { - return - } - var n int64 - n, w.Err = io.CopyN(w.W, r, r.Size()) - w.Offset += uint32(n) -} diff --git a/vendor/github.com/akavel/rsrc/coff/coff.go b/vendor/github.com/akavel/rsrc/coff/coff.go deleted file mode 100644 index 3c6d5f4b93..0000000000 --- a/vendor/github.com/akavel/rsrc/coff/coff.go +++ /dev/null @@ -1,363 +0,0 @@ -package coff - -import ( - "debug/pe" - "encoding/binary" - "errors" - "io" - "reflect" - "regexp" - "sort" - "strconv" - "strings" - - "github.com/akavel/rsrc/binutil" -) - -type Dir struct { // struct IMAGE_RESOURCE_DIRECTORY - Characteristics uint32 - TimeDateStamp uint32 - MajorVersion uint16 - MinorVersion uint16 - NumberOfNamedEntries uint16 - NumberOfIdEntries uint16 - DirEntries - Dirs -} - -type DirEntries []DirEntry -type Dirs []Dir - -type DirEntry struct { // struct IMAGE_RESOURCE_DIRECTORY_ENTRY - NameOrId uint32 - OffsetToData uint32 -} - -type DataEntry struct { // struct IMAGE_RESOURCE_DATA_ENTRY - OffsetToData uint32 - Size1 uint32 - CodePage uint32 //FIXME: what value here? for now just using 0 - Reserved uint32 -} - -type RelocationEntry struct { - RVA uint32 // "offset within the Section's raw data where the address starts." - SymbolIndex uint32 // "(zero based) index in the Symbol table to which the reference refers." - Type uint16 -} - -// Values reverse-engineered from windres output; names from teh Internets. -// Teh googlies Internets don't seem to have much to say about the AMD64 one, -// unfortunately :/ but it works... -const ( - _IMAGE_REL_AMD64_ADDR32NB = 0x03 - _IMAGE_REL_I386_DIR32NB = 0x07 - _IMAGE_REL_ARM64_ADDR32NB = 0x02 - _IMAGE_REL_ARM_ADDR32NB = 0x02 -) - -type Auxiliary [18]byte - -type Symbol struct { - Name [8]byte - Value uint32 - SectionNumber uint16 - Type uint16 - StorageClass uint8 - AuxiliaryCount uint8 - Auxiliaries []Auxiliary -} - -type StringsHeader struct { - Length uint32 -} - -const ( - MASK_SUBDIRECTORY = 1 << 31 - - RT_ICON = 3 - RT_GROUP_ICON = 3 + 11 - RT_MANIFEST = 24 -) - -// http://www.delorie.com/djgpp/doc/coff/symtab.html -const ( - DT_PTR = 1 - T_UCHAR = 12 -) - -var ( - STRING_RSRC = [8]byte{'.', 'r', 's', 'r', 'c', 0, 0, 0} - - LANG_ENTRY = DirEntry{NameOrId: 0x0409} //FIXME: language; what value should be here? -) - -type PaddedData struct { - Data Sizer - Padding []byte -} - -type Sizer interface { - Size() int64 //NOTE: must not exceed limits of uint32, or behavior is undefined -} - -type Coff struct { - pe.FileHeader - pe.SectionHeader32 - - *Dir - DataEntries []DataEntry - Data []PaddedData - - Relocations []RelocationEntry - Symbols []Symbol - StringsHeader - Strings []Sizer -} - -// NOTE: must be called immediately after NewRSRC, before any other -// functions. -func (coff *Coff) Arch(arch string) error { - switch arch { - case "386": - coff.Machine = pe.IMAGE_FILE_MACHINE_I386 - case "amd64": - // Sources: - // https://github.com/golang/go/blob/0e23ca41d99c82d301badf1b762888e2c69e6c57/src/debug/pe/pe.go#L116 - // https://github.com/yasm/yasm/blob/7160679eee91323db98b0974596c7221eeff772c/modules/objfmts/coff/coff-objfmt.c#L38 - // FIXME: currently experimental -- not sure if something more doesn't need to be changed - coff.Machine = pe.IMAGE_FILE_MACHINE_AMD64 - case "arm": - // see - // https://github.com/golang/go/blob/f3424ceff2fa48615ed98580f337ab044925c940/src/cmd/link/internal/ld/pe.go#L736 - coff.Machine = pe.IMAGE_FILE_MACHINE_ARMNT - case "arm64": - // Waiting https://github.com/golang/go/issues/36439 - coff.Machine = pe.IMAGE_FILE_MACHINE_ARM64 - default: - return errors.New("coff: unknown architecture: " + arch) - } - return nil -} - -// addSymbol appends a symbol to Coff.Symbols and to Coff.Strings. -//NOTE: symbol s must be probably >8 characters long -//NOTE: symbol s should not contain embedded zeroes -func (coff *Coff) addSymbol(s string) { - coff.FileHeader.NumberOfSymbols++ - - buf := strings.NewReader(s + "\000") // ASCIIZ - r := io.NewSectionReader(buf, 0, int64(len(s)+1)) - coff.Strings = append(coff.Strings, r) - - coff.StringsHeader.Length += uint32(r.Size()) - - coff.Symbols = append(coff.Symbols, Symbol{ - //Name: // will be filled in Freeze - //Value: // as above - SectionNumber: 1, - Type: 0, // why 0??? // DT_PTR<<4 | T_UCHAR, // unsigned char* // (?) or use void* ? T_VOID=1 - StorageClass: 2, // 2=C_EXT, or 5=C_EXTDEF ? - AuxiliaryCount: 0, - }) -} - -func NewRSRC() *Coff { - return &Coff{ - pe.FileHeader{ - Machine: pe.IMAGE_FILE_MACHINE_I386, - NumberOfSections: 1, // .rsrc - TimeDateStamp: 0, // was also 0 in sample data from MinGW's windres.exe - NumberOfSymbols: 1, - SizeOfOptionalHeader: 0, - Characteristics: 0x0104, //FIXME: copied from windres.exe output, find out what should be here and why - }, - pe.SectionHeader32{ - Name: STRING_RSRC, - Characteristics: 0x40000040, // "INITIALIZED_DATA MEM_READ" ? - }, - - // "directory hierarchy" of .rsrc section: top level goes resource type, then id/name, then language - &Dir{}, - - []DataEntry{}, - []PaddedData{}, - - []RelocationEntry{}, - - []Symbol{Symbol{ - Name: STRING_RSRC, - Value: 0, - SectionNumber: 1, - Type: 0, // FIXME: wtf? - StorageClass: 3, // FIXME: is it ok? and uint8? and what does the value mean? - AuxiliaryCount: 0, // FIXME: wtf? - }}, - - StringsHeader{ - Length: uint32(binary.Size(StringsHeader{})), // empty strings table -- but we must still show size of the table's header... - }, - []Sizer{}, - } -} - -//NOTE: function assumes that 'id' is increasing on each entry -//NOTE: only usable for Coff created using NewRSRC -func (coff *Coff) AddResource(kind uint32, id uint16, data Sizer) { - re := RelocationEntry{ - // "(zero based) index in the Symbol table to which the - // reference refers. Once you have loaded the COFF file into - // memory and know where each symbol is, you find the new - // updated address for the given symbol and update the - // reference accordingly." - SymbolIndex: 0, - } - switch coff.Machine { - case pe.IMAGE_FILE_MACHINE_I386: - re.Type = _IMAGE_REL_I386_DIR32NB - case pe.IMAGE_FILE_MACHINE_AMD64: - re.Type = _IMAGE_REL_AMD64_ADDR32NB - case pe.IMAGE_FILE_MACHINE_ARMNT: - re.Type = _IMAGE_REL_ARM_ADDR32NB - case pe.IMAGE_FILE_MACHINE_ARM64: - re.Type = _IMAGE_REL_ARM64_ADDR32NB - } - coff.Relocations = append(coff.Relocations, re) - coff.SectionHeader32.NumberOfRelocations++ - - // find top level entry, inserting new if necessary at correct sorted position - entries0 := coff.Dir.DirEntries - dirs0 := coff.Dir.Dirs - i0 := sort.Search(len(entries0), func(i int) bool { - return entries0[i].NameOrId >= kind - }) - if i0 >= len(entries0) || entries0[i0].NameOrId != kind { - // inserting new entry & dir - entries0 = append(entries0[:i0], append([]DirEntry{{NameOrId: kind}}, entries0[i0:]...)...) - dirs0 = append(dirs0[:i0], append([]Dir{{}}, dirs0[i0:]...)...) - coff.Dir.NumberOfIdEntries++ - } - coff.Dir.DirEntries = entries0 - coff.Dir.Dirs = dirs0 - - // for second level, assume ID is always increasing, so we don't have to sort - dirs0[i0].DirEntries = append(dirs0[i0].DirEntries, DirEntry{NameOrId: uint32(id)}) - dirs0[i0].Dirs = append(dirs0[i0].Dirs, Dir{ - NumberOfIdEntries: 1, - DirEntries: DirEntries{LANG_ENTRY}, - }) - dirs0[i0].NumberOfIdEntries++ - - // calculate preceding DirEntry leaves, to find new index in Data & DataEntries - n := 0 - for _, dir0 := range dirs0[:i0+1] { - n += len(dir0.DirEntries) //NOTE: assuming 1 language here; TODO: dwell deeper if more langs added - } - n-- - - // insert new data in correct place - coff.DataEntries = append(coff.DataEntries[:n], append([]DataEntry{{Size1: uint32(data.Size())}}, coff.DataEntries[n:]...)...) - coff.Data = append(coff.Data[:n], append([]PaddedData{pad(data)}, coff.Data[n:]...)...) -} - -func pad(data Sizer) PaddedData { - return PaddedData{ - Data: data, - Padding: make([]byte, -data.Size()&7), - } -} - -// Freeze fills in some important offsets in resulting file. -func (coff *Coff) Freeze() { - switch coff.SectionHeader32.Name { - case STRING_RSRC: - coff.freezeRSRC() - } -} - -func (coff *Coff) freezeCommon1(path string, offset, diroff uint32) (newdiroff uint32) { - switch path { - case "/Dir": - coff.SectionHeader32.PointerToRawData = offset - diroff = offset - case "/Relocations": - coff.SectionHeader32.PointerToRelocations = offset - coff.SectionHeader32.SizeOfRawData = offset - diroff - case "/Symbols": - coff.FileHeader.PointerToSymbolTable = offset - } - return diroff -} - -func freezeCommon2(v reflect.Value, offset *uint32) error { - if binutil.Plain(v.Kind()) { - *offset += uint32(binary.Size(v.Interface())) // TODO: change to v.Type().Size() ? - return nil - } - vv, ok := v.Interface().(Sizer) - if ok { - *offset += uint32(vv.Size()) - return binutil.WALK_SKIP - } - return nil -} - -func (coff *Coff) freezeRSRC() { - leafwalker := make(chan *DirEntry) - go func() { - for _, dir1 := range coff.Dir.Dirs { // resource type - for _, dir2 := range dir1.Dirs { // resource ID - for i := range dir2.DirEntries { // resource lang - leafwalker <- &dir2.DirEntries[i] - } - } - } - }() - - var offset, diroff uint32 - binutil.Walk(coff, func(v reflect.Value, path string) error { - diroff = coff.freezeCommon1(path, offset, diroff) - - RE := regexp.MustCompile - const N = `\[(\d+)\]` - m := matcher{} - switch { - case m.Find(path, RE("^/Dir/Dirs"+N+"$")): - coff.Dir.DirEntries[m[0]].OffsetToData = MASK_SUBDIRECTORY | (offset - diroff) - case m.Find(path, RE("^/Dir/Dirs"+N+"/Dirs"+N+"$")): - coff.Dir.Dirs[m[0]].DirEntries[m[1]].OffsetToData = MASK_SUBDIRECTORY | (offset - diroff) - case m.Find(path, RE("^/DataEntries"+N+"$")): - direntry := <-leafwalker - direntry.OffsetToData = offset - diroff - case m.Find(path, RE("^/DataEntries"+N+"/OffsetToData$")): - coff.Relocations[m[0]].RVA = offset - diroff - case m.Find(path, RE("^/Data"+N+"$")): - coff.DataEntries[m[0]].OffsetToData = offset - diroff - } - - return freezeCommon2(v, &offset) - }) -} - -func mustAtoi(s string) int { - i, err := strconv.Atoi(s) - if err != nil { - panic(err) - } - return i -} - -type matcher []int - -func (m *matcher) Find(s string, re *regexp.Regexp) bool { - subs := re.FindStringSubmatch(s) - if subs == nil { - return false - } - - *m = (*m)[:0] - for i := 1; i < len(subs); i++ { - *m = append(*m, mustAtoi(subs[i])) - } - return true -} diff --git a/vendor/github.com/akavel/rsrc/ico/ico.go b/vendor/github.com/akavel/rsrc/ico/ico.go deleted file mode 100644 index 0d419b1272..0000000000 --- a/vendor/github.com/akavel/rsrc/ico/ico.go +++ /dev/null @@ -1,214 +0,0 @@ -// Package ico describes Windows ICO file format. -package ico - -// ICO: http://msdn.microsoft.com/en-us/library/ms997538.aspx -// BMP/DIB: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183562%28v=vs.85%29.aspx - -import ( - "bytes" - "encoding/binary" - "fmt" - "image" - "image/color" - "io" - "io/ioutil" - "sort" -) - -const ( - BI_RGB = 0 -) - -type ICONDIR struct { - Reserved uint16 // must be 0 - Type uint16 // Resource Type (1 for icons) - Count uint16 // How many images? -} - -type IconDirEntryCommon struct { - Width byte // Width, in pixels, of the image - Height byte // Height, in pixels, of the image - ColorCount byte // Number of colors in image (0 if >=8bpp) - Reserved byte // Reserved (must be 0) - Planes uint16 // Color Planes - BitCount uint16 // Bits per pixel - BytesInRes uint32 // How many bytes in this resource? -} - -type ICONDIRENTRY struct { - IconDirEntryCommon - ImageOffset uint32 // Where in the file is this image? [from beginning of file] -} - -type BITMAPINFOHEADER struct { - Size uint32 - Width int32 - Height int32 // NOTE: "represents the combined height of the XOR and AND masks. Remember to divide this number by two before using it to perform calculations for either of the XOR or AND masks." - Planes uint16 // [BMP/DIB]: "is always 1" - BitCount uint16 - Compression uint32 // for ico = 0 - SizeImage uint32 - XPelsPerMeter int32 // for ico = 0 - YPelsPerMeter int32 // for ico = 0 - ClrUsed uint32 // for ico = 0 - ClrImportant uint32 // for ico = 0 -} - -type RGBQUAD struct { - Blue byte - Green byte - Red byte - Reserved byte // must be 0 -} - -func skip(r io.Reader, n int64) error { - _, err := io.CopyN(ioutil.Discard, r, n) - return err -} - -type icoOffset struct { - n int - offset uint32 -} - -type rawico struct { - icoinfo ICONDIRENTRY - bmpinfo *BITMAPINFOHEADER - idx int - data []byte -} - -type byOffsets []rawico - -func (o byOffsets) Len() int { return len(o) } -func (o byOffsets) Less(i, j int) bool { return o[i].icoinfo.ImageOffset < o[j].icoinfo.ImageOffset } -func (o byOffsets) Swap(i, j int) { - tmp := o[i] - o[i] = o[j] - o[j] = tmp -} - -type ICO struct { - image.Image -} - -func DecodeHeaders(r io.Reader) ([]ICONDIRENTRY, error) { - var hdr ICONDIR - err := binary.Read(r, binary.LittleEndian, &hdr) - if err != nil { - return nil, err - } - if hdr.Reserved != 0 || hdr.Type != 1 { - return nil, fmt.Errorf("bad magic number") - } - - entries := make([]ICONDIRENTRY, hdr.Count) - for i := 0; i < len(entries); i++ { - err = binary.Read(r, binary.LittleEndian, &entries[i]) - if err != nil { - return nil, err - } - } - return entries, nil -} - -// NOTE: won't succeed on files with overlapping offsets -func unused_decodeAll(r io.Reader) ([]*ICO, error) { - var hdr ICONDIR - err := binary.Read(r, binary.LittleEndian, &hdr) - if err != nil { - return nil, err - } - if hdr.Reserved != 0 || hdr.Type != 1 { - return nil, fmt.Errorf("bad magic number") - } - - raws := make([]rawico, hdr.Count) - for i := 0; i < len(raws); i++ { - err = binary.Read(r, binary.LittleEndian, &raws[i].icoinfo) - if err != nil { - return nil, err - } - raws[i].idx = i - } - - sort.Sort(byOffsets(raws)) - - offset := uint32(binary.Size(&hdr) + len(raws)*binary.Size(ICONDIRENTRY{})) - for i := 0; i < len(raws); i++ { - err = skip(r, int64(raws[i].icoinfo.ImageOffset-offset)) - if err != nil { - return nil, err - } - offset = raws[i].icoinfo.ImageOffset - - raws[i].bmpinfo = &BITMAPINFOHEADER{} - err = binary.Read(r, binary.LittleEndian, raws[i].bmpinfo) - if err != nil { - return nil, err - } - - err = skip(r, int64(raws[i].bmpinfo.Size-uint32(binary.Size(BITMAPINFOHEADER{})))) - if err != nil { - return nil, err - } - raws[i].data = make([]byte, raws[i].icoinfo.BytesInRes-raws[i].bmpinfo.Size) - _, err = io.ReadFull(r, raws[i].data) - if err != nil { - return nil, err - } - } - - icos := make([]*ICO, len(raws)) - for i := 0; i < len(raws); i++ { - fmt.Println(i) - icos[raws[i].idx], err = decode(raws[i].bmpinfo, &raws[i].icoinfo, raws[i].data) - if err != nil { - return nil, err - } - } - return icos, nil -} - -func decode(info *BITMAPINFOHEADER, icoinfo *ICONDIRENTRY, data []byte) (*ICO, error) { - if info.Compression != BI_RGB { - return nil, fmt.Errorf("ICO compression not supported (got %d)", info.Compression) - } - - //if info.ClrUsed!=0 { - // panic(info.ClrUsed) - //} - - r := bytes.NewBuffer(data) - - bottomup := info.Height > 0 - if !bottomup { - info.Height = -info.Height - } - - switch info.BitCount { - case 8: - ncol := int(icoinfo.ColorCount) - if ncol == 0 { - ncol = 256 - } - - pal := make(color.Palette, ncol) - for i := 0; i < ncol; i++ { - var rgb RGBQUAD - err := binary.Read(r, binary.LittleEndian, &rgb) - if err != nil { - return nil, err - } - pal[i] = color.NRGBA{R: rgb.Red, G: rgb.Green, B: rgb.Blue, A: 0xff} //FIXME: is Alpha ok 0xff? - } - fmt.Println(pal) - - fmt.Println(info.SizeImage, len(data)-binary.Size(RGBQUAD{})*len(pal), info.Width, info.Height) - - default: - return nil, fmt.Errorf("unsupported ICO bit depth (BitCount) %d", info.BitCount) - } - - return nil, nil -} diff --git a/vendor/github.com/josephspurrier/goversioninfo/.gitattributes b/vendor/github.com/josephspurrier/goversioninfo/.gitattributes deleted file mode 100644 index 9f224172fc..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/.gitattributes +++ /dev/null @@ -1,8 +0,0 @@ -*.sh text eol=lf -*.hex binary -*.rc text eol=crlf -*.manifest text eol=crlf -*.ico binary -testdata/go/*.go text eol=lf -go.mod text eol=lf -go.sum text eol=lf diff --git a/vendor/github.com/josephspurrier/goversioninfo/.gitignore b/vendor/github.com/josephspurrier/goversioninfo/.gitignore deleted file mode 100644 index b83ed98b82..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -# IDE Settings -.vscode/ - -# Folders -vendor/ - -# Files -cmd/goversioninfo/goversioninfo -*.exe -*.syso -versioninfo.go -/bin - -# OS Files -.DS_Store -thumbs.db - -# Environment Files -.envrc \ No newline at end of file diff --git a/vendor/github.com/josephspurrier/goversioninfo/LICENSE b/vendor/github.com/josephspurrier/goversioninfo/LICENSE deleted file mode 100644 index 85f6e7e913..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Joseph Spurrier - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/josephspurrier/goversioninfo/Makefile b/vendor/github.com/josephspurrier/goversioninfo/Makefile deleted file mode 100644 index bbaa6729e2..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# This Makefile is an easy way to run common operations. -# Execute commands this: -# * make test-go -# * make test-integration -# -# Tip: Each command is run on its own line so you can't CD unless you -# connect commands together using operators. See examples: -# A; B # Run A and then B, regardless of success of A -# A && B # Run B if and only if A succeeded -# A || B # Run B if and only if A failed -# A & # Run A in background. -# Source: https://askubuntu.com/a/539293 -# -# Tip: Use $(shell app param) syntax when expanding a shell return value. - -.PHONY: test-go -test-go: - # Run the Go tests. - go test ./... - -.PHONY: test-integration -test-integration: - # Build the application. - mkdir -p bin && go build -o bin/goversioninfo cmd/goversioninfo/main.go - # Test the application. - PATH="${PATH}:$(shell pwd)/bin" ./testdata/bash/build.sh \ No newline at end of file diff --git a/vendor/github.com/josephspurrier/goversioninfo/README.md b/vendor/github.com/josephspurrier/goversioninfo/README.md deleted file mode 100644 index 82407168c3..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/README.md +++ /dev/null @@ -1,127 +0,0 @@ -GoVersionInfo -========== - -[![Go Report Card](https://goreportcard.com/badge/github.com/josephspurrier/goversioninfo)](https://goreportcard.com/report/github.com/josephspurrier/goversioninfo) [![Unit Tests](https://github.com/josephspurrier/goversioninfo/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/josephspurrier/goversioninfo/actions/workflows/unit-tests.yml) [![Coverage Status](https://coveralls.io/repos/josephspurrier/goversioninfo/badge.svg)](https://coveralls.io/r/josephspurrier/goversioninfo) [![GoDoc](https://godoc.org/github.com/josephspurrier/goversioninfo?status.svg)](https://godoc.org/github.com/josephspurrier/goversioninfo) - -Microsoft Windows File Properties/Version Info and Icon Resource Generator for the Go Language - -Package creates a syso file which contains Microsoft Windows Version Information and an optional icon. When you run "go build", Go will embed the version information and an optional icon and an optional manifest in the executable. Go will automatically use the syso file if it's in the same directory as the main() function. - -Example of the file properties you can set using this package: - -![Image of File Properties](https://cloud.githubusercontent.com/assets/2394539/12073634/0b32cb04-b0f6-11e5-9d8e-f9923ca554cf.jpg) - -## Usage - -To install, run the following command: -~~~ -go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo -~~~ - -Copy testdata/resource/versioninfo.json into your working directory and then modify the file with your own settings. - -Add a similar text to the top of your Go source code (-icon and -manifest are optional, but can also be specified in the versioninfo.json file): -~~~ go -//go:generate goversioninfo -icon=testdata/resource/icon.ico -manifest=testdata/resource/goversioninfo.exe.manifest -~~~ - -Run the Go commands in this order so goversioninfo will create a file called resource.syso in the same directory as the Go source code. -~~~ -go generate -go build -~~~ - -## Command-Line Flags - -Complete list of the flags for goversioninfo: - -~~~ - -charset=0: charset ID - -comment="": StringFileInfo.Comments - -company="": StringFileInfo.CompanyName - -copyright="": StringFileInfo.LegalCopyright - -description="": StringFileInfo.FileDescription - -example=false: dump out an example versioninfo.json to stdout - -file-version="": StringFileInfo.FileVersion - -icon="": icon file name(s), separated by commas - -internal-name="": StringFileInfo.InternalName - -manifest="": manifest file name - -skip-versioninfo=false: skip version info reading on true, allows setting just icon - -o="resource.syso": output file name - -gofile="": Go output file name (optional) - generates a Go file to access version information internally - -gofilepackage="main": Go output package name (optional, requires parameter: 'gofile') - -platform-specific=false: output i386 and amd64 named resource.syso, ignores -o - -original-name="": StringFileInfo.OriginalFilename - -private-build="": StringFileInfo.PrivateBuild - -product-name="": StringFileInfo.ProductName - -product-version="": StringFileInfo.ProductVersion - -special-build="": StringFileInfo.SpecialBuild - -trademark="": StringFileInfo.LegalTrademarks - -translation=0: translation ID - -64:false: generate 64-bit binaries on true - -arm:false: generate ARM binaries on true - -ver-major=-1: FileVersion.Major - -ver-minor=-1: FileVersion.Minor - -ver-patch=-1: FileVersion.Patch - -ver-build=-1: FileVersion.Build - -product-ver-major=-1: ProductVersion.Major - -product-ver-minor=-1: ProductVersion.Minor - -product-ver-patch=-1: ProductVersion.Patch - -product-ver-build=-1: ProductVersion.Build -~~~ - -You can look over the Microsoft Resource Information: [VERSIONINFO resource](https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx) - -You can look through the Microsoft Version Information structures: [Version Information Structures](https://msdn.microsoft.com/en-us/library/windows/desktop/ff468916(v=vs.85).aspx) - -## PowerShell Differences - -In PowerShell, the version components are named differently than the fields in -the versioninfo.json file: - -``` -PowerShell: versioninfo.json: ------------ ----------------- -FileMajorPart = FileVersion.Major -FileMinorPart = FileVersion.Minor -FileBuildPart = FileVersion.Patch -FilePrivatePart = FileVersion.Build -ProductMajorPart = ProductVersion.Major -ProductMinorPart = ProductVersion.Minor -ProductBuildPart = ProductVersion.Patch -ProductPrivatePart = ProductVersion.Build - -``` - -If you find any other differences, let me know. - -## Alternatives to this Tool - -You can also use [windres](https://sourceware.org/binutils/docs/binutils/windres.html) to create the syso file. The windres executable is available in either [MinGW](http://www.mingw.org/) or [tdm-gcc](http://tdm-gcc.tdragon.net/). - -Below is a sample batch file you can use to create a .syso file from a .rc file. There are sample .rc files in the testdata/rc folder. - -~~~ -@ECHO OFF - -SET PATH=C:\TDM-GCC-64\bin;%PATH% -REM SET PATH=C:\mingw64\bin;%PATH% - -windres -i testdata/rc/versioninfo.rc -O coff -o versioninfo.syso - -PAUSE -~~~ - -The information on how to create a .rc file is available [here](https://msdn.microsoft.com/en-us/library/windows/desktop/aa381043(v=vs.85).aspx). You can use the testdata/rc/versioninfo.rc file to create a .syso file that contains version info, icon, and manifest. - -## Issues - -The majority of the code for the creation of the syso file is from this package: [https://github.com/akavel/rsrc](https://github.com/akavel/rsrc) - -There is an [issue](https://github.com/akavel/rsrc/issues/12) with adding the icon resource that prevents your application from being compressed or modified with a resource editor. Please use with caution. - -## Major Contributions - -Thanks to [Tamás Gulácsi](https://github.com/tgulacsi) for his superb code additions, refactoring, and optimization to make this a solid package. - -Thanks to [Mateusz Czaplinski](https://github.com/akavel/rsrc) for his embedded binary resource package with icon and manifest functionality. diff --git a/vendor/github.com/josephspurrier/goversioninfo/cmd/goversioninfo/main.go b/vendor/github.com/josephspurrier/goversioninfo/cmd/goversioninfo/main.go deleted file mode 100644 index 54fc8a9ba6..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/cmd/goversioninfo/main.go +++ /dev/null @@ -1,290 +0,0 @@ -// Contribution by Tamás Gulácsi - -package main - -import ( - "flag" - "fmt" - "io" - "log" - "os" - - "github.com/josephspurrier/goversioninfo" -) - -func main() { - flagExample := flag.Bool("example", false, "dump out an example versioninfo.json to stdout") - flagOut := flag.String("o", "resource.syso", "output file name") - flagGo := flag.String("gofile", "", "Go output file name (optional)") - flagPackage := flag.String("gofilepackage", "main", "Go output package name (optional, requires parameter: 'gofile')") - flagPlatformSpecific := flag.Bool("platform-specific", false, "output i386, amd64, arm and arm64 named resource.syso, ignores -o") - flagIcon := flag.String("icon", "", "icon file name(s), separated by commas") - flagManifest := flag.String("manifest", "", "manifest file name") - flagSkipVersion := flag.Bool("skip-versioninfo", false, "skip version info") - flagPropagateVerStrings := flag.Bool("propagate-ver-strings", false, - "fill FixedFileInfo version fields using FileVersion and ProductVersion from the StringFileInfo") - - flagComment := flag.String("comment", "", "StringFileInfo.Comments") - flagCompany := flag.String("company", "", "StringFileInfo.CompanyName") - flagDescription := flag.String("description", "", "StringFileInfo.FileDescription") - flagFileVersion := flag.String("file-version", "", "StringFileInfo.FileVersion") - flagInternalName := flag.String("internal-name", "", "StringFileInfo.InternalName") - flagCopyright := flag.String("copyright", "", "StringFileInfo.LegalCopyright") - flagTrademark := flag.String("trademark", "", "StringFileInfo.LegalTrademarks") - flagOriginalName := flag.String("original-name", "", "StringFileInfo.OriginalFilename") - flagPrivateBuild := flag.String("private-build", "", "StringFileInfo.PrivateBuild") - flagProductName := flag.String("product-name", "", "StringFileInfo.ProductName") - flagProductVersion := flag.String("product-version", "", "StringFileInfo.ProductVersion") - flagSpecialBuild := flag.String("special-build", "", "StringFileInfo.SpecialBuild") - - flagTranslation := flag.Int("translation", 0, "translation ID") - flagCharset := flag.Int("charset", 0, "charset ID") - - flag64 := flag.Bool("64", false, "generate 64-bit binaries") - flagarm := flag.Bool("arm", false, "generate arm binaries") - - flagVerMajor := flag.Int("ver-major", -1, "FileVersion.Major") - flagVerMinor := flag.Int("ver-minor", -1, "FileVersion.Minor") - flagVerPatch := flag.Int("ver-patch", -1, "FileVersion.Patch") - flagVerBuild := flag.Int("ver-build", -1, "FileVersion.Build") - - flagProductVerMajor := flag.Int("product-ver-major", -1, "ProductVersion.Major") - flagProductVerMinor := flag.Int("product-ver-minor", -1, "ProductVersion.Minor") - flagProductVerPatch := flag.Int("product-ver-patch", -1, "ProductVersion.Patch") - flagProductVerBuild := flag.Int("product-ver-build", -1, "ProductVersion.Build") - - flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: %s [flags] \n\nPossible flags:\n", os.Args[0]) - flag.PrintDefaults() - } - flag.Parse() - if *flagExample { - io.WriteString(os.Stdout, example) - return - } - - configFile := flag.Arg(0) - if configFile == "" { - configFile = "versioninfo.json" - } - - // Create a new container. - vi := &goversioninfo.VersionInfo{} - - if !*flagSkipVersion { - var err error - var input = io.ReadCloser(os.Stdin) - if configFile != "-" { - if input, err = os.Open(configFile); err != nil { - log.Printf("Cannot open %q: %v", configFile, err) - os.Exit(1) - } - } - - // Read the config file. - jsonBytes, err := io.ReadAll(input) - input.Close() - if err != nil { - log.Printf("Error reading %q: %v", configFile, err) - os.Exit(1) - } - - // Parse the config. - if err := vi.ParseJSON(jsonBytes); err != nil { - log.Printf("Could not parse the .json file: %v", err) - os.Exit(2) - } - - } - - // Override from flags. - if *flagIcon != "" { - vi.IconPath = *flagIcon - } - if *flagManifest != "" { - vi.ManifestPath = *flagManifest - } - if *flagComment != "" { - vi.StringFileInfo.Comments = *flagComment - } - if *flagCompany != "" { - vi.StringFileInfo.CompanyName = *flagCompany - } - if *flagDescription != "" { - vi.StringFileInfo.FileDescription = *flagDescription - } - if *flagFileVersion != "" { - vi.StringFileInfo.FileVersion = *flagFileVersion - } - if *flagInternalName != "" { - vi.StringFileInfo.InternalName = *flagInternalName - } - if *flagCopyright != "" { - vi.StringFileInfo.LegalCopyright = *flagCopyright - } - if *flagTrademark != "" { - vi.StringFileInfo.LegalTrademarks = *flagTrademark - } - if *flagOriginalName != "" { - vi.StringFileInfo.OriginalFilename = *flagOriginalName - } - if *flagPrivateBuild != "" { - vi.StringFileInfo.PrivateBuild = *flagPrivateBuild - } - if *flagProductName != "" { - vi.StringFileInfo.ProductName = *flagProductName - } - if *flagProductVersion != "" { - vi.StringFileInfo.ProductVersion = *flagProductVersion - } - if *flagSpecialBuild != "" { - vi.StringFileInfo.SpecialBuild = *flagSpecialBuild - } - - if *flagTranslation > 0 { - vi.VarFileInfo.Translation.LangID = goversioninfo.LangID(*flagTranslation) - } - if *flagCharset > 0 { - vi.VarFileInfo.Translation.CharsetID = goversioninfo.CharsetID(*flagCharset) - } - - // File Version flags. - if *flagVerMajor >= 0 { - vi.FixedFileInfo.FileVersion.Major = *flagVerMajor - } - if *flagVerMinor >= 0 { - vi.FixedFileInfo.FileVersion.Minor = *flagVerMinor - } - if *flagVerPatch >= 0 { - vi.FixedFileInfo.FileVersion.Patch = *flagVerPatch - } - if *flagVerBuild >= 0 { - vi.FixedFileInfo.FileVersion.Build = *flagVerBuild - } - - // Product Version flags. - if *flagProductVerMajor >= 0 { - vi.FixedFileInfo.ProductVersion.Major = *flagProductVerMajor - } - if *flagProductVerMinor >= 0 { - vi.FixedFileInfo.ProductVersion.Minor = *flagProductVerMinor - } - if *flagProductVerPatch >= 0 { - vi.FixedFileInfo.ProductVersion.Patch = *flagProductVerPatch - } - if *flagProductVerBuild >= 0 { - vi.FixedFileInfo.ProductVersion.Build = *flagProductVerBuild - } - - // Fill FixedFileInfo versions if needed. - if *flagPropagateVerStrings && vi.StringFileInfo.FileVersion != "" { - v, err := goversioninfo.NewFileVersion(vi.StringFileInfo.FileVersion) - if err != nil { - log.Printf("Unexpected StringFileInfo.FileVersion format: %v", err) - os.Exit(3) - } - vi.FixedFileInfo.FileVersion = v - } - if *flagPropagateVerStrings && vi.StringFileInfo.ProductVersion != "" { - v, err := goversioninfo.NewFileVersion(vi.StringFileInfo.ProductVersion) - if err != nil { - log.Printf("Unexpected StringFileInfo.ProductVersion format: %v", err) - os.Exit(3) - } - vi.FixedFileInfo.ProductVersion = v - } - - // Fill the structures with config data. - vi.Build() - - // Write the data to a buffer. - vi.Walk() - - // If the flag is set, then generate the optional Go file. - if *flagGo != "" { - vi.WriteGo(*flagGo, *flagPackage) - } - - // List of the architectures to output. - var archs []string - - // If platform specific, then output all the architectures for Windows. - if flagPlatformSpecific != nil && *flagPlatformSpecific { - archs = []string{"386", "amd64", "arm", "arm64"} - } else { - // Set the architecture, defaulted to 386(32-bit x86). - archs = []string{"386"} // 386(32-bit x86) - if flagarm != nil && *flagarm { - if flag64 != nil && *flag64 { - archs = []string{"arm64"} // arm64(64-bit arm64) - } else { - archs = []string{"arm"} // arm(32-bit arm) - } - } else { - if flag64 != nil && *flag64 { - archs = []string{"amd64"} // amd64(64-bit x86_64) - } - } - - } - - // Loop through each artchitecture. - for _, item := range archs { - // Create the file using the -o argument. - fileout := *flagOut - - // If the number of architectures is greater than one, then don't use - // the -o argument. - if len(archs) > 1 { - fileout = fmt.Sprintf("resource_windows_%v.syso", item) - } - - // Create the file for the specified architecture. - if err := vi.WriteSyso(fileout, item); err != nil { - log.Printf("Error writing syso: %v", err) - os.Exit(3) - } - } -} - -const example = `{ - "FixedFileInfo": { - "FileVersion": { - "Major": 6, - "Minor": 3, - "Patch": 9600, - "Build": 17284 - }, - "ProductVersion": { - "Major": 6, - "Minor": 3, - "Patch": 9600, - "Build": 17284 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "Comments": "", - "CompanyName": "Company, Inc.", - "FileDescription": "", - "FileVersion": "6.3.9600.17284 (aaa.140822-1915)", - "InternalName": "goversioninfo", - "LegalCopyright": "© Author. Licensed under MIT.", - "LegalTrademarks": "", - "OriginalFilename": "goversioninfo", - "PrivateBuild": "", - "ProductName": "Go Version Info", - "ProductVersion": "6.3.9600.17284", - "SpecialBuild": "" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - } -}` diff --git a/vendor/github.com/josephspurrier/goversioninfo/goversioninfo.go b/vendor/github.com/josephspurrier/goversioninfo/goversioninfo.go deleted file mode 100644 index 08b9932879..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/goversioninfo.go +++ /dev/null @@ -1,362 +0,0 @@ -// Package goversioninfo creates a syso file which contains Microsoft Version Information and an optional icon. -package goversioninfo - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "log" - "os" - "reflect" - "regexp" - "strconv" - "strings" - - "github.com/akavel/rsrc/binutil" - "github.com/akavel/rsrc/coff" -) - -// ***************************************************************************** -// JSON and Config -// ***************************************************************************** - -// ParseJSON parses the given bytes as a VersionInfo JSON. -func (vi *VersionInfo) ParseJSON(jsonBytes []byte) error { - return json.Unmarshal([]byte(jsonBytes), &vi) -} - -// VersionInfo data container -type VersionInfo struct { - FixedFileInfo `json:"FixedFileInfo"` - StringFileInfo `json:"StringFileInfo"` - VarFileInfo `json:"VarFileInfo"` - Timestamp bool - Buffer bytes.Buffer - Structure VSVersionInfo - IconPath string `json:"IconPath"` - ManifestPath string `json:"ManifestPath"` -} - -// Translation with langid and charsetid. -type Translation struct { - LangID `json:"LangID"` - CharsetID `json:"CharsetID"` -} - -// FileVersion with 3 parts. -type FileVersion struct { - Major int - Minor int - Patch int - Build int -} - -// FixedFileInfo contains file characteristics - leave most of them at the defaults. -type FixedFileInfo struct { - FileVersion `json:"FileVersion"` - ProductVersion FileVersion - FileFlagsMask string - FileFlags string - FileOS string - FileType string - FileSubType string -} - -// VarFileInfo is the translation container. -type VarFileInfo struct { - Translation `json:"Translation"` -} - -// StringFileInfo is what you want to change. -type StringFileInfo struct { - Comments string - CompanyName string - FileDescription string - FileVersion string - InternalName string - LegalCopyright string - LegalTrademarks string - OriginalFilename string - PrivateBuild string - ProductName string - ProductVersion string - SpecialBuild string -} - -// ***************************************************************************** -// Helpers -// ***************************************************************************** - -// SizedReader is a *bytes.Buffer. -type SizedReader struct { - *bytes.Buffer -} - -// Size returns the length of the buffer. -func (s SizedReader) Size() int64 { - return int64(s.Buffer.Len()) -} - -func str2Uint32(s string) uint32 { - if s == "" { - return 0 - } - u, err := strconv.ParseUint(s, 16, 32) - if err != nil { - log.Printf("Error parsing %q as uint32: %v", s, err) - return 0 - } - - return uint32(u) -} - -func padString(s string, zeros int) []byte { - b := make([]byte, 0, len([]rune(s))*2) - for _, x := range s { - tt := int32(x) - - b = append(b, byte(tt)) - if tt > 255 { - tt = tt >> 8 - b = append(b, byte(tt)) - } else { - b = append(b, byte(0)) - } - } - - for i := 0; i < zeros; i++ { - b = append(b, 0x00) - } - - return b -} - -func padBytes(i int) []byte { - return make([]byte, i) -} - -// NewFileVersion parses semver version string into a FileVersion object -func NewFileVersion(version string) (FileVersion, error) { - re := regexp.MustCompile(`^(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?`) - - comps := re.FindStringSubmatch(version) - if len(comps) == 0 { - return FileVersion{}, fmt.Errorf("version expected to start from x.y.z") - } - - // First match group is a whole matched string. - comps = comps[1:] - if comps[3] == "" { - comps = comps[:3] - } - - nums := make([]int, len(comps)) - for i := range nums { - n, err := strconv.Atoi(comps[i]) - if err != nil { - return FileVersion{}, fmt.Errorf("%s: %s", comps[i], err) - } - nums[i] = n - } - - res := FileVersion{ - Major: nums[0], - Minor: nums[1], - Patch: nums[2], - } - if len(nums) == 4 { - res.Build = nums[3] - } - return res, nil -} - -func (f FileVersion) getVersionHighString() string { - return fmt.Sprintf("%04x%04x", f.Major, f.Minor) -} - -func (f FileVersion) getVersionLowString() string { - return fmt.Sprintf("%04x%04x", f.Patch, f.Build) -} - -// GetVersionString returns a string representation of the version -func (f FileVersion) GetVersionString() string { - return fmt.Sprintf("%d.%d.%d.%d", f.Major, f.Minor, f.Patch, f.Build) -} - -func (t Translation) getTranslationString() string { - return fmt.Sprintf("%04X%04X", t.LangID, t.CharsetID) -} - -func (t Translation) getTranslation() string { - return fmt.Sprintf("%04x%04x", t.CharsetID, t.LangID) -} - -// ***************************************************************************** -// IO Methods -// ***************************************************************************** - -// Walk writes the data buffer with hexadecimal data from the structs -func (vi *VersionInfo) Walk() { - // Create a buffer - var b bytes.Buffer - w := binutil.Writer{W: &b} - - // Write to the buffer - binutil.Walk(vi.Structure, func(v reflect.Value, path string) error { - if binutil.Plain(v.Kind()) { - w.WriteLE(v.Interface()) - } - return nil - }) - - vi.Buffer = b -} - -// WriteSyso creates a resource file from the version info and optionally an icon. -// arch must be an architecture string accepted by coff.Arch, like "386" or "amd64" -func (vi *VersionInfo) WriteSyso(filename string, arch string) error { - - var i uint16 - newID := func() uint16 { - i++ - return i - } - - // Create a new RSRC section - rsrc := coff.NewRSRC() - - // Set the architecture - err := rsrc.Arch(arch) - if err != nil { - return err - } - - // ID 16 is for Version Information - rsrc.AddResource(16, 1, SizedReader{bytes.NewBuffer(vi.Buffer.Bytes())}) - - // If manifest is enabled - if vi.ManifestPath != "" { - - manifest, err := binutil.SizedOpen(vi.ManifestPath) - if err != nil { - return err - } - defer manifest.Close() - - id := newID() - rsrc.AddResource(rtManifest, id, manifest) - } - - // If icon is enabled - if vi.IconPath != "" { - if err := addIcon(rsrc, vi.IconPath, newID); err != nil { - return err - } - } - - rsrc.Freeze() - - // Write to file - return writeCoff(rsrc, filename) -} - -// WriteHex creates a hex file for debugging version info -func (vi *VersionInfo) WriteHex(filename string) error { - return os.WriteFile(filename, vi.Buffer.Bytes(), 0655) -} - -// WriteGo creates a Go file that contains the version info so you can access -// it in the application -func (vi *VersionInfo) WriteGo(filename, packageName string) error { - if len(packageName) == 0 { - packageName = "main" - } - - out, err := os.Create(filename) - if err != nil { - return err - } - - ffib, err := json.MarshalIndent(vi.FixedFileInfo, "\t", "\t") - if err != nil { - return err - } - - sfib, err := json.MarshalIndent(vi.StringFileInfo, "\t", "\t") - if err != nil { - return err - } - - vfib, err := json.MarshalIndent(vi.VarFileInfo, "\t", "\t") - if err != nil { - return err - } - - replace := "`\" + \"`\" + \"`" - str := "`{\n\t" - str += `"FixedFileInfo":` - str += strings.Replace(string(ffib), "`", replace, -1) - str += ",\n\t" - str += `"StringFileInfo":` - str += strings.Replace(string(sfib), "`", replace, -1) - str += ",\n\t" - str += `"VarFileInfo":` - str += strings.Replace(string(vfib), "`", replace, -1) - str += "\n" - str += "}`" - fmt.Fprintf(out, `// Auto-generated file by goversioninfo. Do not edit. -package %v - -import ( - "encoding/json" - - "github.com/josephspurrier/goversioninfo" -) - -func unmarshalGoVersionInfo(b []byte) goversioninfo.VersionInfo { - vi := goversioninfo.VersionInfo{} - json.Unmarshal(b, &vi) - return vi -} - -var versionInfo = unmarshalGoVersionInfo([]byte(%v)) -`, packageName, string(str)) - - return nil -} - -func writeCoff(coff *coff.Coff, fnameout string) error { - out, err := os.Create(fnameout) - if err != nil { - return err - } - if err = writeCoffTo(out, coff); err != nil { - return fmt.Errorf("error writing %q: %v", fnameout, err) - } - return nil -} - -func writeCoffTo(w io.WriteCloser, coff *coff.Coff) error { - bw := binutil.Writer{W: w} - - // write the resulting file to disk - binutil.Walk(coff, func(v reflect.Value, path string) error { - if binutil.Plain(v.Kind()) { - bw.WriteLE(v.Interface()) - return nil - } - vv, ok := v.Interface().(binutil.SizedReader) - if ok { - bw.WriteFromSized(vv) - return binutil.WALK_SKIP - } - return nil - }) - - err := bw.Err - if closeErr := w.Close(); closeErr != nil && err == nil { - err = closeErr - } - return err -} diff --git a/vendor/github.com/josephspurrier/goversioninfo/icon.go b/vendor/github.com/josephspurrier/goversioninfo/icon.go deleted file mode 100644 index 2d1681d611..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/icon.go +++ /dev/null @@ -1,121 +0,0 @@ -package goversioninfo - -import ( - "bytes" - "encoding/binary" - "fmt" - "os" - "strings" - - "github.com/akavel/rsrc/coff" - "github.com/akavel/rsrc/ico" -) - -// ***************************************************************************** -/* -Code from https://github.com/akavel/rsrc - -The MIT License (MIT) - -Copyright (c) 2013-2014 The rsrc Authors. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -// ***************************************************************************** - -const ( - rtIcon = coff.RT_ICON - rtGroupIcon = coff.RT_GROUP_ICON - rtManifest = coff.RT_MANIFEST -) - -// on storing icons, see: http://blogs.msdn.com/b/oldnewthing/archive/2012/07/20/10331787.aspx -type gRPICONDIR struct { - ico.ICONDIR - Entries []gRPICONDIRENTRY -} - -func (group gRPICONDIR) Size() int64 { - return int64(binary.Size(group.ICONDIR) + len(group.Entries)*binary.Size(group.Entries[0])) -} - -type gRPICONDIRENTRY struct { - ico.IconDirEntryCommon - ID uint16 -} - -func addIcon(coff *coff.Coff, fnames string, newID func() uint16) error { - for { - var fname1 string - var ok bool - fname1, fnames, ok = strings.Cut(fnames, ",") - if fname1 != "" { - if err := addOneIcon(coff, fname1, newID); err != nil { - return fmt.Errorf("%s: %w", fname1, err) - } - } - if !ok { - return nil - } - } -} - -func addOneIcon(coff *coff.Coff, fname string, newID func() uint16) error { - f, err := os.Open(fname) - if err != nil { - return err - } - defer f.Close() - - icons, err := ico.DecodeHeaders(f) - if err != nil { - return err - } - - if len(icons) > 0 { - // RT_ICONs - group := gRPICONDIR{ICONDIR: ico.ICONDIR{ - Reserved: 0, // magic num. - Type: 1, // magic num. - Count: uint16(len(icons)), - }} - gid := newID() - for _, icon := range icons { - id := newID() - buff, err := bufferIcon(f, int64(icon.ImageOffset), int(icon.BytesInRes)) - if err != nil { - return err - } - coff.AddResource(rtIcon, id, buff) - group.Entries = append(group.Entries, gRPICONDIRENTRY{IconDirEntryCommon: icon.IconDirEntryCommon, ID: id}) - } - coff.AddResource(rtGroupIcon, gid, group) - } - - return nil -} - -func bufferIcon(f *os.File, offset int64, size int) (*bytes.Reader, error) { - data := make([]byte, size) - _, err := f.ReadAt(data, offset) - if err != nil { - return nil, err - } - return bytes.NewReader(data), nil -} diff --git a/vendor/github.com/josephspurrier/goversioninfo/lang_cs.go b/vendor/github.com/josephspurrier/goversioninfo/lang_cs.go deleted file mode 100644 index 554c9fbf50..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/lang_cs.go +++ /dev/null @@ -1,131 +0,0 @@ -// Contribution by Tamás Gulácsi - -package goversioninfo - -import ( - "encoding/json" - "strconv" -) - -// CharsetID must use be a character-set identifier from: -// https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx#charsetID -type CharsetID uint16 - -// CharsetID constants -const ( - Cs7ASCII = CharsetID(0) // Cs7ASCII: 0 0000 7-bit ASCII - CsJIS = CharsetID(932) // CsJIS: 932 03A4 Japan (Shift ? JIS X-0208) - CsKSC = CharsetID(949) // CsKSC: 949 03B5 Korea (Shift ? KSC 5601) - CsBig5 = CharsetID(950) // CsBig5: 950 03B6 Taiwan (Big5) - CsUnicode = CharsetID(1200) // CsUnicode: 1200 04B0 Unicode - CsLatin2 = CharsetID(1250) // CsLatin2: 1250 04E2 Latin-2 (Eastern European) - CsCyrillic = CharsetID(1251) // CsCyrillic: 1251 04E3 Cyrillic - CsMultilingual = CharsetID(1252) // CsMultilingual: 1252 04E4 Multilingual - CsGreek = CharsetID(1253) // CsGreek: 1253 04E5 Greek - CsTurkish = CharsetID(1254) // CsTurkish: 1254 04E6 Turkish - CsHebrew = CharsetID(1255) // CsHebrew: 1255 04E7 Hebrew - CsArabic = CharsetID(1256) // CsArabic: 1256 04E8 Arabic -) - -// UnmarshalJSON converts the string to a CharsetID -func (cs *CharsetID) UnmarshalJSON(p []byte) error { - if len(p) == 0 { - return nil - } - if p[0] != '"' { - var u uint16 - if err := json.Unmarshal(p, &u); err != nil { - return err - } - *cs = CharsetID(u) - return nil - } - var s string - if err := json.Unmarshal(p, &s); err != nil { - return err - } - u, err := strconv.ParseUint(s, 16, 16) - if err != nil { - return err - } - *cs = CharsetID(u) - return nil -} - -// LangID must use be a character-set identifier from: -// https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx#langID -type LangID uint16 - -// UnmarshalJSON converts the string to a LangID -func (lng *LangID) UnmarshalJSON(p []byte) error { - if len(p) == 0 { - return nil - } - if p[0] != '"' { - var u uint16 - if err := json.Unmarshal(p, &u); err != nil { - return err - } - *lng = LangID(u) - return nil - } - var s string - if err := json.Unmarshal(p, &s); err != nil { - return err - } - u, err := strconv.ParseUint(s, 16, 16) - if err != nil { - return err - } - *lng = LangID(u) - return nil -} - -// LangID constants -const ( - LngArabic = LangID(0x0401) // LngArabic: 0x0401 Arabic - LngBulgarian = LangID(0x0402) // LngBulgarian: 0x0402 Bulgarian - LngCatalan = LangID(0x0403) // LngCatalan: 0x0403 Catalan - LngTraditionalChinese = LangID(0x0404) // LngTraditionalChinese: 0x0404 Traditional Chinese - LngCzech = LangID(0x0405) // LngCzech: 0x0405 Czech - LngDanish = LangID(0x0406) // LngDanish: 0x0406 Danish - LngGerman = LangID(0x0407) // LngGerman: 0x0407 German - LngGreek = LangID(0x0408) // LngGreek: 0x0408 Greek - LngUSEnglish = LangID(0x0409) // LngUSEnglish: 0x0409 U.S. English - LngCastilianSpanish = LangID(0x040A) // LngCastilianSpanish: 0x040A Castilian Spanish - LngFinnish = LangID(0x040B) // LngFinnish: 0x040B Finnish - LngFrench = LangID(0x040C) // LngFrench: 0x040C French - LngHebrew = LangID(0x040D) // LngHebrew: 0x040D Hebrew - LngHungarian = LangID(0x040E) // LngHungarian: 0x040E Hungarian - LngIcelandic = LangID(0x040F) // LngIcelandic: 0x040F Icelandic - LngItalian = LangID(0x0410) // LngItalian: 0x0410 Italian - LngJapanese = LangID(0x0411) // LngJapanese: 0x0411 Japanese - LngKorean = LangID(0x0412) // LngKorean: 0x0412 Korean - LngDutch = LangID(0x0413) // LngDutch: 0x0413 Dutch - LngNorwegianBokmal = LangID(0x0414) // LngNorwegianBokmal: 0x0414 Norwegian ? Bokmal - LngPolish = LangID(0x0415) // LngPolish: 0x0415 Polish - LngPortugueseBrazil = LangID(0x0416) // LngPortugueseBrazil: 0x0416 Portuguese (Brazil) - LngRhaetoRomanic = LangID(0x0417) // LngRhaetoRomanic: 0x0417 Rhaeto-Romanic - LngRomanian = LangID(0x0418) // LngRomanian: 0x0418 Romanian - LngRussian = LangID(0x0419) // LngRussian: 0x0419 Russian - LngCroatoSerbianLatin = LangID(0x041A) // LngCroatoSerbianLatin: 0x041A Croato-Serbian (Latin) - LngSlovak = LangID(0x041B) // LngSlovak: 0x041B Slovak - LngAlbanian = LangID(0x041C) // LngAlbanian: 0x041C Albanian - LngSwedish = LangID(0x041D) // LngSwedish: 0x041D Swedish - LngThai = LangID(0x041E) // LngThai: 0x041E Thai - LngTurkish = LangID(0x041F) // LngTurkish: 0x041F Turkish - LngUrdu = LangID(0x0420) // LngUrdu: 0x0420 Urdu - LngBahasa = LangID(0x0421) // LngBahasa: 0x0421 Bahasa - LngSimplifiedChinese = LangID(0x0804) // LngSimplifiedChinese: 0x0804 Simplified Chinese - LngSwissGerman = LangID(0x0807) // LngSwiss German: 0x0807 Swiss German - LngUKEnglish = LangID(0x0809) // LngUKEnglish: 0x0809 U.K. English - LngSpanishMexico = LangID(0x080A) // LngSpanishMexico: 0x080A Spanish (Mexico) - LngBelgianFrench = LangID(0x080C) // LngBelgian French: 0x080C Belgian French - LngSwissItalian = LangID(0x0810) // LngSwiss Italian: 0x0810 Swiss Italian - LngBelgianDutch = LangID(0x0813) // LngBelgian Dutch: 0x0813 Belgian Dutch - LngNorwegianNynorsk = LangID(0x0814) // LngNorwegianNynorsk: 0x0814 Norwegian ? Nynorsk - LngPortuguesePortugal = LangID(0x0816) // LngPortuguese (Portugal): 0x0816 Portuguese (Portugal) - LngSerboCroatianCyrillic = LangID(0x081A) // LngSerboCroatianCyrillic: 0x081A Serbo-Croatian (Cyrillic) - LngCanadianFrench = LangID(0x0C0C) // LngCanadian French: 0x0C0C Canadian French - LngSwissFrench = LangID(0x100C) // LngSwiss French: 0x100C Swiss French -) diff --git a/vendor/github.com/josephspurrier/goversioninfo/structbuild.go b/vendor/github.com/josephspurrier/goversioninfo/structbuild.go deleted file mode 100644 index e5f9d8033a..0000000000 --- a/vendor/github.com/josephspurrier/goversioninfo/structbuild.go +++ /dev/null @@ -1,330 +0,0 @@ -package goversioninfo - -import ( - "reflect" -) - -// ***************************************************************************** -// Structure Building -// ***************************************************************************** - -/* -Version Information Structures -http://msdn.microsoft.com/en-us/library/windows/desktop/ff468916.aspx - -VersionInfo Names -http://msdn.microsoft.com/en-us/library/windows/desktop/aa381058.aspx#string-name - -Translation: LangID -http://msdn.microsoft.com/en-us/library/windows/desktop/aa381058.aspx#langid - -Translation: CharsetID -http://msdn.microsoft.com/en-us/library/windows/desktop/aa381058.aspx#charsetid - -*/ - -// VSVersionInfo is the top level version container. -type VSVersionInfo struct { - WLength uint16 - WValueLength uint16 - WType uint16 - SzKey []byte - Padding1 []byte - Value VSFixedFileInfo - Padding2 []byte - Children VSStringFileInfo - Children2 VSVarFileInfo -} - -// VSFixedFileInfo - most of these should be left at the defaults. -type VSFixedFileInfo struct { - DwSignature uint32 - DwStrucVersion uint32 - DwFileVersionMS uint32 - DwFileVersionLS uint32 - DwProductVersionMS uint32 - DwProductVersionLS uint32 - DwFileFlagsMask uint32 - DwFileFlags uint32 - DwFileOS uint32 - DwFileType uint32 - DwFileSubtype uint32 - DwFileDateMS uint32 - DwFileDateLS uint32 -} - -// VSStringFileInfo holds multiple collections of keys and values, -// only allows for 1 collection in this package. -type VSStringFileInfo struct { - WLength uint16 - WValueLength uint16 - WType uint16 - SzKey []byte - Padding []byte - Children VSStringTable -} - -// VSStringTable holds a collection of string keys and values. -type VSStringTable struct { - WLength uint16 - WValueLength uint16 - WType uint16 - SzKey []byte - Padding []byte - Children []VSString -} - -// VSString holds the keys and values. -type VSString struct { - WLength uint16 - WValueLength uint16 - WType uint16 - SzKey []byte - Padding []byte - Value []byte -} - -// VSVarFileInfo holds the translation collection of 1. -type VSVarFileInfo struct { - WLength uint16 - WValueLength uint16 - WType uint16 - SzKey []byte - Padding []byte - Value VSVar -} - -// VSVar holds the translation key. -type VSVar struct { - WLength uint16 - WValueLength uint16 - WType uint16 - SzKey []byte - Padding []byte - Value uint32 -} - -func buildString(i int, v reflect.Value) (VSString, bool) { - sValue := string(v.Field(i).Interface().(string)) - sName := v.Type().Field(i).Name - - ss := VSString{} - - // If the value is set - if sValue != "" { - // 0 for binary, 1 for text - ss.WType = 0x01 - - // Create key - ss.SzKey = padString(sName, 0) - - // Align to 32-bit boundary - soFar := 2 - for (len(ss.SzKey)+6+soFar)%4 != 0 { - soFar += 2 - } - ss.Padding = padBytes(soFar) - soFar += len(ss.SzKey) - - // Align zeros to 32-bit boundary - zeros := 2 - for (6+soFar+(len(padString(sValue, 0)))+zeros)%4 != 0 { - zeros += 2 - } - - // Create value - ss.Value = padString(sValue, zeros) - - // Length of text in words (2 bytes) plus zero terminate word - ss.WValueLength = uint16(len(padString(sValue, 0))/2) + 1 - - // Length of structure - //ss.WLength = 6 + uint16(soFar) + (ss.WValueLength * 2) - ss.WLength = uint16(6 + soFar + len(ss.Value)) - - return ss, true - } - - return ss, false -} - -func buildStringTable(vi *VersionInfo) VSStringTable { - st := VSStringTable{} - - // Always set to 0 - st.WValueLength = 0x00 - - // 0 for binary, 1 for text - st.WType = 0x01 - - // Language identifier and Code page - st.SzKey = padString(vi.VarFileInfo.Translation.getTranslationString(), 0) - - // Align to 32-bit boundary - soFar := 2 - for (len(st.SzKey)+6+soFar)%4 != 0 { - soFar += 2 - } - st.Padding = padBytes(soFar) - soFar += len(st.SzKey) - - // Loop through the struct fields - v := reflect.ValueOf(vi.StringFileInfo) - for i := 0; i < v.NumField(); i++ { - // If the struct is valid - if r, ok := buildString(i, v); ok { - st.Children = append(st.Children, r) - st.WLength += r.WLength - } - } - - st.WLength += 6 + uint16(soFar) - - return st -} - -func buildStringFileInfo(vi *VersionInfo) VSStringFileInfo { - sf := VSStringFileInfo{} - - // Always set to 0 - sf.WValueLength = 0x00 - - // 0 for binary, 1 for text - sf.WType = 0x01 - - sf.SzKey = padString("StringFileInfo", 0) - - // Align to 32-bit boundary - soFar := 2 - for (len(sf.SzKey)+6+soFar)%4 != 0 { - soFar += 2 - } - sf.Padding = padBytes(soFar) - soFar += len(sf.SzKey) - - // Allows for more than one string table - st := buildStringTable(vi) - sf.Children = st - - sf.WLength = 6 + uint16(soFar) + st.WLength - - return sf -} - -func buildVar(vfi VarFileInfo) VSVar { - vs := VSVar{} - - // 0 for binary, 1 for text - vs.WType = 0x00 - - // Create key - vs.SzKey = padString("Translation", 0) - - // Align to 32-bit boundary - soFar := 2 - for (len(vs.SzKey)+6+soFar)%4 != 0 { - soFar += 2 - } - vs.Padding = padBytes(soFar) - soFar += len(vs.SzKey) - - // Create value - vs.Value = str2Uint32(vfi.Translation.getTranslation()) - - // Length of text in bytes - vs.WValueLength = 4 - - // Length of structure - vs.WLength = 6 + vs.WValueLength + uint16(soFar) - - return vs -} - -func buildVarFileInfo(vfi VarFileInfo) VSVarFileInfo { - vf := VSVarFileInfo{} - - // Always set to 0 - vf.WValueLength = 0x00 - - // 0 for binary, 1 for text - vf.WType = 0x01 - - vf.SzKey = padString("VarFileInfo", 0) - - // Align to 32-bit boundary - soFar := 2 - for (len(vf.SzKey)+6+soFar)%4 != 0 { - soFar += 2 - } - vf.Padding = padBytes(soFar) - soFar += len(vf.SzKey) - - // TODO Allow for more than one var table - st := buildVar(vfi) - vf.Value = st - vf.WLength = 6 + st.WLength + uint16(soFar) - - return vf -} - -func buildFixedFileInfo(vi *VersionInfo) VSFixedFileInfo { - ff := VSFixedFileInfo{} - ff.DwSignature = 0xFEEF04BD - ff.DwStrucVersion = 0x00010000 - ff.DwFileVersionMS = str2Uint32(vi.FixedFileInfo.FileVersion.getVersionHighString()) - ff.DwFileVersionLS = str2Uint32(vi.FixedFileInfo.FileVersion.getVersionLowString()) - ff.DwProductVersionMS = str2Uint32(vi.FixedFileInfo.ProductVersion.getVersionHighString()) - ff.DwProductVersionLS = str2Uint32(vi.FixedFileInfo.ProductVersion.getVersionLowString()) - ff.DwFileFlagsMask = str2Uint32(vi.FixedFileInfo.FileFlagsMask) - ff.DwFileFlags = str2Uint32(vi.FixedFileInfo.FileFlags) - ff.DwFileOS = str2Uint32(vi.FixedFileInfo.FileOS) - ff.DwFileType = str2Uint32(vi.FixedFileInfo.FileType) - ff.DwFileSubtype = str2Uint32(vi.FixedFileInfo.FileSubType) - - // According to the spec, these should be zero...ugh - /*if vi.Timestamp { - now := syscall.NsecToFiletime(time.Now().UnixNano()) - ff.DwFileDateMS = now.HighDateTime - ff.DwFileDateLS = now.LowDateTime - }*/ - - return ff -} - -// Build fills the structs with data from the config file -func (v *VersionInfo) Build() { - vi := VSVersionInfo{} - - // 0 for binary, 1 for text - vi.WType = 0x00 - - vi.SzKey = padString("VS_VERSION_INFO", 0) - - // Align to 32-bit boundary - // 6 is for the size of WLength, WValueLength, and WType (each is 1 word or 2 bytes: FF FF) - soFar := 2 - for (len(vi.SzKey)+6+soFar)%4 != 0 { - soFar += 2 - } - vi.Padding1 = padBytes(soFar) - soFar += len(vi.SzKey) - - vi.Value = buildFixedFileInfo(v) - - // Length of VSFixedFileInfo (always the same) - vi.WValueLength = 0x34 - - // Never needs padding, not included in WLength - vi.Padding2 = []byte{} - - // Build strings - vi.Children = buildStringFileInfo(v) - - // Build translation - vi.Children2 = buildVarFileInfo(v.VarFileInfo) - - // Calculate the total size - vi.WLength += 6 + uint16(soFar) + vi.WValueLength + vi.Children.WLength + vi.Children2.WLength - - v.Structure = vi -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 42cbba483d..c9d971c854 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -31,11 +31,6 @@ github.com/OneOfOne/xxhash # github.com/agnivade/levenshtein v1.2.0 ## explicit; go 1.21 github.com/agnivade/levenshtein -# github.com/akavel/rsrc v0.10.2 -## explicit; go 1.12 -github.com/akavel/rsrc/binutil -github.com/akavel/rsrc/coff -github.com/akavel/rsrc/ico # github.com/beorn7/perks v1.0.1 ## explicit; go 1.11 github.com/beorn7/perks/quantile @@ -277,10 +272,6 @@ github.com/google/uuid # github.com/gorilla/mux v1.8.1 ## explicit; go 1.20 github.com/gorilla/mux -# github.com/josephspurrier/goversioninfo v1.5.0 -## explicit; go 1.18 -github.com/josephspurrier/goversioninfo -github.com/josephspurrier/goversioninfo/cmd/goversioninfo # github.com/klauspost/compress v1.18.5 ## explicit; go 1.24 github.com/klauspost/compress