-
-
Notifications
You must be signed in to change notification settings - Fork 33
Change win program resolution to match macOS/Linux #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ded3bc9
Change win program resolution to match macOS/Linux
lread dd93ac1
cleanup: turf unused import
lread db938a5
consistency: add dir context for macos/linux test
lread eb4a3c5
Update src/babashka/process.cljc
borkdude 7fe7ce3
review feeback: only alter `program` if necessary
lread 1abe118
tweak tests for when they are run from babashka
lread File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Babashka Process Test Resources | ||
|
||
For test coverage, we need executables that emit their path and their current working directory. | ||
For example, on Windows: | ||
``` | ||
> .\print-dirs.bat | ||
exepath: Z:\babashka\process\test-resources\print-dirs.bat | ||
workdir: Z:\babashka\process\test-resources | ||
> cd .. | ||
>test-resources\print-dirs | ||
exepath: Z:\babashka\process\test-resources\print-dirs.exe | ||
workdir: Z:\babashka\process | ||
``` | ||
|
||
This is straightforward for Linux/macOS `.sh`, Windows `.cmd` and Windows `.bat` variants, but for the Windows `.exe` variant, we need to create a binary. | ||
|
||
## Generating a Windows .exe | ||
|
||
It doesn't matter how `print-dirs.exe` is created; it won't need to be recreated often (we commit it to source control). | ||
|
||
Since it generates relatively small binaries very quickly for any architecture, we've built a `print-dirs.exe` using Go. | ||
Source is in [print-dirs.go](print-dirs.go) | ||
|
||
### Minimal Build | ||
Presuming you have [Go](https://go.dev/) installed, from this dir: | ||
|
||
```shell | ||
GOOS=windows GOARCH=amd64 go build -o print-dirs.exe print-dirs.go | ||
``` | ||
|
||
For me, this generated a 1.9mb `print-dirs.exe`. | ||
|
||
### Build a Smaller Exe | ||
Since this `.exe` is checked into version control, I opted to create a smaller binary by adding the following `-ldflags` to strip debug info: | ||
|
||
```shell | ||
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o print-dirs.exe print-dirs.go | ||
``` | ||
|
||
For me, the generated `print-dirs.exe` is now 1.3mb. | ||
To further shrink down the binary, you can use [UPX](https://upx.github.io/) (which is also cross-platform): | ||
|
||
``` | ||
upx --ultra-brute print-dirs.exe | ||
``` | ||
|
||
And now `print-dirs.exe` is 457kb. | ||
|
||
### Building With Docker | ||
If you don't want to install Go and UPX on your dev box but have docker installed, you can build from a docker image like so: | ||
|
||
``` shell | ||
docker run --rm \ | ||
-v "$PWD":/src \ | ||
-w /src \ | ||
devopsworks/golang-upx:latest \ | ||
bash -c 'GOOS=windows GOARCH=amd64 \ | ||
go build -ldflags "-s -w" -o print-dirs.exe print-dirs.go && | ||
upx --ultra-brute print-dirs.exe' | ||
``` | ||
|
||
This is ultimately the command I ran to create our Windows .exe. | ||
|
||
## What about Windows .com? | ||
|
||
These days, `.com` executables are rare. | ||
|
||
I could not find an easy way to create one. | ||
Our tests use `print-dirs.exe` copied to `print-dirs.com` to support `.com` test cases. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
echo exepath: %~dpnx0 | ||
echo workdir: %cd% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
echo exepath: %~dpnx0 | ||
echo workdir: %cd% |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
executable, _ := os.Executable() | ||
fmt.Fprintln(os.Stdout,"exepath:", executable) | ||
cwd, _ := os.Getwd() | ||
fmt.Fprintln(os.Stdout,"workdir:", cwd) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Write-Output "exepath: $($MyInvocation.MyCommand.Path)" | ||
Write-Output "workdir: $(Get-Location)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
echo "exepath: $(readlink -f "$0")" | ||
echo "workdir: $(pwd)" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.