Skip to content
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

fix: --build.bin path for windows #590

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import (
"flag"
"fmt"
"log"

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

undefined: Println
"os"
"os/signal"
"runtime"
Expand Down Expand Up @@ -95,7 +95,13 @@
log.Fatal(err)
return
}
cfg.WithArgs(cmdArgs)

err = cfg.WithArgs(cmdArgs)
if err != nil {
log.Fatal(err)
return

Check warning on line 102 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L99-L102

Added lines #L99 - L102 were not covered by tests
}

r, err := runner.NewEngineWithConfig(cfg, debugMode)
if err != nil {
log.Fatal(err)
Expand Down
13 changes: 11 additions & 2 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,20 @@
}

// WithArgs returns a new config with the given arguments added to the configuration.
func (c *Config) WithArgs(args map[string]TomlInfo) {
for _, value := range args {
func (c *Config) WithArgs(args map[string]TomlInfo) error {
for key, value := range args {
if value.Value != nil && *value.Value != unsetDefault {
// To avoid path resolving problems on Windows.
if key == "build.bin" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think put logic in there is a good choice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we need to apply logic to windows only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think put logic in there is a good choice.

I agree on this one, I am thinking of moving the logic inside setValue2Struct, wdyt!

abs, err := filepath.Abs(*value.Value)
if err != nil {
return err

Check warning on line 393 in runner/config.go

View check run for this annotation

Codecov / codecov/patch

runner/config.go#L393

Added line #L393 was not covered by tests
}
value.Value = &abs
}
v := reflect.ValueOf(c)
setValue2Struct(v, value.fieldPath, *value.Value)
}
}
return nil
}
23 changes: 23 additions & 0 deletions runner/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,29 @@ func TestKillDelay(t *testing.T) {
}
}

func TestWithArgs(t *testing.T) {
testData := []struct {
bin string
}{{
bin: "bin\\main.exe",
}, {bin: "bin/main.exe"}}

for _, test := range testData {
config := Config{}
args := map[string]TomlInfo{
"build.bin": {
Value: &test.bin,
},
}
err := config.WithArgs(args)

if err != nil {
t.Fatal("Test shouldn't have failed, found: ", err)
}
}

}

func contains(sl []string, target string) bool {
for _, c := range sl {
if c == target {
Expand Down
3 changes: 2 additions & 1 deletion runner/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

const unsetDefault = "DEFAULT"

// ParseConfigFlag parse toml information for flag
// ParseConfigFlag parse toml information for flag and register
// keys as Vars in `flag` to be filled later when using `.Parse()`
func ParseConfigFlag(f *flag.FlagSet) map[string]TomlInfo {
c := Config{}
m := flatConfig(c)
Expand Down
Loading