From 113b41b6f5f0d95302839fadee320096d65b54ee Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Mon, 18 Sep 2023 17:41:33 -0400 Subject: [PATCH 1/2] Buildtag out unix commands for common OS files Unix only code crept into shared portions of the machine codebase, preventing builds on Windows. Move them into unix-only files. [NO NEW TESTS NEEDED] Signed-off-by: Ashley Cui --- pkg/machine/qemu/machine.go | 13 ++----------- pkg/machine/qemu/machine_unix.go | 14 ++++++++++++++ pkg/machine/qemu/machine_windows.go | 8 ++++++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 8082f3b9d8..652b69c1e1 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -28,7 +28,6 @@ import ( "github.com/containers/storage/pkg/lockfile" "github.com/digitalocean/go-qemu/qmp" "github.com/sirupsen/logrus" - "golang.org/x/sys/unix" ) var ( @@ -589,15 +588,7 @@ func (v *MachineVM) qemuPid() (int, error) { logrus.Warnf("Reading QEMU pidfile: %v", err) return -1, nil } - - if err := unix.Kill(pid, 0); err != nil { - if err == unix.ESRCH { - return -1, nil - } - return -1, fmt.Errorf("pinging QEMU process: %w", err) - } - - return pid, nil + return findProcess(pid) } // Start executes the qemu command line and forks it @@ -970,7 +961,7 @@ func (v *MachineVM) Stop(_ string, _ machine.StopOptions) error { return stopErr } - if err := unix.Kill(qemuPid, unix.SIGKILL); err != nil { + if err := sigKill(qemuPid); err != nil { if stopErr == nil { return err } diff --git a/pkg/machine/qemu/machine_unix.go b/pkg/machine/qemu/machine_unix.go index b798d03dba..e764013d8c 100644 --- a/pkg/machine/qemu/machine_unix.go +++ b/pkg/machine/qemu/machine_unix.go @@ -43,3 +43,17 @@ func extractTargetPath(paths []string) string { } return paths[0] } + +func sigKill(pid int) error { + return unix.Kill(pid, unix.SIGKILL) +} + +func findProcess(pid int) (int, error) { + if err := unix.Kill(pid, 0); err != nil { + if err == unix.ESRCH { + return -1, nil + } + return -1, fmt.Errorf("pinging QEMU process: %w", err) + } + return pid, nil +} diff --git a/pkg/machine/qemu/machine_windows.go b/pkg/machine/qemu/machine_windows.go index 04065cb1d3..b31a4f1d10 100644 --- a/pkg/machine/qemu/machine_windows.go +++ b/pkg/machine/qemu/machine_windows.go @@ -50,3 +50,11 @@ func extractTargetPath(paths []string) string { dedup := regexp.MustCompile(`//+`) return dedup.ReplaceAllLiteralString("/"+target, "/") } + +func sigKill(pid int) error { + return nil +} + +func findProcess(pid int) (int, error) { + return -1, nil +} From 6d8b3047d7a36e47e760f65fb4cb805b28d645e1 Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Tue, 19 Sep 2023 02:09:13 -0400 Subject: [PATCH 2/2] Makefile equiv Powershell script Introduce a powershell script that mirrors Makefile capbilities on Windows. Syntax: ./winmake target [options] [NO NEW TESTS NEEDED] Signed-off-by: Ashley Cui --- winmake.ps1 | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 winmake.ps1 diff --git a/winmake.ps1 b/winmake.ps1 new file mode 100644 index 0000000000..1c390b0801 --- /dev/null +++ b/winmake.ps1 @@ -0,0 +1,103 @@ +$ErrorActionPreference = 'Stop' + +# Targets +function Podman-Remote{ + New-Item ./bin/windows -ItemType Directory -ea 0 + + $buildInfo = Get-Date -UFormat %s -Millisecond 0 + $buildInfo = "-X github.com/containers/podman/v4/libpod/define.buildInfo=$buildInfo " + $commit = Git-Commit + $commit = "-X github.com/containers/podman/v4/libpod/define.gitCommit=$commit " + + Run-Command "go build --ldflags `"$commit $buildInfo `" --tags `"$remotetags`" --o ./bin/windows/podman.exe ./cmd/podman/." +} + +function Make-Clean{ + Remove-Item ./bin -Recurse -Force -Confirm:$false +} + +function Local-Machine { + param ( + [string]$files + ); + Build-Ginkgo + if ($files) { + $files = " --focus-file $files " + } + + Run-Command "./test/tools/build/ginkgo.exe -vv --tags `"$remotetags`" -timeout=90m --trace --no-color $files pkg/machine/e2e/. " +} + +# Helpers +function Build-Ginkgo{ + if (Test-Path -Path ./test/tools/build/ginkgo.exe -PathType Leaf) { + return + } + Write-Host "Building Ginkgo" + Push-Location ./test/tools + Run-Command "go build -o build/ginkgo.exe ./vendor/github.com/onsi/ginkgo/v2/ginkgo" + Pop-Location +} + +function Git-Commit{ + # git is not installed by default on windows, + # so if we can't get the commit, we don't include this info + Get-Command git -ErrorAction SilentlyContinue | out-null + if(!$?){ + return + } + $commit = git rev-parse HEAD + $dirty = git status --porcelain --untracked-files=no + if ($dirty){ + $commit = "$commit-dirty" + } + return $commit +} + +function Run-Command { + param ( + [string] $command + ) + + Write-Host $command + + Invoke-Expression $command + $result = $LASTEXITCODE + if ($result -ne 0) { + Write-Host "Command failed (exit: $result)" + Exit $result + } +} + +# Init script +$target = $args[0] + +$remotetags = "remote exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper containers_image_openpgp" +$Env:GOOS = "windows"; $Env:GOARCH = "amd64" + +switch ($target) { + {$_ -in '', 'podman-remote', 'podman'} { + Podman-Remote + } + 'localmachine' { + if ($args.Count -gt 1) { + $files = $args[1] + } + Local-Machine -files $files + } + 'clean' { + Make-Clean + } + default { + Write-Host "Usage: " $MyInvocation.MyCommand.Name " [options]" + Write-Host + Write-Host "Example: Build podman-remote " + Write-Host " .\winmake podman-remote" + Write-Host + Write-Host "Example: Run all machine tests " + Write-Host " .\winmake localmachine" + Write-Host + Write-Host "Example: Run specfic machine tests " + Write-Host " .\winmake localmachine "basic_test.go"" + } +}