#46 cross platform support

This commit is contained in:
Jeevanandam M
2016-06-07 00:16:51 -07:00
parent 4b9e74e1ea
commit e485de7e9c
5 changed files with 29 additions and 30 deletions

View File

@@ -88,7 +88,8 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) {
// Add in build flags // Add in build flags
flags = append(flags, buildFlags...) 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")) flags = append(flags, path.Join(revel.ImportPath, "app", "tmp"))
buildCmd := exec.Command(goPath, flags...) buildCmd := exec.Command(goPath, flags...)
@@ -143,7 +144,7 @@ func getAppVersion() string {
// Check for the git binary // Check for the git binary
if gitPath, err := exec.LookPath("git"); err == nil { if gitPath, err := exec.LookPath("git"); err == nil {
// Check for the .git directory // Check for the .git directory
gitDir := path.Join(revel.BasePath, ".git") gitDir := filepath.Join(revel.BasePath, ".git")
info, err := os.Stat(gitDir) info, err := os.Stat(gitDir)
if (err != nil && os.IsNotExist(err)) || !info.IsDir() { if (err != nil && os.IsNotExist(err)) || !info.IsDir() {
return "" return ""
@@ -171,7 +172,7 @@ func cleanSource(dirs ...string) {
func cleanDir(dir string) { func cleanDir(dir string) {
revel.INFO.Println("Cleaning dir " + dir) revel.INFO.Println("Cleaning dir " + dir)
tmpPath := path.Join(revel.AppPath, dir) tmpPath := filepath.Join(revel.AppPath, dir)
f, err := os.Open(tmpPath) f, err := os.Open(tmpPath)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
@@ -186,7 +187,7 @@ func cleanDir(dir string) {
} }
} else { } else {
for _, info := range infos { for _, info := range infos {
path := path.Join(tmpPath, info.Name()) path := filepath.Join(tmpPath, info.Name())
if info.IsDir() { if info.IsDir() {
err := os.RemoveAll(path) err := os.RemoveAll(path)
if err != nil { if err != nil {
@@ -212,14 +213,14 @@ func genSource(dir, filename, templateSource string, args map[string]interface{}
// Create a fresh dir. // Create a fresh dir.
cleanSource(dir) cleanSource(dir)
tmpPath := path.Join(revel.AppPath, dir) tmpPath := filepath.Join(revel.AppPath, dir)
err := os.Mkdir(tmpPath, 0777) err := os.Mkdir(tmpPath, 0777)
if err != nil && !os.IsExist(err) { if err != nil && !os.IsExist(err) {
revel.ERROR.Fatalf("Failed to make '%v' directory: %v", dir, err) revel.ERROR.Fatalf("Failed to make '%v' directory: %v", dir, err)
} }
// Create the file // Create the file
file, err := os.Create(path.Join(tmpPath, filename)) file, err := os.Create(filepath.Join(tmpPath, filename))
defer file.Close() defer file.Close()
if err != nil { if err != nil {
revel.ERROR.Fatalf("Failed to create file: %v", err) revel.ERROR.Fatalf("Failed to create file: %v", err)

View File

@@ -3,7 +3,6 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -52,7 +51,7 @@ func buildApp(args []string) {
// First, verify that it is either already empty or looks like a previous // First, verify that it is either already empty or looks like a previous
// build (to avoid clobbering anything) // 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) errorf("Abort: %s exists and does not look like a build directory.", destPath)
} }
@@ -69,14 +68,14 @@ func buildApp(args []string) {
// - app // - app
// Revel and the app are in a directory structure mirroring import path // Revel and the app are in a directory structure mirroring import path
srcPath := path.Join(destPath, "src") srcPath := filepath.Join(destPath, "src")
destBinaryPath := path.Join(destPath, filepath.Base(app.BinaryPath)) destBinaryPath := filepath.Join(destPath, filepath.Base(app.BinaryPath))
tmpRevelPath := path.Join(srcPath, filepath.FromSlash(revel.REVEL_IMPORT_PATH)) tmpRevelPath := filepath.Join(srcPath, filepath.FromSlash(revel.REVEL_IMPORT_PATH))
mustCopyFile(destBinaryPath, app.BinaryPath) mustCopyFile(destBinaryPath, app.BinaryPath)
mustChmod(destBinaryPath, 0755) mustChmod(destBinaryPath, 0755)
mustCopyDir(path.Join(tmpRevelPath, "conf"), path.Join(revel.RevelPath, "conf"), nil) mustCopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel.RevelPath, "conf"), nil)
mustCopyDir(path.Join(tmpRevelPath, "templates"), path.Join(revel.RevelPath, "templates"), nil) mustCopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel.RevelPath, "templates"), nil)
mustCopyDir(path.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil) mustCopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil)
// Find all the modules used and copy them over. // Find all the modules used and copy them over.
config := revel.Config.Raw() config := revel.Config.Raw()
@@ -99,14 +98,14 @@ func buildApp(args []string) {
} }
} }
for importPath, fsPath := range modulePaths { for importPath, fsPath := range modulePaths {
mustCopyDir(path.Join(srcPath, importPath), fsPath, nil) mustCopyDir(filepath.Join(srcPath, importPath), fsPath, nil)
} }
tmplData, runShPath := map[string]interface{}{ tmplData, runShPath := map[string]interface{}{
"BinName": filepath.Base(app.BinaryPath), "BinName": filepath.Base(app.BinaryPath),
"ImportPath": appImportPath, "ImportPath": appImportPath,
"Mode": mode, "Mode": mode,
}, path.Join(destPath, "run.sh") }, filepath.Join(destPath, "run.sh")
mustRenderTemplate( mustRenderTemplate(
runShPath, runShPath,

View File

@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"go/build" "go/build"
"os" "os"
"path" "path/filepath"
) )
var cmdClean = &Command{ var cmdClean = &Command{
@@ -38,8 +38,8 @@ func cleanApp(args []string) {
} }
purgeDirs := []string{ purgeDirs := []string{
path.Join(appPkg.Dir, "app", "tmp"), filepath.Join(appPkg.Dir, "app", "tmp"),
path.Join(appPkg.Dir, "app", "routes"), filepath.Join(appPkg.Dir, "app", "routes"),
} }
for _, dir := range purgeDirs { for _, dir := range purgeDirs {

View File

@@ -7,7 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path/filepath"
"strings" "strings"
"time" "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. // 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 { if err = os.RemoveAll(resultPath); err != nil {
errorf("Failed to remove test result directory %s: %s", resultPath, err) 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. // 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 { 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() 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. // Load the result template, which we execute for each suite.
module, _ := revel.ModuleByName("testrunner") 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 { if err := TemplateLoader.Refresh(); err != nil {
errorf("Failed to compile templates: %s", err) 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())) fmt.Printf("%8s%3s%6ds\n", suiteResultStr, suiteAlert, int(time.Since(startTime).Seconds()))
// Create the result HTML file. // Create the result HTML file.
suiteResultFilename := path.Join(resultPath, suiteResultFilename := filepath.Join(resultPath,
fmt.Sprintf("%s.%s.html", suite.Name, strings.ToLower(suiteResultStr))) fmt.Sprintf("%s.%s.html", suite.Name, strings.ToLower(suiteResultStr)))
suiteResultFile, err := os.Create(suiteResultFilename) suiteResultFile, err := os.Create(suiteResultFilename)
if err != nil { 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) { func writeResultFile(resultPath, name, content string) {
if err := ioutil.WriteFile(path.Join(resultPath, name), []byte(content), 0666); err != nil { if err := ioutil.WriteFile(filepath.Join(resultPath, name), []byte(content), 0666); err != nil {
errorf("Failed to write result file %s: %s", path.Join(resultPath, name), err) errorf("Failed to write result file %s: %s", filepath.Join(resultPath, name), err)
} }
} }

View File

@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"text/template" "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 // Get the relative path from the source base, and the corresponding path in
// the dest directory. // the dest directory.
relSrcPath := strings.TrimLeft(srcPath[len(srcDir):], string(os.PathSeparator)) 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. // Skip dot files and dot directories.
if strings.HasPrefix(relSrcPath, ".") { if strings.HasPrefix(relSrcPath, ".") {
@@ -82,7 +81,7 @@ func mustCopyDir(destDir, srcDir string, data map[string]interface{}) error {
// Create a subdirectory if necessary. // Create a subdirectory if necessary.
if info.IsDir() { if info.IsDir() {
err := os.MkdirAll(path.Join(destDir, relSrcPath), 0777) err := os.MkdirAll(filepath.Join(destDir, relSrcPath), 0777)
if !os.IsExist(err) { if !os.IsExist(err) {
panicOnError(err, "Failed to create directory") panicOnError(err, "Failed to create directory")
} }