Skip to content
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
__pycache__
.DS_Store
/tt
**/*_gen.go
.venv
coverage
dist
9 changes: 9 additions & 0 deletions cli/checkpoint/lua_embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package checkpoint

import _ "embed"

//go:embed lua/cat.lua
var catFile string

//go:embed lua/play.lua
var playFile string
152 changes: 0 additions & 152 deletions cli/codegen/generate_code.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/connector/lua/call_func_template.lua

This file was deleted.

6 changes: 6 additions & 0 deletions cli/connector/lua_embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package connector

import _ "embed"

//go:embed lua/eval_func_template.lua
var evalFuncTmpl string
14 changes: 1 addition & 13 deletions cli/create/builtin_templates/builtin_templates.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package builtin_templates

import (
"embed"

"github.com/tarantool/tt/cli/create/builtin_templates/static"
)
import "embed"

//go:embed templates/*
var TemplatesFs embed.FS

// FileModes contains mapping of file modes by built-in template name.
var FileModes = map[string]map[string]int{
"vshard_cluster": static.VshardClusterFileModes,
"single_instance": static.SingleInstanceFileModes,
"config_storage": static.ConfigStorageFileModes,
"cluster": static.ClusterFileModes,
}

// Names contains built-in template names.
var Names = [...]string{
"vshard_cluster",
Expand Down
Empty file.
72 changes: 25 additions & 47 deletions cli/create/internal/steps/copy_app_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,40 @@ import (
// CopyAppTemplate represents template -> app directory copy step.
type CopyAppTemplate struct{}

// Returns a file perm for path from fileModes. Or default perm if data is missing in modes map.
func getFileMode(path string, dirEntry fs.DirEntry, fileModes map[string]int) fs.FileMode {
const defaultDirPerm = 0o755 // drwxr-xr-x
const defaultFilePerm = 0o660 // -rw-rw----
if dirEntry.IsDir() {
return defaultDirPerm
}

fileMode, found := fileModes[path]
if !found {
log.Warnf("No file mode info for '%s'", path)
return fs.FileMode(defaultFilePerm)
}

return fs.FileMode(fileMode)
}

// copyEmbedFs copies src file system tree to dst.
func copyEmbedFs(srcFs fs.FS, dst string, fileModes map[string]int) error {
// copyEmbedFs copies src file system tree to dst. Directories get 0755 and
// files get 0644 — every built-in template uses those modes, and embed.FS
// strips the source modes anyway, so there is nothing else to preserve.
func copyEmbedFs(srcFs fs.FS, dst string) error {
const (
dirPerm fs.FileMode = 0o755
filePerm fs.FileMode = 0o644
)
err := fs.WalkDir(srcFs, ".", func(path string, dirEntry fs.DirEntry, err error) error {
if err != nil {
return err
return fmt.Errorf("walk %q: %w", path, err)
}
fileMode := getFileMode(path, dirEntry, fileModes)
if dirEntry.IsDir() {
destDirPath := filepath.Join(dst, path)
if err := util.CreateDirectory(destDirPath, fileMode); err != nil {
return err
}
} else {
inFile, err := srcFs.Open(path)
if err != nil {
return err
}
defer inFile.Close()
return util.CreateDirectory(filepath.Join(dst, path), dirPerm)
}
inFile, err := srcFs.Open(path)
if err != nil {
return fmt.Errorf("open template file %q: %w", path, err)
}
defer inFile.Close()

outFile, err := os.OpenFile(filepath.Join(dst, path), os.O_CREATE|os.O_WRONLY,
fileMode)
if err != nil {
return err
}
defer outFile.Close()
outFile, err := os.OpenFile(filepath.Join(dst, path), os.O_CREATE|os.O_WRONLY, filePerm)
if err != nil {
return fmt.Errorf("create %q: %w", path, err)
}
defer outFile.Close()

if _, err := io.Copy(outFile, inFile); err != nil {
return err
}
if _, err := io.Copy(outFile, inFile); err != nil {
return fmt.Errorf("copy %q: %w", path, err)
}
return nil
})
if err != nil {
return err
return fmt.Errorf("copy embedded template: %w", err)
}
return nil
}
Expand Down Expand Up @@ -118,12 +101,7 @@ func (CopyAppTemplate) Run(createCtx *create_ctx.CreateCtx,
if err != nil {
return err
}
fileModes, found := builtin_templates.FileModes[templateName]
if !found {
log.Warn("File permissions data is not found for '%s' template. " +
"Using default permissions.")
}
return copyEmbedFs(templateFs, templateCtx.AppPath, fileModes)
return copyEmbedFs(templateFs, templateCtx.AppPath) //nolint:wrapcheck // already wraps.
}
}

Expand Down
7 changes: 2 additions & 5 deletions cli/create/internal/steps/copy_app_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,11 @@ func TestCopyEmbeddedFs(t *testing.T) {
tmpDir := t.TempDir()
templateFs, err := fs.Sub(templateTestFs, "testdata/copy_template/templates/basic")
require.NoError(t, err)
require.NoError(t, copyEmbedFs(templateFs, tmpDir, map[string]int{
"init.lua": 0o600,
"echo.sh": 0o755,
}))
require.NoError(t, copyEmbedFs(templateFs, tmpDir))
assert.FileExists(t, filepath.Join(tmpDir, "init.lua"))
assert.FileExists(t, filepath.Join(tmpDir, "subdir", "file.txt"))
assert.FileExists(t, filepath.Join(tmpDir, "echo.sh"))
stat, err := os.Stat(filepath.Join(tmpDir, "echo.sh"))
require.NoError(t, err)
assert.True(t, stat.Mode().Perm()&0o110 != 0)
assert.Equal(t, fs.FileMode(0o644), stat.Mode().Perm())
}
6 changes: 6 additions & 0 deletions cli/running/lua_embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package running

import _ "embed"

//go:embed lua/check.lua
var checkSyntax string
18 changes: 0 additions & 18 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ var (
pythonExecutableName = "python3"
ttExecutableName = "tt"

generateModePath = filepath.Join(packagePath, "codegen", "generate_code.go")

Aliases = map[string]any{
"build": Build.Release,
"unit": Unit.Default,
Expand Down Expand Up @@ -136,8 +134,6 @@ func appendTags(args []string) ([]string, error) {
// Building tt executable. Supported environment variables:
// TT_CLI_BUILD_SSL=(no|static|shared).
func buildTt(argUpdaters ...optsUpdater) error {
mg.Deps(GenerateGoCode)

args := []string{"build", "-o", ttExecutableName}
var err error
for _, updateArguments := range argUpdaters {
Expand Down Expand Up @@ -214,8 +210,6 @@ func (Lint) Full() error {
func (Lint) Golang() error {
fmt.Println("Running golangci-lint...")

mg.Deps(GenerateGoCode)

lintDirs := append([]string{"."}, modules...)
root, err := os.Getwd()
if err != nil {
Expand Down Expand Up @@ -247,8 +241,6 @@ func (Lint) Python() error {
type Unit mg.Namespace

func runUnitTests(flags []string) error {
mg.Deps(GenerateGoCode)

testDirs := append([]string{"."}, modules...)
for _, module := range testDirs {
args := []string{"test", "-C", module}
Expand Down Expand Up @@ -418,16 +410,6 @@ func Generate() error {
return nil
}

// GenerateGoCode generates code from lua files.
func GenerateGoCode() error {
err := sh.RunWith(getBuildEnvironment(), goExecutableName, "run", generateModePath)
if err != nil {
return err
}

return nil
}

// getDefaultConfigPath returns the path to the configuration file,
// determining it based on the OS.
func getDefaultConfigPath() string {
Expand Down
Loading