Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 5cd267f

Browse files
authored
Merge pull request #1951 from sdboyer/new-status-ii
status: Accommodate new verify systems
2 parents 7ca88e9 + 054c665 commit 5cd267f

File tree

2 files changed

+120
-47
lines changed

2 files changed

+120
-47
lines changed

cmd/dep/status.go

+84-25
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import (
3030
const availableTemplateVariables = "ProjectRoot, Constraint, Version, Revision, Latest, and PackageCount."
3131
const availableDefaultTemplateVariables = `.Projects[]{
3232
.ProjectRoot,.Source,.Constraint,.PackageCount,.Packages[],
33-
.Locked{.Branch,.Revision,.Version},.Latest{.Revision,.Version}
33+
.PruneOpts,.Digest,.Locked{.Branch,.Revision,.Version},
34+
.Latest{.Revision,.Version}
3435
},
3536
.Metadata{
36-
.AnalyzerName,.AnalyzerVersion,.InputsDigest,.SolverName,
37+
.AnalyzerName,.AnalyzerVersion,.InputImports,.SolverName,
3738
.SolverVersion
3839
}`
3940

@@ -405,6 +406,8 @@ func (out *templateOutput) DetailLine(ds *DetailStatus) error {
405406
Constraint: ds.getConsolidatedConstraint(),
406407
Locked: formatDetailVersion(ds.Version, ds.Revision),
407408
Latest: formatDetailLatestVersion(ds.Latest, ds.hasError),
409+
PruneOpts: ds.getPruneOpts(),
410+
Digest: ds.Digest.String(),
408411
PackageCount: ds.PackageCount,
409412
Source: ds.Source,
410413
Packages: ds.Packages,
@@ -757,6 +760,8 @@ type rawDetailProject struct {
757760
Packages []string
758761
Locked rawDetailVersion
759762
Latest rawDetailVersion
763+
PruneOpts string
764+
Digest string
760765
Source string `json:"Source,omitempty"`
761766
Constraint string
762767
PackageCount int
@@ -765,7 +770,8 @@ type rawDetailProject struct {
765770
type rawDetailMetadata struct {
766771
AnalyzerName string
767772
AnalyzerVersion int
768-
InputsDigest string
773+
InputsDigest string // deprecated
774+
InputImports []string
769775
SolverName string
770776
SolverVersion int
771777
}
@@ -778,6 +784,7 @@ func newRawMetadata(metadata *dep.SolveMeta) rawDetailMetadata {
778784
return rawDetailMetadata{
779785
AnalyzerName: metadata.AnalyzerName,
780786
AnalyzerVersion: metadata.AnalyzerVersion,
787+
InputImports: metadata.InputImports,
781788
SolverName: metadata.SolverName,
782789
SolverVersion: metadata.SolverVersion,
783790
}
@@ -802,8 +809,10 @@ type BasicStatus struct {
802809
// information included about a a project in a lock file.
803810
type DetailStatus struct {
804811
BasicStatus
805-
Packages []string
806-
Source string
812+
Packages []string
813+
Source string
814+
PruneOpts gps.PruneOptions
815+
Digest verify.VersionedDigest
807816
}
808817

809818
func (bs *BasicStatus) getConsolidatedConstraint() string {
@@ -849,6 +858,10 @@ func (bs *BasicStatus) getConsolidatedLatest(revSize uint8) string {
849858
return latest
850859
}
851860

861+
func (ds *DetailStatus) getPruneOpts() string {
862+
return (ds.PruneOpts & ^gps.PruneNestedVendorDirs).String()
863+
}
864+
852865
func (bs *BasicStatus) marshalJSON() *rawStatus {
853866
return &rawStatus{
854867
ProjectRoot: bs.ProjectRoot,
@@ -868,6 +881,8 @@ func (ds *DetailStatus) marshalJSON() *rawDetailProject {
868881
Constraint: rawStatus.Constraint,
869882
Locked: formatDetailVersion(ds.Version, ds.Revision),
870883
Latest: formatDetailLatestVersion(ds.Latest, ds.hasError),
884+
PruneOpts: ds.getPruneOpts(),
885+
Digest: ds.Digest.String(),
871886
Source: ds.Source,
872887
Packages: ds.Packages,
873888
PackageCount: ds.PackageCount,
@@ -926,9 +941,10 @@ func (cmd *statusCommand) runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Proje
926941

927942
lsat := verify.LockSatisfiesInputs(p.Lock, p.Manifest, params.RootPackageTree)
928943
if lsat.Satisfied() {
929-
// If these are equal, we're guaranteed that the lock is a transitively
930-
// complete picture of all deps. That eliminates the need for at least
931-
// some checks.
944+
// If the lock satisfies the inputs, we're guaranteed (barring manual
945+
// meddling, about which we can do nothing) that the lock is a
946+
// transitively complete picture of all deps. That eliminates the need
947+
// for some checks.
932948

933949
logger.Println("Checking upstream projects:")
934950

@@ -945,7 +961,7 @@ func (cmd *statusCommand) runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Proje
945961
wg.Add(1)
946962
logger.Printf("(%d/%d) %s\n", i+1, len(slp), proj.Ident().ProjectRoot)
947963

948-
go func(proj gps.LockedProject) {
964+
go func(proj verify.VerifiableProject) {
949965
bs := BasicStatus{
950966
ProjectRoot: string(proj.Ident().ProjectRoot),
951967
PackageCount: len(proj.Packages()),
@@ -1043,12 +1059,14 @@ func (cmd *statusCommand) runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Proje
10431059
if cmd.detail {
10441060
ds.Source = proj.Ident().Source
10451061
ds.Packages = proj.Packages()
1062+
ds.PruneOpts = proj.PruneOpts
1063+
ds.Digest = proj.Digest
10461064
}
10471065

10481066
dsCh <- &ds
10491067

10501068
wg.Done()
1051-
}(proj)
1069+
}(proj.(verify.VerifiableProject))
10521070
}
10531071

10541072
wg.Wait()
@@ -1118,12 +1136,6 @@ func (cmd *statusCommand) runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Proje
11181136
return false, errCount, err
11191137
}
11201138

1121-
// Hash digest mismatch may indicate that some deps are no longer
1122-
// needed, some are missing, or that some constraints or source
1123-
// locations have changed.
1124-
//
1125-
// It's possible for digests to not match, but still have a correct
1126-
// lock.
11271139
rm, _ := ptree.ToReachMap(true, true, false, p.Manifest.IgnoredPackages())
11281140

11291141
external := rm.FlattenFn(paths.IsStandardImportPath)
@@ -1406,28 +1418,75 @@ func parseStatusTemplate(format string) (*template.Template, error) {
14061418
"dec": func(i int) int {
14071419
return i - 1
14081420
},
1421+
"tomlStrSplit": tomlStrSplit,
1422+
"tomlStrSplit2": func(strlist []string, level int) string {
1423+
// Hardcode to two spaces.
1424+
inbracket, inp := strings.Repeat(" ", level), strings.Repeat(" ", level+1)
1425+
switch len(strlist) {
1426+
case 0:
1427+
return "[]"
1428+
case 1:
1429+
return fmt.Sprintf("[\"%s\"]", strlist[0])
1430+
default:
1431+
var buf bytes.Buffer
1432+
1433+
fmt.Fprintf(&buf, "[\n")
1434+
for _, str := range strlist {
1435+
fmt.Fprintf(&buf, "%s\"%s\",\n", inp, str)
1436+
}
1437+
fmt.Fprintf(&buf, "%s]", inbracket)
1438+
1439+
return buf.String()
1440+
}
1441+
},
14091442
}).Parse(format)
14101443

14111444
return tmpl, err
14121445
}
14131446

1447+
func tomlStrSplit(strlist []string) string {
1448+
switch len(strlist) {
1449+
case 0:
1450+
return "[]"
1451+
case 1:
1452+
return fmt.Sprintf("[\"%s\"]", strlist[0])
1453+
default:
1454+
var buf bytes.Buffer
1455+
1456+
// Hardcode to two spaces.
1457+
fmt.Fprintf(&buf, "[\n")
1458+
for _, str := range strlist {
1459+
fmt.Fprintf(&buf, " \"%s\",\n", str)
1460+
}
1461+
fmt.Fprintf(&buf, " ]")
1462+
1463+
return buf.String()
1464+
}
1465+
}
1466+
14141467
const statusLockTemplate = `# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
14151468
14161469
1417-
{{range $p := .Projects}}[[projects]]{{if $p.Locked.Branch}}
1418-
branch = "{{$p.Locked.Branch}}"{{end}}
1470+
{{range $p := .Projects}}[[projects]]
1471+
{{- if $p.Locked.Branch}}
1472+
branch = "{{$p.Locked.Branch}}"
1473+
{{- end}}
1474+
digest = "{{$p.Digest}}"
14191475
name = "{{$p.ProjectRoot}}"
1420-
packages = [{{if eq 0 (len $p.Packages)}}"."]{{else}}{{range $i, $pkg := $p.Packages}}
1421-
"{{$pkg}}"{{if lt $i (dec (len $p.Packages))}},{{end}}{{end}}
1422-
]{{end}}
1423-
revision = "{{$p.Locked.Revision}}"{{if $p.Source}}
1424-
source = "{{$p.Source}}"{{end}}{{if $p.Locked.Version}}
1425-
version = "{{$p.Locked.Version}}"{{end}}
1476+
packages = {{(tomlStrSplit $p.Packages)}}
1477+
pruneopts = "{{$p.PruneOpts}}"
1478+
revision = "{{$p.Locked.Revision}}"
1479+
{{- if $p.Source}}
1480+
source = "{{$p.Source}}"
1481+
{{- end}}
1482+
{{- if $p.Locked.Version}}
1483+
version = "{{$p.Locked.Version}}"
1484+
{{- end}}
14261485
14271486
{{end}}[solve-meta]
14281487
analyzer-name = "{{.Metadata.AnalyzerName}}"
14291488
analyzer-version = {{.Metadata.AnalyzerVersion}}
1430-
inputs-digest = "{{.Metadata.InputsDigest}}"
1489+
input-imports = {{(tomlStrSplit .Metadata.InputImports)}}
14311490
solver-name = "{{.Metadata.SolverName}}"
14321491
solver-version = {{.Metadata.SolverVersion}}
14331492
`

cmd/dep/status_test.go

+36-22
Original file line numberDiff line numberDiff line change
@@ -871,64 +871,82 @@ const expectedStatusDetail = `# This file is autogenerated, do not edit; changes
871871
%s[solve-meta]
872872
analyzer-name = "dep"
873873
analyzer-version = 1
874-
inputs-digest = "900e50172c505781bfed67991919eccea483d78173f8e5c74404a5f6d05858bb"
874+
input-imports = %s
875875
solver-name = "gps-cdcl"
876876
solver-version = 1
877877
`
878878

879-
var expectedStatusMetadata = rawDetailMetadata{
880-
AnalyzerName: "dep",
881-
AnalyzerVersion: 1,
882-
InputsDigest: "900e50172c505781bfed67991919eccea483d78173f8e5c74404a5f6d05858bb",
883-
SolverName: "gps-cdcl",
884-
SolverVersion: 1,
885-
}
886-
887879
func TestStatusDetailTemplates(t *testing.T) {
880+
expectedStatusMetadata := rawDetailMetadata{
881+
AnalyzerName: "dep",
882+
AnalyzerVersion: 1,
883+
SolverName: "gps-cdcl",
884+
SolverVersion: 1,
885+
}
886+
expectWithInputs := expectedStatusMetadata
887+
expectWithInputs.InputImports = []string{"github.com/akutz/one", "github.com/akutz/three/a"}
888+
888889
testCases := []struct {
889890
name string
890891
tpl string
891892
exp string
892893
data rawDetail
893894
}{
895+
{
896+
name: "Lock Template No Projects",
897+
tpl: statusLockTemplate,
898+
exp: fmt.Sprintf(expectedStatusDetail, "", tomlStrSplit(nil)),
899+
data: rawDetail{
900+
Metadata: expectedStatusMetadata,
901+
},
902+
},
894903
{
895904
name: "Lock Template",
896905
tpl: statusLockTemplate,
897906
exp: fmt.Sprintf(expectedStatusDetail, `[[projects]]
898907
branch = "master"
908+
digest = "1:cbcdef1234"
899909
name = "github.com/akutz/one"
900910
packages = ["."]
911+
pruneopts = "UT"
901912
revision = "b78744579491c1ceeaaa3b40205e56b0591b93a3"
902913
903914
[[projects]]
915+
digest = "1:dbcdef1234"
904916
name = "github.com/akutz/two"
905917
packages = [
906918
".",
907-
"helloworld"
919+
"helloworld",
908920
]
921+
pruneopts = "NUT"
909922
revision = "12bd96e66386c1960ab0f74ced1362f66f552f7b"
910923
version = "v1.0.0"
911924
912925
[[projects]]
913926
branch = "feature/morning"
927+
digest = "1:abcdef1234"
914928
name = "github.com/akutz/three"
915929
packages = [
916930
"a",
917931
"b",
918-
"c"
932+
"c",
919933
]
934+
pruneopts = "NUT"
920935
revision = "890a5c3458b43e6104ff5da8dfa139d013d77544"
921936
source = "https://github.com/mandy/three"
922937
923-
`),
938+
`, tomlStrSplit([]string{"github.com/akutz/one", "github.com/akutz/three/a"})),
924939
data: rawDetail{
925940
Projects: []rawDetailProject{
926941
rawDetailProject{
927942
Locked: rawDetailVersion{
928943
Branch: "master",
929944
Revision: "b78744579491c1ceeaaa3b40205e56b0591b93a3",
930945
},
946+
Packages: []string{"."},
931947
ProjectRoot: "github.com/akutz/one",
948+
PruneOpts: "UT",
949+
Digest: "1:cbcdef1234",
932950
},
933951
rawDetailProject{
934952
Locked: rawDetailVersion{
@@ -940,6 +958,8 @@ func TestStatusDetailTemplates(t *testing.T) {
940958
".",
941959
"helloworld",
942960
},
961+
PruneOpts: "NUT",
962+
Digest: "1:dbcdef1234",
943963
},
944964
rawDetailProject{
945965
Locked: rawDetailVersion{
@@ -952,18 +972,12 @@ func TestStatusDetailTemplates(t *testing.T) {
952972
"b",
953973
"c",
954974
},
955-
Source: "https://github.com/mandy/three",
975+
Source: "https://github.com/mandy/three",
976+
PruneOpts: "NUT",
977+
Digest: "1:abcdef1234",
956978
},
957979
},
958-
Metadata: expectedStatusMetadata,
959-
},
960-
},
961-
{
962-
name: "Lock Template No Projects",
963-
tpl: statusLockTemplate,
964-
exp: fmt.Sprintf(expectedStatusDetail, ""),
965-
data: rawDetail{
966-
Metadata: expectedStatusMetadata,
980+
Metadata: expectWithInputs,
967981
},
968982
},
969983
}

0 commit comments

Comments
 (0)