Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 13a0ed1

Browse files
simonferquelDavid Chung
authored andcommitted
Make Infrakit build on Windows (even if not functional) (#687)
Signed-off-by: Simon Ferquel <[email protected]>
1 parent 084ff32 commit 13a0ed1

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,23 @@ ci: fmt vet lint check-docs coverage e2e-test
2929
AUTHORS: .mailmap .git/HEAD
3030
git log --format='%aN <%aE>' | sort -fu > $@
3131

32+
# Handle file extension suffix (for Windows)
33+
EXE_EXT:=
34+
ifeq ($(OS),Windows_NT)
35+
EXE_EXT:=.exe
36+
endif
37+
3238
# Package list
3339
PKGS_AND_MOCKS := $(shell go list ./... | grep -v /vendor)
40+
ifeq ($(OS),Windows_NT)
41+
# skip libvirt instance plugin on Windows (does not compile)
42+
PKGS_AND_MOCKS := $(shell echo $(PKGS_AND_MOCKS) | tr ' ' '\n' | grep -v libvirt)
43+
endif
3444
PKGS := $(shell echo $(PKGS_AND_MOCKS) | tr ' ' '\n' | grep -v /mock$)
3545
PKGS_TEST := $(shell echo $(PKGS_AND_MOCKS) | tr ' ' '\n' | grep pkg$)
3646

47+
48+
3749
get-tools:
3850
@echo "+ $@"
3951
@go get -u \
@@ -76,7 +88,7 @@ clean:
7688

7789
define binary_target_template
7890
build/$(1): $(SRCS)
79-
go build -o build/$(1) \
91+
go build -o build/$(1)$(EXE_EXT) \
8092
-ldflags "-X github.com/docker/infrakit/pkg/cli.Version=$(VERSION) -X github.com/docker/infrakit/pkg/cli.Revision=$(REVISION) -X github.com/docker/infrakit/pkg/util/docker.ClientVersion=$(DOCKER_CLIENT_VERSION)" $(2)
8193
endef
8294
define define_binary_target
@@ -99,7 +111,12 @@ $(call define_binary_target,infrakit-instance-file,github.com/docker/infrakit/ex
99111
$(call define_binary_target,infrakit-instance-gcp,github.com/docker/infrakit/cmd/instance/google)
100112
$(call define_binary_target,infrakit-instance-hyperkit,github.com/docker/infrakit/cmd/instance/hyperkit)
101113
$(call define_binary_target,infrakit-instance-image,github.com/docker/infrakit/cmd/instance/image)
114+
ifeq ($(OS),Windows_NT)
115+
build/infrakit-instance-libvirt:
116+
# noop on windows
117+
else
102118
$(call define_binary_target,infrakit-instance-libvirt,github.com/docker/infrakit/cmd/instance/libvirt)
119+
endif
103120
$(call define_binary_target,infrakit-instance-maas,github.com/docker/infrakit/examples/instance/maas)
104121
$(call define_binary_target,infrakit-instance-packet,github.com/docker/infrakit/cmd/instance/packet)
105122
$(call define_binary_target,infrakit-instance-terraform,github.com/docker/infrakit/pkg/provider/terraform/instance/cmd)

pkg/launch/os/os_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io/ioutil"
66
"os"
77
"path/filepath"
8+
"runtime"
9+
"strings"
810
"testing"
911
"time"
1012

@@ -14,12 +16,15 @@ import (
1416
)
1517

1618
func TestLaunchOSCommand(t *testing.T) {
17-
19+
sleepCmd := "sleep 100"
20+
if runtime.GOOS == "windows" {
21+
sleepCmd = "timeout 100"
22+
}
1823
launcher, err := NewLauncher("os")
1924
require.NoError(t, err)
2025

2126
_, starting, err := launcher.Exec("sleepPlugin", plugin.Name("sleepPlugin"), types.AnyValueMust(&LaunchConfig{
22-
Cmd: "sleep 100",
27+
Cmd: sleepCmd,
2328
}))
2429
require.NoError(t, err)
2530

@@ -47,5 +52,5 @@ func TestLaunchWithLog(t *testing.T) {
4752

4853
v, err := ioutil.ReadFile(logfile)
4954
require.NoError(t, err)
50-
require.Equal(t, "hello\n", string(v))
55+
require.Equal(t, "hello", strings.TrimSpace(string(v)))
5156
}

pkg/launch/os/os_windows.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package os
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
7+
log "github.com/Sirupsen/logrus"
8+
"github.com/docker/infrakit/pkg/launch"
9+
)
10+
11+
func start(executor launch.Exec, name, sh string, setPgID bool) <-chan error {
12+
block := make(chan error)
13+
14+
go func() {
15+
16+
defer close(block)
17+
18+
log.Infoln("OS(", executor.Name(), ") launcher: Plugin", name, "setPgId=", setPgID, "starting", sh)
19+
cmd := exec.Command("cmd", "/s", "/c", sh)
20+
21+
log.Infoln("Running", cmd.Path, strings.Join(cmd.Args, " "))
22+
23+
err := cmd.Start()
24+
log.Infoln("Starting with", err, "sh=", sh)
25+
if err != nil {
26+
log.Warningln("OS launcher: Plugin", name, "failed to start:", err, "cmd=", sh)
27+
block <- err
28+
}
29+
}()
30+
31+
return block
32+
}

0 commit comments

Comments
 (0)