diff --git a/.gitignore b/.gitignore index 896ffb3ad8..4a65c2279c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .DS_Store -./build +/build/ +cli/winresources/rsrc_386.syso +cli/winresources/rsrc_amd64.syso diff --git a/Makefile b/Makefile index 4b9a71eae8..e1633df737 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: binary # remove build artifacts .PHONY: clean clean: - @rm -rf ./build/* + @rm -rf ./build/* cli/winresources/rsrc_* # run go test # the "-tags daemon" part is temporary diff --git a/cli/winresources/res_windows.go b/cli/winresources/res_windows.go new file mode 100644 index 0000000000..3f755cc4bd --- /dev/null +++ b/cli/winresources/res_windows.go @@ -0,0 +1,18 @@ +/*Package winresources is used to embed Windows resources into docker.exe. +These resources are used to provide + + * Version information + * An icon + * A Windows manifest declaring Windows version support + +The resource object files are generated with go generate. +The resource source files are located in scripts/winresources. +This occurs automatically when you run scripts/build/windows. + +These object files are picked up automatically by go build when this package +is included. + +*/ +package winresources + +//go:generate ../../scripts/gen/windows-resources diff --git a/cmd/docker/docker_autogen_windows.go b/cmd/docker/docker_autogen_windows.go deleted file mode 100644 index 55bfda0812..0000000000 --- a/cmd/docker/docker_autogen_windows.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build autogen,windows - -package main - -// TODO: add build scripts that include the winresources (for docker icon etc.) -// Those scripts will need to specify an autogen buildtag. - -import _ "github.com/docker/cli/autogen/winresources" diff --git a/cmd/docker/docker_windows.go b/cmd/docker/docker_windows.go new file mode 100644 index 0000000000..88ac499486 --- /dev/null +++ b/cmd/docker/docker_windows.go @@ -0,0 +1,3 @@ +package main + +import _ "github.com/docker/cli/cli/winresources" diff --git a/scripts/build/cross b/scripts/build/cross index b9df606fca..51b8024ecb 100755 --- a/scripts/build/cross +++ b/scripts/build/cross @@ -2,7 +2,7 @@ set -eu -o pipefail -export BUILDDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BUILDDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" echo "Building all binaries" SHELL=/bin/bash parallel ::: \ diff --git a/scripts/build/windows b/scripts/build/windows index eccf6d1e57..ea26ab1e82 100755 --- a/scripts/build/windows +++ b/scripts/build/windows @@ -15,6 +15,9 @@ export GOARCH=amd64 # Override TARGET TARGET="build/docker-$GOOS-$GOARCH" +echo "Generating windows resources" +go generate ./cli/winresources + echo "Building $TARGET" # TODO: -tags pkcs11 go build -o "${TARGET}" --ldflags "${LDFLAGS}" "${SOURCE}" diff --git a/scripts/gen/windows-resources b/scripts/gen/windows-resources new file mode 100755 index 0000000000..85f030abab --- /dev/null +++ b/scripts/gen/windows-resources @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# +# Compile the Windows resources into the sources +# + +set -eu -o pipefail + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $SCRIPTDIR/../build/.variables + +RESOURCES=$SCRIPTDIR/../winresources + +TEMPDIR=$(mktemp -d) +trap 'rm -rf $TEMPDIR' EXIT + +if [ "$(go env GOHOSTOS)" == "windows" ]; then + WINDRES=windres + WINDMC=windmc +else + # Cross compiling + WINDRES=x86_64-w64-mingw32-windres + WINDMC=x86_64-w64-mingw32-windmc +fi + +# Generate a Windows file version of the form major,minor,patch,build (with any part optional) +VERSION_QUAD=$(echo -n $VERSION | sed -re 's/^([0-9.]*).*$/\1/' | tr . ,) + +# Pass version and commit information into the resource compiler +defs= +[ ! -z $VERSION ] && defs="$defs -D DOCKER_VERSION=\"$VERSION\"" +[ ! -z $VERSION_QUAD ] && defs="$defs -D DOCKER_VERSION_QUAD=$VERSION_QUAD" +[ ! -z $GITCOMMIT ] && defs="$defs -D DOCKER_COMMIT=\"$GITCOMMIT\"" + +function makeres { + $WINDRES \ + -i $RESOURCES/$1 \ + -o $3 \ + -F $2 \ + --use-temp-file \ + -I $TEMPDIR \ + $defs +} + +$WINDMC $RESOURCES/event_messages.mc -h $TEMPDIR -r $TEMPDIR +makeres docker.rc pe-x86-64 rsrc_amd64.syso +makeres docker.rc pe-i386 rsrc_386.syso diff --git a/scripts/winresources/common.rc b/scripts/winresources/common.rc new file mode 100644 index 0000000000..000fb35367 --- /dev/null +++ b/scripts/winresources/common.rc @@ -0,0 +1,38 @@ +// Application icon +1 ICON "docker.ico" + +// Windows executable manifest +1 24 /* RT_MANIFEST */ "docker.exe.manifest" + +// Version information +1 VERSIONINFO + +#ifdef DOCKER_VERSION_QUAD +FILEVERSION DOCKER_VERSION_QUAD +PRODUCTVERSION DOCKER_VERSION_QUAD +#endif + +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004B0" + BEGIN + VALUE "ProductName", DOCKER_NAME + +#ifdef DOCKER_VERSION + VALUE "FileVersion", DOCKER_VERSION + VALUE "ProductVersion", DOCKER_VERSION +#endif + +#ifdef DOCKER_COMMIT + VALUE "OriginalFileName", DOCKER_COMMIT +#endif + + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0000, 0x04B0 + END +END diff --git a/scripts/winresources/docker.exe.manifest b/scripts/winresources/docker.exe.manifest new file mode 100644 index 0000000000..674bc9422b --- /dev/null +++ b/scripts/winresources/docker.exe.manifest @@ -0,0 +1,18 @@ + + + Docker + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scripts/winresources/docker.ico b/scripts/winresources/docker.ico new file mode 100644 index 0000000000..c6506ec8db Binary files /dev/null and b/scripts/winresources/docker.ico differ diff --git a/scripts/winresources/docker.png b/scripts/winresources/docker.png new file mode 100644 index 0000000000..88df0b66df Binary files /dev/null and b/scripts/winresources/docker.png differ diff --git a/scripts/winresources/docker.rc b/scripts/winresources/docker.rc new file mode 100644 index 0000000000..40c645ad1d --- /dev/null +++ b/scripts/winresources/docker.rc @@ -0,0 +1,3 @@ +#define DOCKER_NAME "Docker Client" + +#include "common.rc" diff --git a/scripts/winresources/event_messages.mc b/scripts/winresources/event_messages.mc new file mode 100644 index 0000000000..980107a44d --- /dev/null +++ b/scripts/winresources/event_messages.mc @@ -0,0 +1,39 @@ +MessageId=1 +Language=English +%1 +. + +MessageId=2 +Language=English +debug: %1 +. + +MessageId=3 +Language=English +panic: %1 +. + +MessageId=4 +Language=English +fatal: %1 +. + +MessageId=11 +Language=English +%1 [%2] +. + +MessageId=12 +Language=English +debug: %1 [%2] +. + +MessageId=13 +Language=English +panic: %1 [%2] +. + +MessageId=14 +Language=English +fatal: %1 [%2] +. diff --git a/scripts/winresources/resources.go b/scripts/winresources/resources.go new file mode 100644 index 0000000000..b171259f83 --- /dev/null +++ b/scripts/winresources/resources.go @@ -0,0 +1,18 @@ +/* + +Package winresources is used to embed Windows resources into docker.exe. +These resources are used to provide + + * Version information + * An icon + * A Windows manifest declaring Windows version support + +The resource object files are generated in hack/make/.go-autogen from +source files in hack/make/.resources-windows. This occurs automatically +when you run hack/make.sh. + +These object files are picked up automatically by go build when this package +is included. + +*/ +package winresources