Skip to content

Commit

Permalink
Remove module symlink in scaffolding
Browse files Browse the repository at this point in the history
Now the path to user function code is directly in go.mod.

Signed-off-by: Matej Vašek <[email protected]>
  • Loading branch information
matejvasek committed Oct 21, 2024
1 parent 97fb956 commit 8e5fb4d
Show file tree
Hide file tree
Showing 10 changed files with 9,365 additions and 9,386 deletions.
18,714 changes: 9,348 additions & 9,366 deletions generate/zz_filesystem_generated.go

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions pkg/scaffolding/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scaffolding

import (
"fmt"
"os"
"path/filepath"

"knative.dev/func/pkg/filesystem"
Expand Down Expand Up @@ -43,6 +42,19 @@ func Write(out, src, runtime, invoke string, fs filesystem.Filesystem) (err erro
return ErrScaffoldingNotFound
}

rel, err := filepath.Rel(out, src)
if err != nil {
return ScaffoldingError{"error determining relative path to function source", err}
}

fs = filesystem.NewTemplatingFS(fs, struct {
ModuleName string
FuncPath string
}{
ModuleName: "function",
FuncPath: rel,
})

// Copy from d -> out from the filesystem
if err := filesystem.CopyFromFS(d, out, fs); err != nil {
return ScaffoldingError{"filesystem copy failed", err}
Expand All @@ -56,17 +68,6 @@ func Write(out, src, runtime, invoke string, fs filesystem.Filesystem) (err erro
return ScaffoldingError{"certs copy failed", err}
}

// Replace the 'f' link of the scaffolding (which is now incorrect) to
// link to the function's root.
rel, err := filepath.Rel(out, src)
if err != nil {
return ScaffoldingError{"error determining relative path to function source", err}
}
link := filepath.Join(out, "f")
_ = os.Remove(link)
if err = os.Symlink(rel, link); err != nil {
return fmt.Errorf("error linking scaffolding to source %w", err)
}
return
}

Expand Down
1 change: 0 additions & 1 deletion templates/go/scaffolding/instanced-cloudevents/f

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module s

replace function => ./f
replace {{.ModuleName}} => {{.FuncPath}}

go 1.21

Expand Down
1 change: 0 additions & 1 deletion templates/go/scaffolding/instanced-http/f

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module s

replace function => ./f
replace {{.ModuleName}} => {{.FuncPath}}

go 1.21

Expand Down
1 change: 0 additions & 1 deletion templates/go/scaffolding/static-cloudevents/f

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module s

replace function => ./f
replace {{.ModuleName}} => {{.FuncPath}}

go 1.21

Expand Down
1 change: 0 additions & 1 deletion templates/go/scaffolding/static-http/f

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module s

replace function => ./f
replace {{.ModuleName}} => {{.FuncPath}}

go 1.21

Expand Down

0 comments on commit 8e5fb4d

Please sign in to comment.