Skip to content

Commit

Permalink
Adding build constraints
Browse files Browse the repository at this point in the history
Adding windows build constraints to code to allow tests and benchmarks
to be run on Linux.

Added doc.go to modules (with doc string, where appropriate) to prevent
compiler/linter errors about broken imports.
In some cases (ie, winapi and wclayer), the package already had an
OS-agnostic file of the same name, along with a doc string. A doc.go
file was added to preempt situations where windows-specific code is
added to that file in the future.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed Mar 30, 2022
1 parent dfe9b5e commit f371686
Show file tree
Hide file tree
Showing 615 changed files with 1,224 additions and 268 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ rootfs-conv/*
/build/

deps/*
out/*
out/*

go.work
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ clean:
rm -rf bin deps rootfs out

test:
cd $(SRCROOT) && go test -v ./internal/guest/...
cd $(SRCROOT) && $(GO) test -v ./internal/guest/...

rootfs: out/rootfs.vhd

Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/clone.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/delete.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
8 changes: 5 additions & 3 deletions cmd/containerd-shim-runhcs-v1/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ type publisher interface {
}

type eventPublisher struct {
namespace string
remotePublisher *shim.RemoteEventsPublisher
}

var _ = (publisher)(&eventPublisher{})
var _ publisher = &eventPublisher{}

func newEventPublisher(address string) (*eventPublisher, error) {
func newEventPublisher(address, namespace string) (*eventPublisher, error) {
p, err := shim.NewPublisher(address)
if err != nil {
return nil, err
}
return &eventPublisher{
namespace: namespace,
remotePublisher: p,
}, nil
}
Expand All @@ -46,5 +48,5 @@ func (e *eventPublisher) publishEvent(ctx context.Context, topic string, event i
return nil
}

return e.remotePublisher.Publish(namespaces.WithNamespace(ctx, namespaceFlag), topic, event)
return e.remotePublisher.Publish(namespaces.WithNamespace(ctx, e.namespace), topic, event)
}
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type fakePublisher struct {
events []interface{}
}

var _ = (publisher)(&fakePublisher{})
var _ publisher = &fakePublisher{}

func newFakePublisher() *fakePublisher {
return &fakePublisher{}
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/exec.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/exec_clone.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/exec_hcs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/exec_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/exec_wcow_podsandbox.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/exec_wcow_podsandbox_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/pod.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/pod_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
4 changes: 3 additions & 1 deletion cmd/containerd-shim-runhcs-v1/serve.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down Expand Up @@ -175,7 +177,7 @@ var serveCommand = cli.Command{
}

ttrpcAddress := os.Getenv(ttrpcAddressEnv)
ttrpcEventPublisher, err := newEventPublisher(ttrpcAddress)
ttrpcEventPublisher, err := newEventPublisher(ttrpcAddress, namespaceFlag)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/service.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/service_internal.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down Expand Up @@ -609,7 +611,7 @@ func Test_TaskShim_waitInternal_InitTaskID_2ndExecID_Success(t *testing.T) {
}
}

func Test_TaskShim_statsInternal_InitTaskID_Sucess(t *testing.T) {
func Test_TaskShim_statsInternal_InitTaskID_Success(t *testing.T) {
testNames := []string{"WCOW", "LCOW"}
for i, isWCOW := range []bool{true, false} {
t.Run(testNames[i], func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/service_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/start.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/task.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/task_hcs_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/task_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/device-util/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/jobobject-util/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
3 changes: 2 additions & 1 deletion cmd/ncproxy/computeagent_cache.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down Expand Up @@ -38,7 +40,6 @@ func (c *computeAgentCache) getAllAndClear() ([]*computeAgentClient, error) {
results = append(results, agent)
}
return results, nil

}

func (c *computeAgentCache) get(cid string) (*computeAgentClient, error) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/hcn.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/hcn_networking_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
3 changes: 2 additions & 1 deletion cmd/ncproxy/ncproxy.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down Expand Up @@ -153,7 +155,6 @@ func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest
return nil, err
}
return &ncproxygrpc.AddNICResponse{}, nil

}

func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICRequest) (_ *ncproxygrpc.ModifyNICResponse, err error) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/ncproxy_networking_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/run.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/server_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/service.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 0 additions & 2 deletions cmd/ncproxy/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func networkExists(targetName string, networks []*ncproxygrpc.GetNetworkResponse
return true
}
}

}
return false
}
Expand All @@ -50,7 +49,6 @@ func endpointExists(targetName string, endpoints []*ncproxygrpc.GetEndpointRespo
return true
}
}

}
return false
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/runhcs/container.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down Expand Up @@ -36,7 +38,7 @@ type persistedState struct {
ID string `json:",omitempty"`
// Owner is the owner value passed into the runhcs command and may be `""`.
Owner string `json:",omitempty"`
// SandboxID is the sandbox identifer passed in via OCI specifications. This
// SandboxID is the sandbox identifier passed in via OCI specifications. This
// can either be the sandbox itself or the sandbox this container should run
// in. See `parseSandboxAnnotations`.
SandboxID string `json:",omitempty"`
Expand Down Expand Up @@ -203,8 +205,8 @@ func launchShim(cmd, pidFile, logFile string, args []string, data interface{}) (
// different runtimes to represent a sandbox ID, and sandbox type.
//
// If found returns the tuple `(sandboxID, isSandbox)` where `isSandbox == true`
// indicates the identifer is the sandbox itself; `isSandbox == false` indicates
// the identifer is the sandbox in which to place this container. Otherwise
// indicates the identifier is the sandbox itself; `isSandbox == false` indicates
// the identifier is the sandbox in which to place this container. Otherwise
// returns `("", false)`.
func parseSandboxAnnotations(a map[string]string) (string, bool) {
var t, id string
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/create-scratch.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/create.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/delete.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/exec.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/kill.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/list.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/runhcs/pause.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
Loading

0 comments on commit f371686

Please sign in to comment.