mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-11 18:54:31 +00:00
#46 cross platform support
This commit is contained in:
@@ -88,7 +88,8 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) {
|
||||
// Add in build flags
|
||||
flags = append(flags, buildFlags...)
|
||||
|
||||
// The main path
|
||||
// This is Go main path
|
||||
// Note: It's not applicable for filepath.* usage
|
||||
flags = append(flags, path.Join(revel.ImportPath, "app", "tmp"))
|
||||
|
||||
buildCmd := exec.Command(goPath, flags...)
|
||||
@@ -143,7 +144,7 @@ func getAppVersion() string {
|
||||
// Check for the git binary
|
||||
if gitPath, err := exec.LookPath("git"); err == nil {
|
||||
// Check for the .git directory
|
||||
gitDir := path.Join(revel.BasePath, ".git")
|
||||
gitDir := filepath.Join(revel.BasePath, ".git")
|
||||
info, err := os.Stat(gitDir)
|
||||
if (err != nil && os.IsNotExist(err)) || !info.IsDir() {
|
||||
return ""
|
||||
@@ -171,7 +172,7 @@ func cleanSource(dirs ...string) {
|
||||
|
||||
func cleanDir(dir string) {
|
||||
revel.INFO.Println("Cleaning dir " + dir)
|
||||
tmpPath := path.Join(revel.AppPath, dir)
|
||||
tmpPath := filepath.Join(revel.AppPath, dir)
|
||||
f, err := os.Open(tmpPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
@@ -186,7 +187,7 @@ func cleanDir(dir string) {
|
||||
}
|
||||
} else {
|
||||
for _, info := range infos {
|
||||
path := path.Join(tmpPath, info.Name())
|
||||
path := filepath.Join(tmpPath, info.Name())
|
||||
if info.IsDir() {
|
||||
err := os.RemoveAll(path)
|
||||
if err != nil {
|
||||
@@ -212,14 +213,14 @@ func genSource(dir, filename, templateSource string, args map[string]interface{}
|
||||
|
||||
// Create a fresh dir.
|
||||
cleanSource(dir)
|
||||
tmpPath := path.Join(revel.AppPath, dir)
|
||||
tmpPath := filepath.Join(revel.AppPath, dir)
|
||||
err := os.Mkdir(tmpPath, 0777)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
revel.ERROR.Fatalf("Failed to make '%v' directory: %v", dir, err)
|
||||
}
|
||||
|
||||
// Create the file
|
||||
file, err := os.Create(path.Join(tmpPath, filename))
|
||||
file, err := os.Create(filepath.Join(tmpPath, filename))
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
revel.ERROR.Fatalf("Failed to create file: %v", err)
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -52,7 +51,7 @@ func buildApp(args []string) {
|
||||
|
||||
// First, verify that it is either already empty or looks like a previous
|
||||
// build (to avoid clobbering anything)
|
||||
if exists(destPath) && !empty(destPath) && !exists(path.Join(destPath, "run.sh")) {
|
||||
if exists(destPath) && !empty(destPath) && !exists(filepath.Join(destPath, "run.sh")) {
|
||||
errorf("Abort: %s exists and does not look like a build directory.", destPath)
|
||||
}
|
||||
|
||||
@@ -69,14 +68,14 @@ func buildApp(args []string) {
|
||||
// - app
|
||||
|
||||
// Revel and the app are in a directory structure mirroring import path
|
||||
srcPath := path.Join(destPath, "src")
|
||||
destBinaryPath := path.Join(destPath, filepath.Base(app.BinaryPath))
|
||||
tmpRevelPath := path.Join(srcPath, filepath.FromSlash(revel.REVEL_IMPORT_PATH))
|
||||
srcPath := filepath.Join(destPath, "src")
|
||||
destBinaryPath := filepath.Join(destPath, filepath.Base(app.BinaryPath))
|
||||
tmpRevelPath := filepath.Join(srcPath, filepath.FromSlash(revel.REVEL_IMPORT_PATH))
|
||||
mustCopyFile(destBinaryPath, app.BinaryPath)
|
||||
mustChmod(destBinaryPath, 0755)
|
||||
mustCopyDir(path.Join(tmpRevelPath, "conf"), path.Join(revel.RevelPath, "conf"), nil)
|
||||
mustCopyDir(path.Join(tmpRevelPath, "templates"), path.Join(revel.RevelPath, "templates"), nil)
|
||||
mustCopyDir(path.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil)
|
||||
mustCopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel.RevelPath, "conf"), nil)
|
||||
mustCopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel.RevelPath, "templates"), nil)
|
||||
mustCopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil)
|
||||
|
||||
// Find all the modules used and copy them over.
|
||||
config := revel.Config.Raw()
|
||||
@@ -99,14 +98,14 @@ func buildApp(args []string) {
|
||||
}
|
||||
}
|
||||
for importPath, fsPath := range modulePaths {
|
||||
mustCopyDir(path.Join(srcPath, importPath), fsPath, nil)
|
||||
mustCopyDir(filepath.Join(srcPath, importPath), fsPath, nil)
|
||||
}
|
||||
|
||||
tmplData, runShPath := map[string]interface{}{
|
||||
"BinName": filepath.Base(app.BinaryPath),
|
||||
"ImportPath": appImportPath,
|
||||
"Mode": mode,
|
||||
}, path.Join(destPath, "run.sh")
|
||||
}, filepath.Join(destPath, "run.sh")
|
||||
|
||||
mustRenderTemplate(
|
||||
runShPath,
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"go/build"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var cmdClean = &Command{
|
||||
@@ -38,8 +38,8 @@ func cleanApp(args []string) {
|
||||
}
|
||||
|
||||
purgeDirs := []string{
|
||||
path.Join(appPkg.Dir, "app", "tmp"),
|
||||
path.Join(appPkg.Dir, "app", "routes"),
|
||||
filepath.Join(appPkg.Dir, "app", "tmp"),
|
||||
filepath.Join(appPkg.Dir, "app", "routes"),
|
||||
}
|
||||
|
||||
for _, dir := range purgeDirs {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -79,7 +79,7 @@ You can add it to a run mode configuration with the following line:
|
||||
}
|
||||
|
||||
// Create a directory to hold the test result files.
|
||||
resultPath := path.Join(revel.BasePath, "test-results")
|
||||
resultPath := filepath.Join(revel.BasePath, "test-results")
|
||||
if err = os.RemoveAll(resultPath); err != nil {
|
||||
errorf("Failed to remove test result directory %s: %s", resultPath, err)
|
||||
}
|
||||
@@ -88,9 +88,9 @@ You can add it to a run mode configuration with the following line:
|
||||
}
|
||||
|
||||
// Direct all the output into a file in the test-results directory.
|
||||
file, err := os.OpenFile(path.Join(resultPath, "app.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
file, err := os.OpenFile(filepath.Join(resultPath, "app.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
errorf("Failed to create log file: %s", err)
|
||||
errorf("Failed to create test result log file: %s", err)
|
||||
}
|
||||
|
||||
app, reverr := harness.Build()
|
||||
@@ -144,7 +144,7 @@ You can add it to a run mode configuration with the following line:
|
||||
|
||||
// Load the result template, which we execute for each suite.
|
||||
module, _ := revel.ModuleByName("testrunner")
|
||||
TemplateLoader := revel.NewTemplateLoader([]string{path.Join(module.Path, "app", "views")})
|
||||
TemplateLoader := revel.NewTemplateLoader([]string{filepath.Join(module.Path, "app", "views")})
|
||||
if err := TemplateLoader.Refresh(); err != nil {
|
||||
errorf("Failed to compile templates: %s", err)
|
||||
}
|
||||
@@ -194,7 +194,7 @@ You can add it to a run mode configuration with the following line:
|
||||
}
|
||||
fmt.Printf("%8s%3s%6ds\n", suiteResultStr, suiteAlert, int(time.Since(startTime).Seconds()))
|
||||
// Create the result HTML file.
|
||||
suiteResultFilename := path.Join(resultPath,
|
||||
suiteResultFilename := filepath.Join(resultPath,
|
||||
fmt.Sprintf("%s.%s.html", suite.Name, strings.ToLower(suiteResultStr)))
|
||||
suiteResultFile, err := os.Create(suiteResultFilename)
|
||||
if err != nil {
|
||||
@@ -225,8 +225,8 @@ You can add it to a run mode configuration with the following line:
|
||||
}
|
||||
|
||||
func writeResultFile(resultPath, name, content string) {
|
||||
if err := ioutil.WriteFile(path.Join(resultPath, name), []byte(content), 0666); err != nil {
|
||||
errorf("Failed to write result file %s: %s", path.Join(resultPath, name), err)
|
||||
if err := ioutil.WriteFile(filepath.Join(resultPath, name), []byte(content), 0666); err != nil {
|
||||
errorf("Failed to write result file %s: %s", filepath.Join(resultPath, name), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
@@ -70,7 +69,7 @@ func mustCopyDir(destDir, srcDir string, data map[string]interface{}) error {
|
||||
// Get the relative path from the source base, and the corresponding path in
|
||||
// the dest directory.
|
||||
relSrcPath := strings.TrimLeft(srcPath[len(srcDir):], string(os.PathSeparator))
|
||||
destPath := path.Join(destDir, relSrcPath)
|
||||
destPath := filepath.Join(destDir, relSrcPath)
|
||||
|
||||
// Skip dot files and dot directories.
|
||||
if strings.HasPrefix(relSrcPath, ".") {
|
||||
@@ -82,7 +81,7 @@ func mustCopyDir(destDir, srcDir string, data map[string]interface{}) error {
|
||||
|
||||
// Create a subdirectory if necessary.
|
||||
if info.IsDir() {
|
||||
err := os.MkdirAll(path.Join(destDir, relSrcPath), 0777)
|
||||
err := os.MkdirAll(filepath.Join(destDir, relSrcPath), 0777)
|
||||
if !os.IsExist(err) {
|
||||
panicOnError(err, "Failed to create directory")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user