Skip to content

Commit

Permalink
Fix: "revel package" includes modules in the package too
Browse files Browse the repository at this point in the history
Fixes revel#180
  • Loading branch information
robfig committed Jun 18, 2013
1 parent 5f8324e commit b0248f8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func LoadConfig(confName string) (*MergedConfig, error) {
return nil, err
}

func (c *MergedConfig) Raw() *config.Config {
return c.config
}

func (c *MergedConfig) SetSection(section string) {
c.section = section
}
Expand Down
19 changes: 17 additions & 2 deletions revel.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (

// Private
secretKey []byte // Key used to sign cookies. An empty key disables signing.
packaged bool // If true, this is running from a pre-built package.
)

func init() {
Expand Down Expand Up @@ -89,6 +90,7 @@ func Init(mode, importPath, srcPath string) {
// If the SourcePath was specified, assume both Revel and the app are within it.
SourcePath = path.Clean(SourcePath)
revelSourcePath = SourcePath
packaged = true
}

RevelPath = path.Join(revelSourcePath, filepath.FromSlash(REVEL_IMPORT_PATH))
Expand Down Expand Up @@ -231,13 +233,26 @@ func loadModules() {
continue
}

modPkg, err := build.Import(moduleImportPath, "", build.FindOnly)
modulePath, err := ResolveImportPath(moduleImportPath)
if err != nil {
log.Fatalln("Failed to load module. Import of", moduleImportPath, "failed:", err)
}
addModule(key[len("module."):], moduleImportPath, modulePath)
}
}

addModule(key[len("module."):], moduleImportPath, modPkg.Dir)
// ResolveImportPath returns the filesystem path for the given import path.
// Returns an error if the import path could not be found.
func ResolveImportPath(importPath string) (string, error) {
if packaged {
return path.Join(SourcePath, importPath), nil
}

modPkg, err := build.Import(importPath, "", build.FindOnly)
if err != nil {
return "", err
}
return modPkg.Dir, nil
}

func addModule(name, importPath, modulePath string) {
Expand Down
25 changes: 25 additions & 0 deletions revel/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
)

var cmdBuild = &Command{
Expand Down Expand Up @@ -59,6 +60,30 @@ func buildApp(args []string) {
mustCopyDir(path.Join(tmpRevelPath, "templates"), path.Join(revel.RevelPath, "templates"), nil)
mustCopyDir(path.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil)

// Find all the modules used and copy them over.
config := revel.Config.Raw()
modulePaths := make(map[string]string) // import path => filesystem path
for _, section := range config.Sections() {
options, _ := config.SectionOptions(section)
for _, key := range options {
if !strings.HasPrefix(key, "module.") {
continue
}
moduleImportPath, _ := config.String(section, key)
if moduleImportPath == "" {
continue
}
modulePath, err := revel.ResolveImportPath(moduleImportPath)
if err != nil {
revel.ERROR.Fatalln("Failed to load module %s: %s", key[len("module."):], err)
}
modulePaths[moduleImportPath] = modulePath
}
}
for importPath, fsPath := range modulePaths {
mustCopyDir(path.Join(srcPath, importPath), fsPath, nil)
}

tmplData := map[string]interface{}{
"BinName": filepath.Base(app.BinaryPath),
"ImportPath": appImportPath,
Expand Down

0 comments on commit b0248f8

Please sign in to comment.