-
Notifications
You must be signed in to change notification settings - Fork 24
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 relative project dir paths. #47
Conversation
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.
There's actually a simpler solution here, which is to normalize the projectDir
flag with filepath.Abs
after parsing from cobra.
This diff is working for me:
diff --git a/cmd/pkl-gen-go/pkl-gen-go.go b/cmd/pkl-gen-go/pkl-gen-go.go
index 5f463cd..65f6b53 100644
--- a/cmd/pkl-gen-go/pkl-gen-go.go
+++ b/cmd/pkl-gen-go/pkl-gen-go.go
@@ -138,7 +138,7 @@ var Version = "development"
func init() {
info, ok := debug.ReadBuildInfo()
- if !ok || info.Main.Version == "" || Version != "development" {
+ if !ok || info.Main.Version == "" || info.Main.Version == "(devel)" || Version != "development" {
return
}
Version = strings.TrimPrefix(info.Main.Version, "v")
@@ -240,6 +240,12 @@ func init() {
if err = flags.Parse(os.Args); err != nil && !errors.Is(err, pflag.ErrHelp) {
panic(err)
}
+ if projectDir != "" {
+ projectDir, err = filepath.Abs(projectDir)
+ if err != nil {
+ panic(err)
+ }
+ }
settings, err = loadGeneratorSettings(generatorSettingsPath, projectDir)
if err != nil {
panic(err)
@@ -260,7 +266,7 @@ func init() {
settings.AllowedResources = allowedResources
}
if projectDir != "" {
- settings.ProjectDir = &projectDir
+ *settings.ProjectDir = projectDir
}
settings.DryRun = dryRun
}
I doubt it will handle relative direction path properly when it is defined in setting file and is not under the same path with project. This was initial reason this bug existed, to handle relative pathes from settings file. Will test it later, though. |
@bioball Here is the way to reproduce it with this repository:
where This leads to error As you see parent has This is caused because projectDir flag is actually overrides within Later on projectDir is constructed again from settings within So proposed diff does not solve the initial problem. |
Hi @bioball |
@eli-l apologies for the late response! I've been focused on the next release, and this slipped through the cracks. I followed the steps that you outlined (remove Steps:
If you run these five steps, you should see output that looks something like this:
Here is the updated diff that avoids a nil dereference error: diff --git a/cmd/pkl-gen-go/pkl-gen-go.go b/cmd/pkl-gen-go/pkl-gen-go.go
index 5f463cd..3a7b044 100644
--- a/cmd/pkl-gen-go/pkl-gen-go.go
+++ b/cmd/pkl-gen-go/pkl-gen-go.go
@@ -138,7 +138,7 @@ var Version = "development"
func init() {
info, ok := debug.ReadBuildInfo()
- if !ok || info.Main.Version == "" || Version != "development" {
+ if !ok || info.Main.Version == "" || info.Main.Version == "(devel)" || Version != "development" {
return
}
Version = strings.TrimPrefix(info.Main.Version, "v")
@@ -240,6 +240,12 @@ func init() {
if err = flags.Parse(os.Args); err != nil && !errors.Is(err, pflag.ErrHelp) {
panic(err)
}
+ if projectDir != "" {
+ projectDir, err = filepath.Abs(projectDir)
+ if err != nil {
+ panic(err)
+ }
+ }
settings, err = loadGeneratorSettings(generatorSettingsPath, projectDir)
if err != nil {
panic(err)
@@ -260,7 +266,10 @@ func init() {
settings.AllowedResources = allowedResources
}
if projectDir != "" {
- settings.ProjectDir = &projectDir
+ if settings.ProjectDir == nil {
+ settings.ProjectDir = new(string)
+ }
+ *settings.ProjectDir = projectDir
}
settings.DryRun = dryRun
}
|
Addresses #48
Because of generator settings may fall back to default value (when installed globally) we can not rely on this value when building path from relative project dir.
This commit changes the behaviour of it:
generator-settings.pkl
is not present or is in default location (CWD) -> project dir is built from CWD, not settings dirprojectDir
defined in the settings files accurately describe location.