-
-
Notifications
You must be signed in to change notification settings - Fork 113
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 main.go generation when executing on a windows machine #32
Fix main.go generation when executing on a windows machine #32
Conversation
When normalizing the `importPath` it will try to write on `main.go` files with imports like `github.com/caddyserver/xcaddy/c:\xcaddy`
5181fd6
to
57b3486
Compare
I just rebased it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! How does it handle the situation where you're in a subdir of a module, i.e. cwd = /xcaddy/subdir
, and on Windows, i.e. c:\xcaddy\subdir
?
cmd/xcaddy/main_test.go
Outdated
@@ -71,3 +71,34 @@ func TestSplitWith(t *testing.T) { | |||
} | |||
} | |||
} | |||
|
|||
func Test_normalizeImportPath(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func Test_normalizeImportPath(t *testing.T) { | |
func TestNormalizeImportPath(t *testing.T) { |
cmd/xcaddy/main.go
Outdated
@@ -243,6 +243,10 @@ func runDev(ctx context.Context, args []string) error { | |||
return cmd.Wait() | |||
} | |||
|
|||
func normalizeImportPath(currentModule string, cwd string, moduleDir string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func normalizeImportPath(currentModule string, cwd string, moduleDir string) string { | |
func normalizeImportPath(currentModule, cwd, moduleDir string) string { |
Hey @mholt args{
currentModule: "github.com/caddyserver/xcaddy",
cwd: "c:\\xcaddy\\subdir",
moduleDir: "c:\\xcaddy\\subdir",
} should be: |
I mean we need to add at least 2 more test cases. |
If I understood correctly, something like this? diff --git a/cmd/xcaddy/main_test.go b/cmd/xcaddy/main_test.go
index af9f0de..23975c4 100644
--- a/cmd/xcaddy/main_test.go
+++ b/cmd/xcaddy/main_test.go
@@ -88,11 +88,21 @@ func TestNormalizeImportPath(t *testing.T) {
cwd: "/xcaddy",
moduleDir: "/xcaddy",
}, "github.com/caddyserver/xcaddy"},
+ {"linux-subpath", args{
+ currentModule: "github.com/caddyserver/xcaddy",
+ cwd: "/xcaddy/subdir",
+ moduleDir: "/xcaddy",
+ }, "github.com/caddyserver/xcaddy/subdir"},
{"windows-path", args{
currentModule: "github.com/caddyserver/xcaddy",
cwd: "c:\\xcaddy",
moduleDir: "c:\\xcaddy",
}, "github.com/caddyserver/xcaddy"},
+ {"windows-subpath", args{
+ currentModule: "github.com/caddyserver/xcaddy",
+ cwd: "c:\\xcaddy\\subdir",
+ moduleDir: "c:\\xcaddy",
+ }, "github.com/caddyserver/xcaddy/subdir"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { |
Yes I think that's right! (My brain's all over the place today but see if that works) |
Thank you! |
Hmm, and it fails on Linux for windows subpaths. |
Well, Windows paths shouldn't come up on Unix at all, so running tests for Windows path on Unix does seem a bit unnecessary. Or, maybe something like this? return path.Join(currentModule, filepath.ToSlash(strings.TrimPrefix(cwd, filepath.ToSlash(moduleDir)))) |
I guess for that to work I need to make the cwd slashed as well. |
Oh, yes, that's probably true! |
Hey there |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that works. Thanks so much for contributing this!
When normalizing the
importPath
it will try to write onmain.go
files with importslike
github.com/caddyserver/xcaddy/c:\xcaddy
The fix is basically changing from
path.Join(currentModule, strings.TrimPrefix(cwd, filepath.ToSlash(moduleDir)))
topath.Join(currentModule, filepath.ToSlash(strings.TrimPrefix(cwd, moduleDir)))