Skip to content

Commit

Permalink
godot fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
javorszky committed Feb 3, 2022
1 parent 63b3ea4 commit 50648ba
Show file tree
Hide file tree
Showing 37 changed files with 141 additions and 140 deletions.
22 changes: 11 additions & 11 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/suborbital/subo/subo/util"
)

// Builder is capable of building Wasm modules from source
// Builder is capable of building Wasm modules from source.
type Builder struct {
Context *context.BuildContext

Expand All @@ -29,7 +29,7 @@ type Builder struct {
log util.FriendlyLogger
}

// BuildResult is the results of a build including the built module and logs
// BuildResult is the results of a build including the built module and logs.
type BuildResult struct {
Succeeded bool
OutputLog string
Expand All @@ -42,7 +42,7 @@ const (
ToolchainDocker = Toolchain("docker")
)

// ForDirectory creates a Builder bound to a particular directory
// ForDirectory creates a Builder bound to a particular directory.
func ForDirectory(logger util.FriendlyLogger, dir string) (*Builder, error) {
ctx, err := context.ForDirectory(dir)
if err != nil {
Expand All @@ -63,8 +63,8 @@ func (b *Builder) BuildWithToolchain(tcn Toolchain) error {

b.results = []BuildResult{}

// when building in Docker mode, just collect the langs we need to build, and then
// launch the associated builder images which will do the building
// When building in Docker mode, just collect the langs we need to build, and then
// launch the associated builder images which will do the building.
dockerLangs := map[string]bool{}

for _, r := range b.Context.Runnables {
Expand All @@ -89,8 +89,8 @@ func (b *Builder) BuildWithToolchain(tcn Toolchain) error {

err = b.doNativeBuildForRunnable(r, result)

// even if there was a failure, load the result into the builder
// since the logs of the failed build are useful
// Even if there was a failure, load the result into the builder
// since the logs of the failed build are useful.
b.results = append(b.results, *result)

if err != nil {
Expand Down Expand Up @@ -144,7 +144,7 @@ func (b *Builder) Bundle() error {
} else if b.Context.Directive.Headless {
b.log.LogInfo("updating Directive")

// bump the appVersion since we're in headless mode
// Bump the appVersion since we're in headless mode.
majorStr := strings.TrimPrefix(semver.Major(b.Context.Directive.AppVersion), "v")
major, _ := strconv.Atoi(majorStr)
new := fmt.Sprintf("v%d.0.0", major+1)
Expand Down Expand Up @@ -212,7 +212,7 @@ func (b *Builder) dockerBuildForLang(lang string) (*BuildResult, error) {
return result, nil
}

// results and resulting file are loaded into the BuildResult pointer
// results and resulting file are loaded into the BuildResult pointer.
func (b *Builder) doNativeBuildForRunnable(r context.RunnableDir, result *BuildResult) error {
cmds, err := context.NativeBuildCommands(r.Runnable.Lang)
if err != nil {
Expand All @@ -232,7 +232,7 @@ func (b *Builder) doNativeBuildForRunnable(r context.RunnableDir, result *BuildR

cmdString := strings.TrimSpace(fullCmd.String())

// Even if the command fails, still load the output into the result object
// Even if the command fails, still load the output into the result object.
outputLog, err := util.RunInDir(cmdString, r.Fullpath)

result.OutputLog += outputLog + "\n"
Expand Down Expand Up @@ -283,7 +283,7 @@ func (b *Builder) checkAndRunPreReqs(runnable context.RunnableDir, result *Build
}

// analyzeForCompilerFlags looks at the Runnable and determines if any additional compiler flags are needed
// this is initially added to support AS-JSON in AssemblyScript with its need for the --transform flag
// this is initially added to support AS-JSON in AssemblyScript with its need for the --transform flag.
func (b *Builder) analyzeForCompilerFlags(runnable context.RunnableDir) (string, error) {
if runnable.Runnable.Lang == "assemblyscript" {
packageJSONBytes, err := ioutil.ReadFile(filepath.Join(runnable.Fullpath, "package.json"))
Expand Down
20 changes: 10 additions & 10 deletions builder/context/buildcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var dockerImageForLang = map[string]string{
"js": "suborbital/builder-js",
}

// BuildContext describes the context under which the tool is being run
// BuildContext describes the context under which the tool is being run.
type BuildContext struct {
Cwd string
CwdIsRunnable bool
Expand All @@ -38,7 +38,7 @@ type BuildContext struct {
BuilderTag string
}

// RunnableDir represents a directory containing a Runnable
// RunnableDir represents a directory containing a Runnable.
type RunnableDir struct {
Name string
UnderscoreName string
Expand All @@ -47,13 +47,13 @@ type RunnableDir struct {
CompilerFlags string
}

// BundleRef contains information about a bundle in the current context
// BundleRef contains information about a bundle in the current context.
type BundleRef struct {
Exists bool
Fullpath string
}

// ForDirectory returns the build context for the provided working directory
// ForDirectory returns the build context for the provided working directory.
func ForDirectory(dir string) (*BuildContext, error) {
fullDir, err := filepath.Abs(dir)
if err != nil {
Expand Down Expand Up @@ -101,7 +101,7 @@ func ForDirectory(dir string) (*BuildContext, error) {
return bctx, nil
}

// RunnableExists returns true if the context contains a runnable with name <name>
// RunnableExists returns true if the context contains a runnable with name <name>.
func (b *BuildContext) RunnableExists(name string) bool {
for _, r := range b.Runnables {
if r.Name == name {
Expand All @@ -112,7 +112,7 @@ func (b *BuildContext) RunnableExists(name string) bool {
return false
}

// ShouldBuildLang returns true if the provided language is safe-listed for building
// ShouldBuildLang returns true if the provided language is safe-listed for building.
func (b *BuildContext) ShouldBuildLang(lang string) bool {
if len(b.Langs) == 0 {
return true
Expand Down Expand Up @@ -147,13 +147,13 @@ func (b *BuildContext) Modules() ([]os.File, error) {
func getRunnableDirs(cwd string) ([]RunnableDir, bool, error) {
runnables := []RunnableDir{}

// go through all of the dirs in the current dir
// Go through all of the dirs in the current dir.
topLvlFiles, err := ioutil.ReadDir(cwd)
if err != nil {
return nil, false, errors.Wrap(err, "failed to list directory")
}

// check to see if we're running from within a Runnable directory
// Check to see if we're running from within a Runnable directory
// and return true if so.
runnableDir, err := getRunnableFromFiles(cwd, topLvlFiles)
if err != nil {
Expand All @@ -170,7 +170,7 @@ func getRunnableDirs(cwd string) ([]RunnableDir, bool, error) {

dirPath := filepath.Join(cwd, tf.Name())

// determine if a .runnable file exists in that dir
// Determine if a .runnable file exists in that dir.
innerFiles, err := ioutil.ReadDir(dirPath)
if err != nil {
util.LogWarn(fmt.Sprintf("couldn't read files in %v", dirPath))
Expand All @@ -190,7 +190,7 @@ func getRunnableDirs(cwd string) ([]RunnableDir, bool, error) {
return runnables, false, nil
}

// containsRunnableYaml finds any .runnable file in a list of files
// ContainsRunnableYaml finds any .runnable file in a list of files.
func ContainsRunnableYaml(files []os.FileInfo) (string, bool) {
for _, f := range files {
if strings.HasPrefix(f.Name(), ".runnable.") {
Expand Down
10 changes: 5 additions & 5 deletions builder/context/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/suborbital/subo/subo/util"
)

// WriteDirectiveFile writes a Directive to disk
// WriteDirectiveFile writes a Directive to disk.
func WriteDirectiveFile(cwd string, directive *directive.Directive) error {
filePath := filepath.Join(cwd, "Directive.yaml")

Expand All @@ -29,7 +29,7 @@ func WriteDirectiveFile(cwd string, directive *directive.Directive) error {
return nil
}

// readDirectiveFile finds a Directive from disk but does not validate it
// readDirectiveFile finds a Directive from disk but does not validate it.
func readDirectiveFile(cwd string) (*directive.Directive, error) {
filePath := filepath.Join(cwd, "Directive.yaml")

Expand All @@ -55,7 +55,7 @@ func readDirectiveFile(cwd string) (*directive.Directive, error) {
return directive, nil
}

// readQueriesFile finds a queries.yaml from disk
// readQueriesFile finds a queries.yaml from disk.
func readQueriesFile(cwd string) ([]directive.DBQuery, error) {
filePath := filepath.Join(cwd, "Queries.yaml")

Expand All @@ -77,7 +77,7 @@ func readQueriesFile(cwd string) ([]directive.DBQuery, error) {
}

// AugmentAndValidateDirectiveFns ensures that all functions referenced in a handler exist
// in the project and then adds the function list to the provided directive
// in the project and then adds the function list to the provided directive.
func AugmentAndValidateDirectiveFns(dxe *directive.Directive, fns []RunnableDir) error {
fnMap := map[string]bool{}
for _, fn := range fns {
Expand All @@ -102,7 +102,7 @@ func AugmentAndValidateDirectiveFns(dxe *directive.Directive, fns []RunnableDir)
return nil
}

// getHandlerFnList gets a full list of all functions used in the directive's handlers
// getHandlerFnList gets a full list of all functions used in the directive's handlers.
func getHandlerFnList(dxe *directive.Directive) []string {
fnMap := map[string]bool{}

Expand Down
2 changes: 1 addition & 1 deletion builder/context/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime"
)

// NativeBuildCommands returns the native build commands needed to build a Runnable of a particular language
// NativeBuildCommands returns the native build commands needed to build a Runnable of a particular language.
func NativeBuildCommands(lang string) ([]string, error) {
os := runtime.GOOS

Expand Down
4 changes: 2 additions & 2 deletions builder/context/prereq.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package context

// PreReq is a pre-requisite file paired with the native command needed to acquire that file (if it's missing)
// PreReq is a pre-requisite file paired with the native command needed to acquire that file (if it's missing).
type Prereq struct {
File string
Command string
}

// PreRequisiteCommands is a map of OS : language : preReq
// PreRequisiteCommands is a map of OS : language : preReq.
var PreRequisiteCommands = map[string]map[string][]Prereq{
"darwin": {
"rust": {},
Expand Down
2 changes: 1 addition & 1 deletion builder/context/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// CollectStaticFiles collects all of the files in the `static/` directory relative to cwd
// and generates a map of their relative paths
// and generates a map of their relative paths.
func CollectStaticFiles(cwd string) (map[string]os.File, error) {
staticDir := filepath.Join(cwd, "static")

Expand Down
2 changes: 1 addition & 1 deletion builder/template/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TemplateFullPath(repo, branch string) (string, error) {
return filepath.Join(root, fmt.Sprintf("%s-%s", repoName, strings.ReplaceAll(branch, "/", "-")), "templates"), nil
}

// TemplateRootDir gets the template directory for subo and ensures it exists
// TemplateRootDir gets the template directory for subo and ensures it exists.
func TemplateRootDir() (string, error) {
config, err := os.UserConfigDir()
if err != nil {
Expand Down
30 changes: 15 additions & 15 deletions builder/template/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/suborbital/subo/subo/util"
)

// ErrTemplateMissing and others are template related errors
// ErrTemplateMissing and others are template related errors.
var ErrTemplateMissing = errors.New("template missing")

type tmplData struct {
Expand Down Expand Up @@ -47,7 +47,7 @@ func UpdateTemplates(repo, branch string) (string, error) {
return "", errors.Wrap(err, "🚫 failed to downloadZip for templates")
}

// tmplPath may be different than the default if a custom URL was provided
// The tmplPath may be different than the default if a custom URL was provided.
tmplPath, err := extractZip(filepath, templateRootPath, branchDirName)
if err != nil {
return "", errors.Wrap(err, "🚫 failed to extractZip for templates")
Expand All @@ -58,7 +58,7 @@ func UpdateTemplates(repo, branch string) (string, error) {
return tmplPath, nil
}

// TemplatesExist returns the templates directory for the provided repo and branch
// TemplatesExist returns the templates directory for the provided repo and branch.
func TemplatesExist(repo, branch string) (string, error) {
repoParts := strings.Split(repo, "/")
if len(repoParts) != 2 {
Expand Down Expand Up @@ -86,7 +86,7 @@ func TemplatesExist(repo, branch string) (string, error) {
return tmplPath, nil
}

// ExecRunnableTmplStr executes a template string with the runnable's data
// ExecRunnableTmplStr executes a template string with the runnable's data.
func ExecRunnableTmplStr(templateStr string, runnable *directive.Runnable) (string, error) {
templateData := makeTemplateData(runnable)

Expand All @@ -103,14 +103,14 @@ func ExecRunnableTmplStr(templateStr string, runnable *directive.Runnable) (stri
return builder.String(), nil
}

// ExecRunnableTmpl copies a template
// ExecRunnableTmpl copies a template.
func ExecRunnableTmpl(cwd, name, templatesPath string, runnable *directive.Runnable) error {
templateData := makeTemplateData(runnable)

return ExecTmplDir(cwd, name, templatesPath, runnable.Lang, templateData)
}

// ExecTmplDir copies a generic templated directory
// ExecTmplDir copies a generic templated directory.
func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interface{}) error {
templatePath := filepath.Join(templatesPath, tmplName)
targetPath := filepath.Join(cwd, name)
Expand All @@ -123,8 +123,8 @@ func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interfa
return errors.Wrap(err, "failed to Stat template directory")
}

var err error = filepath.Walk(templatePath, func(path string, info os.FileInfo, _ error) error {
var relPath string = strings.Replace(path, templatePath, "", 1)
var err = filepath.Walk(templatePath, func(path string, info os.FileInfo, _ error) error {
var relPath = strings.Replace(path, templatePath, "", 1)
if relPath == "" {
return nil
}
Expand All @@ -144,15 +144,15 @@ func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interfa
targetRelPath = builder.String()
}

// check if the target path is an existing file, and skip it if so
// Check if the target path is an existing file, and skip it if so.
if _, err := os.Stat(filepath.Join(targetPath, targetRelPath)); err != nil {
if os.IsNotExist(err) {
// that's fine, continue
// That's fine, continue.
} else {
return errors.Wrap(err, "failed to Stat")
}
} else {
// if the target file already exists, we're going to skip the rest since we don't want to overwrite
// If the target file already exists, we're going to skip the rest since we don't want to overwrite.
return nil
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interfa
return err
}

// downloadZip downloads a ZIP from a particular branch of the Subo repo
// downloadZip downloads a ZIP from a particular branch of the Subo repo.
func downloadZip(repo, branch, targetPath string) (string, error) {
url := fmt.Sprintf("https://github.com/%s/archive/%s.zip", repo, branch)

Expand All @@ -213,7 +213,7 @@ func downloadZip(repo, branch, targetPath string) (string, error) {

filePath := filepath.Join(targetPath, "subo.zip")

// check if the zip already exists, and delete it if it does
// Check if the zip already exists, and delete it if it does.
if _, err := os.Stat(filePath); err == nil {
if err := os.Remove(filePath); err != nil {
return "", errors.Wrap(err, "failed to delete exising templates zip")
Expand All @@ -237,7 +237,7 @@ func downloadZip(repo, branch, targetPath string) (string, error) {
return filePath, nil
}

// extractZip extracts a ZIP file
// extractZip extracts a ZIP file.
func extractZip(filePath, destPath, branchDirName string) (string, error) {
escapedFilepath := strings.ReplaceAll(filePath, " ", "\\ ")
escapedDestPath := strings.ReplaceAll(destPath, " ", "\\ ") + string(filepath.Separator)
Expand All @@ -257,7 +257,7 @@ func extractZip(filePath, destPath, branchDirName string) (string, error) {
return filepath.Join(existingPath, "templates"), nil
}

// makeTemplateData makes data to be used in templates
// makeTemplateData makes data to be used in templates.
func makeTemplateData(runnable *directive.Runnable) tmplData {
nameCamel := ""
nameParts := strings.Split(runnable.Name, "-")
Expand Down
6 changes: 3 additions & 3 deletions root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ including building WebAssembly Runnables and Atmo projects.`,

cmd.SetVersionTemplate("Subo CLI v{{.Version}}\n")

// create commands
// create commands.
create := &cobra.Command{
Use: "create",
Short: "create a runnable, project, or handler",
Expand All @@ -38,10 +38,10 @@ including building WebAssembly Runnables and Atmo projects.`,
create.AddCommand(command.CreateRunnableCmd())
create.AddCommand(command.CreateHandlerCmd())

// compute network related commands
// compute network related commands.
cmd.AddCommand(computeCommand())

// add top-level commands to root
// add top-level commands to root.
cmd.AddCommand(create)
cmd.AddCommand(command.BuildCmd())
cmd.AddCommand(command.DevCmd())
Expand Down
Loading

0 comments on commit 50648ba

Please sign in to comment.