Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Make Path Handling More Robust
Browse files Browse the repository at this point in the history
- 🐛 Handle GOPATH with multiple entries (fixes #18)
- 💄 Replace `~` and `$HOME` in paths with appropriate value
- 💄 Enhance fix for #17 with patch to go (https://code.google.com/p/go/issues/detail?id=7724)
  • Loading branch information
joefitzgerald committed Apr 8, 2014
1 parent 3b46077 commit 1fb5093
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## v1.0.3 (April 7th, 2014)

* :bug: Handle GOPATH with multiple entries (fixes #18)
* :lipstick: Replace `~` and `$HOME` in paths with appropriate value
* :lipstick: Enhance fix for #17 with patch to go (https://code.google.com/p/go/issues/detail?id=7724)

## v1.0.2 (April 7th, 2014)

* :lipstick: Redirect build output to temporary directory (fixes #17)
Expand Down
22 changes: 21 additions & 1 deletion lib/dispatch.coffee
Expand Up @@ -151,7 +151,27 @@ class Dispatch
gopath = gopathEnv if gopathEnv? and gopathEnv isnt ''
gopath = gopathConfig if not environmentOverridesConfig and gopathConfig? and gopathConfig isnt ''
gopath = gopathConfig if gopath is ''
return gopath
return @replaceTokensInPath(gopath, true)

replaceTokensInPath: (path, skipGoPath) ->
return '' unless path?
unless skipGoPath or path.toUpperCase().indexOf('$GOPATH') is -1
path = @replaceGoPathToken(path)
unless path.indexOf('~') is -1
home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
path = path.replace(/~/i, home)
unless path.toUpperCase().indexOf('$HOME') is -1
home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
path = path.replace(/\$HOME/i, home)
return path

replaceGoPathToken: (path) ->
gopath = @buildGoPath()
return path unless gopath? and gopath isnt ''
return path.replace(/^\$GOPATH\//i, gopath.replace(/^\s+|\s+$/g, "") + '/') if path.indexOf(':') is -1
gopaths = gopath.split(':')
return path.replace(/^\$GOPATH\//i, gopaths[0].replace(/^\s+|\s+$/g, "") + '/') if gopaths? and _.size(gopaths) > 0 and gopaths[0]? and gopaths[0] isnt ''
return path

isValidEditorView: (editorView) ->
editorView?.getEditor()?.getGrammar()?.scopeName is 'source.go'
Expand Down
1 change: 1 addition & 0 deletions lib/gobuild.coffee
Expand Up @@ -69,6 +69,7 @@ class Gobuild
outputPath = path.join(@tempDir, output)
args = ['build', '-o', outputPath, '.']
cmd = atom.config.get('go-plus.goExecutablePath')
cmd = @dispatch.replaceTokensInPath(cmd, true)
errored = false
proc = spawn(cmd, args, {cwd: cwd, env: env})
proc.on 'error', (error) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/gofmt.coffee
Expand Up @@ -37,7 +37,7 @@ class Gofmt
gopath = @dispatch.buildGoPath()
args = ['-w', buffer.getPath()]
cmd = atom.config.get('go-plus.gofmtPath')
cmd = cmd.replace(/^\$GOPATH\//i, gopath + '/') if gopath? and gopath isnt ''
cmd = @dispatch.replaceTokensInPath(cmd)
errored = false
proc = spawn(cmd, args)
proc.on 'error', (error) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/golint.coffee
Expand Up @@ -37,7 +37,7 @@ class Golint
gopath = @dispatch.buildGoPath()
args = [buffer.getPath()]
cmd = atom.config.get('go-plus.golintPath')
cmd = cmd.replace(/^\$GOPATH\//i, gopath + '/') if gopath? and gopath isnt ''
cmd = @dispatch.replaceTokensInPath(cmd)
errored = false
proc = spawn(cmd, args)
proc.on 'error', (error) =>
Expand Down
1 change: 1 addition & 0 deletions lib/govet.coffee
Expand Up @@ -36,6 +36,7 @@ class Govet
return
args = [@name, buffer.getPath()]
cmd = atom.config.get('go-plus.goExecutablePath')
cmd = @dispatch.replaceTokensInPath(cmd, true)
errored = false
proc = spawn(cmd, args)
proc.on 'error', (error) =>
Expand Down

0 comments on commit 1fb5093

Please sign in to comment.