Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
tools
godep
Commits
b8fe416f
Commit
b8fe416f
authored
9 years ago
by
Edward Muller
Browse files
Options
Download
Email Patches
Plain Diff
Additional moves
parent
b348158c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
111 deletions
+116
-111
dep.go
dep.go
+0
-93
diff.go
diff.go
+1
-3
godepfile.go
godepfile.go
+104
-9
save.go
save.go
+10
-6
save_test.go
save_test.go
+1
-0
No files found.
dep.go
View file @
b8fe416f
...
...
@@ -2,14 +2,10 @@ package main
import
(
"encoding/json"
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
)
...
...
@@ -32,95 +28,6 @@ type Dependency struct {
vcs
*
VCS
}
// pkgs is the list of packages to read dependencies
func
(
g
*
Godeps
)
Load
(
pkgs
[]
*
Package
,
destImportPath
string
)
error
{
var
err1
error
var
path
[]
string
for
_
,
p
:=
range
pkgs
{
if
p
.
Standard
{
log
.
Println
(
"ignoring stdlib package:"
,
p
.
ImportPath
)
continue
}
if
p
.
Error
.
Err
!=
""
{
log
.
Println
(
p
.
Error
.
Err
)
err1
=
errors
.
New
(
"error loading packages"
)
continue
}
path
=
append
(
path
,
p
.
ImportPath
)
path
=
append
(
path
,
p
.
Deps
...
)
}
var
testImports
[]
string
for
_
,
p
:=
range
pkgs
{
testImports
=
append
(
testImports
,
p
.
TestImports
...
)
testImports
=
append
(
testImports
,
p
.
XTestImports
...
)
}
ps
,
err
:=
LoadPackages
(
testImports
...
)
if
err
!=
nil
{
return
err
}
for
_
,
p
:=
range
ps
{
if
p
.
Standard
{
continue
}
if
p
.
Error
.
Err
!=
""
{
log
.
Println
(
p
.
Error
.
Err
)
err1
=
errors
.
New
(
"error loading packages"
)
continue
}
path
=
append
(
path
,
p
.
ImportPath
)
path
=
append
(
path
,
p
.
Deps
...
)
}
for
i
,
p
:=
range
path
{
path
[
i
]
=
unqualify
(
p
)
}
sort
.
Strings
(
path
)
path
=
uniq
(
path
)
ps
,
err
=
LoadPackages
(
path
...
)
if
err
!=
nil
{
return
err
}
seen
:=
[]
string
{
destImportPath
}
for
_
,
pkg
:=
range
ps
{
if
pkg
.
Error
.
Err
!=
""
{
log
.
Println
(
pkg
.
Error
.
Err
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
if
pkg
.
Standard
||
containsPathPrefix
(
seen
,
pkg
.
ImportPath
)
{
continue
}
seen
=
append
(
seen
,
pkg
.
ImportPath
)
vcs
,
reporoot
,
err
:=
VCSFromDir
(
pkg
.
Dir
,
filepath
.
Join
(
pkg
.
Root
,
"src"
))
if
err
!=
nil
{
log
.
Println
(
err
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
id
,
err
:=
vcs
.
identify
(
pkg
.
Dir
)
if
err
!=
nil
{
log
.
Println
(
err
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
if
vcs
.
isDirty
(
pkg
.
Dir
,
id
)
{
log
.
Println
(
"dirty working tree (please commit changes):"
,
pkg
.
Dir
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
comment
:=
vcs
.
describe
(
pkg
.
Dir
,
id
)
g
.
Deps
=
append
(
g
.
Deps
,
Dependency
{
ImportPath
:
pkg
.
ImportPath
,
Rev
:
id
,
Comment
:
comment
,
dir
:
pkg
.
Dir
,
ws
:
pkg
.
Root
,
root
:
filepath
.
ToSlash
(
reporoot
),
vcs
:
vcs
,
})
}
return
err1
}
func
ReadGodeps
(
path
string
,
g
*
Godeps
)
error
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
diff.go
View file @
b8fe416f
...
...
@@ -20,9 +20,7 @@ previous 'go save' execution.
}
func
runDiff
(
cmd
*
Command
,
args
[]
string
)
{
var
gold
Godeps
_
,
err
:=
readGodeps
(
&
gold
)
gold
,
err
:=
readGodeps
()
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
...
...
This diff is collapsed.
Click to expand it.
godepfile.go
View file @
b8fe416f
...
...
@@ -2,8 +2,11 @@ package main
import
(
"encoding/json"
"errors"
"log"
"os"
"path/filepath"
"sort"
)
var
godepsFile
=
filepath
.
Join
(
"Godeps"
,
"Godeps.json"
)
...
...
@@ -15,22 +18,114 @@ type Godeps struct {
GoVersion
string
Packages
[]
string
`json:",omitempty"`
// Arguments to save, if any.
Deps
[]
Dependency
isFile
bool
is
Old
File
bool
}
func
readGodeps
(
g
*
Godeps
)
(
isFile
bool
,
err
error
)
{
func
readGodeps
()
(
Godeps
,
error
)
{
var
godeps
Godeps
f
,
err
:=
os
.
Open
(
godepsFile
)
if
err
!=
nil
{
isFile
=
true
f
,
err
=
os
.
Open
(
"Godeps"
)
if
os
.
IsNotExist
(
err
)
{
return
godeps
,
nil
}
if
err
==
nil
{
godeps
.
isOldFile
=
true
}
}
if
os
.
IsNotExist
(
err
)
{
return
false
,
nil
if
err
!=
nil
{
return
godeps
,
err
}
defer
f
.
Close
()
err
=
json
.
NewDecoder
(
f
)
.
Decode
(
&
godeps
)
return
godeps
,
err
}
// pkgs is the list of packages to read dependencies
func
(
g
*
Godeps
)
Load
(
pkgs
[]
*
Package
,
destImportPath
string
)
error
{
var
err1
error
var
path
[]
string
for
_
,
p
:=
range
pkgs
{
if
p
.
Standard
{
log
.
Println
(
"ignoring stdlib package:"
,
p
.
ImportPath
)
continue
}
if
p
.
Error
.
Err
!=
""
{
log
.
Println
(
p
.
Error
.
Err
)
err1
=
errors
.
New
(
"error loading packages"
)
continue
}
path
=
append
(
path
,
p
.
ImportPath
)
path
=
append
(
path
,
p
.
Deps
...
)
}
var
testImports
[]
string
for
_
,
p
:=
range
pkgs
{
testImports
=
append
(
testImports
,
p
.
TestImports
...
)
testImports
=
append
(
testImports
,
p
.
XTestImports
...
)
}
ps
,
err
:=
LoadPackages
(
testImports
...
)
if
err
!=
nil
{
return
false
,
err
return
err
}
for
_
,
p
:=
range
ps
{
if
p
.
Standard
{
continue
}
if
p
.
Error
.
Err
!=
""
{
log
.
Println
(
p
.
Error
.
Err
)
err1
=
errors
.
New
(
"error loading packages"
)
continue
}
path
=
append
(
path
,
p
.
ImportPath
)
path
=
append
(
path
,
p
.
Deps
...
)
}
for
i
,
p
:=
range
path
{
path
[
i
]
=
unqualify
(
p
)
}
sort
.
Strings
(
path
)
path
=
uniq
(
path
)
ps
,
err
=
LoadPackages
(
path
...
)
if
err
!=
nil
{
return
err
}
seen
:=
[]
string
{
destImportPath
}
for
_
,
pkg
:=
range
ps
{
if
pkg
.
Error
.
Err
!=
""
{
log
.
Println
(
pkg
.
Error
.
Err
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
if
pkg
.
Standard
||
containsPathPrefix
(
seen
,
pkg
.
ImportPath
)
{
continue
}
seen
=
append
(
seen
,
pkg
.
ImportPath
)
vcs
,
reporoot
,
err
:=
VCSFromDir
(
pkg
.
Dir
,
filepath
.
Join
(
pkg
.
Root
,
"src"
))
if
err
!=
nil
{
log
.
Println
(
err
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
id
,
err
:=
vcs
.
identify
(
pkg
.
Dir
)
if
err
!=
nil
{
log
.
Println
(
err
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
if
vcs
.
isDirty
(
pkg
.
Dir
,
id
)
{
log
.
Println
(
"dirty working tree (please commit changes):"
,
pkg
.
Dir
)
err1
=
errors
.
New
(
"error loading dependencies"
)
continue
}
comment
:=
vcs
.
describe
(
pkg
.
Dir
,
id
)
g
.
Deps
=
append
(
g
.
Deps
,
Dependency
{
ImportPath
:
pkg
.
ImportPath
,
Rev
:
id
,
Comment
:
comment
,
dir
:
pkg
.
Dir
,
ws
:
pkg
.
Root
,
root
:
filepath
.
ToSlash
(
reporoot
),
vcs
:
vcs
,
})
}
err
=
json
.
NewDecoder
(
f
)
.
Decode
(
g
)
f
.
Close
()
return
isFile
,
err
return
err1
}
This diff is collapsed.
Click to expand it.
save.go
View file @
b8fe416f
...
...
@@ -96,20 +96,24 @@ func save(pkgs []string) error {
if
err
!=
nil
{
return
err
}
var
gold
Godeps
old
IsFile
,
err
:=
readGodeps
(
&
gold
)
g
old
,
err
:=
readGodeps
()
if
err
!=
nil
{
return
err
}
gnew
:=
&
Godeps
{
ImportPath
:
dot
.
ImportPath
,
GoVersion
:
ver
,
}
if
len
(
pkgs
)
>
0
{
gnew
.
Packages
=
pkgs
}
el
se
{
switch
len
(
pkgs
)
{
ca
se
0
:
pkgs
=
[]
string
{
"."
}
default
:
gnew
.
Packages
=
pkgs
}
a
,
err
:=
LoadPackages
(
pkgs
...
)
if
err
!=
nil
{
return
err
...
...
@@ -126,7 +130,7 @@ func save(pkgs []string) error {
if
err
!=
nil
{
return
err
}
if
old
Is
File
{
if
g
old
.
isOld
File
{
// If we are migrating from an old format file,
// we require that the listed version of every
// dependency must be installed in GOPATH, so it's
...
...
This diff is collapsed.
Click to expand it.
save_test.go
View file @
b8fe416f
...
...
@@ -1015,6 +1015,7 @@ func TestSave(t *testing.T) {
t
.
Fatal
(
err
)
}
const
scratch
=
"godeptest"
os
.
RemoveAll
(
scratch
)
defer
os
.
RemoveAll
(
scratch
)
for
_
,
test
:=
range
cases
{
err
=
os
.
RemoveAll
(
scratch
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment