Skip to content

Commit

Permalink
Fix parsing Julia v1.0 Manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
Octogonapus committed Feb 9, 2024
1 parent 8cc7d40 commit f112af8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/julia/manifest/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func (p *Parser) Parse(r dio.ReadSeekerAt) ([]types.Library, []types.Dependency,
var primMan primitiveManifest
var manMetadata toml.MetaData
decoder := toml.NewDecoder(r)
// Try to read the old Manifest format. If that fails, try the new format.
if _, err := decoder.Decode(&oldDeps); err != nil {
// Try to read the old Manifest format. This can also read the v1.0 Manifest format, which we parse out later.
var err error
if manMetadata, err = decoder.Decode(&oldDeps); err != nil {
if _, err = r.Seek(0, io.SeekStart); err != nil {
return nil, nil, xerrors.Errorf("seek error: %w", err)
}
Expand Down Expand Up @@ -144,6 +145,19 @@ func decodeDependency(man *primitiveManifest, dep primitiveDependency, metadata
return dep, nil
}

// The deps could also be in the format from v1.0:
// [[A]]
// [A.deps]
// B = "..."
var possibleDepsMapv1_0 map[string]string
err = metadata.PrimitiveDecode(dep.Dependencies, &possibleDepsMapv1_0)
if err == nil {
possibleUuids := maps.Values(possibleDepsMapv1_0)
sort.Strings(possibleUuids)
dep.DependsOn = possibleUuids
return dep, nil
}

// The other possibility is a map where the manifest looks like
// [deps.A.deps]
// B = "..."
Expand Down
6 changes: 6 additions & 0 deletions pkg/julia/manifest/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func TestParse(t *testing.T) {
want: juliaV1_9ShadowedDepLibs,
wantDeps: juliaV1_9ShadowedDepDeps,
},
{
name: "julia v1.0 format",
file: "testdata/julia_v1.0_format/Manifest.toml",
want: juliaV1_0FormatLibs,
wantDeps: juliaV1_0FormatDeps,
},
}

for _, tt := range tests {
Expand Down
15 changes: 15 additions & 0 deletions pkg/julia/manifest/parse_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ var (
juliaV1_9ShadowedDepDeps = []types.Dependency{
{ID: "ead4f63c-334e-11e9-00e6-e7f0a5f21b60", DependsOn: []string{"f41f7b98-334e-11e9-1257-49272045fb24"}},
}

juliaV1_0FormatLibs = []types.Library{
{ID: "767738be-2f1f-45a9-b806-0234f3164144", Name: "Foo", Version: "unknown", Locations: []types.Location{{StartLine: 1, EndLine: 5}}},
{ID: "6f418443-bd2e-4783-b551-cdbac608adf2", Name: "Foo", Version: "unknown", Locations: []types.Location{{StartLine: 7, EndLine: 10}}},
{ID: "2a550a13-6bab-4a91-a4ee-dff34d6b99d0", Name: "Bar", Version: "unknown", Locations: []types.Location{{StartLine: 12, EndLine: 14}}},
{ID: "6801f525-dc68-44e8-a4e8-cabd286279e7", Name: "Baz", Version: "unknown", Locations: []types.Location{{StartLine: 19, EndLine: 21}}},
{ID: "b5ec9b9c-e354-47fd-b367-a348bdc8f909", Name: "Qux", Version: "unknown", Locations: []types.Location{{StartLine: 26, EndLine: 28}}},
}

juliaV1_0FormatDeps = []types.Dependency{
{ID: "767738be-2f1f-45a9-b806-0234f3164144", DependsOn: []string{"2a550a13-6bab-4a91-a4ee-dff34d6b99d0", "6801f525-dc68-44e8-a4e8-cabd286279e7", "b5ec9b9c-e354-47fd-b367-a348bdc8f909"}},
{ID: "6f418443-bd2e-4783-b551-cdbac608adf2", DependsOn: []string{"b5ec9b9c-e354-47fd-b367-a348bdc8f909"}},
{ID: "2a550a13-6bab-4a91-a4ee-dff34d6b99d0", DependsOn: []string{"6801f525-dc68-44e8-a4e8-cabd286279e7", "6f418443-bd2e-4783-b551-cdbac608adf2"}},
{ID: "6801f525-dc68-44e8-a4e8-cabd286279e7", DependsOn: []string{"6f418443-bd2e-4783-b551-cdbac608adf2", "b5ec9b9c-e354-47fd-b367-a348bdc8f909"}},
}
)
28 changes: 28 additions & 0 deletions pkg/julia/manifest/testdata/julia_v1.0_format/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[[Foo]]
deps = ["Bar", "Baz", "Qux"]
uuid = "767738be-2f1f-45a9-b806-0234f3164144"
git-tree-sha1 = "7c626031568a5e432112a74009c3763f9b851e3e"
path = "deps/Foo1"

[[Foo]]
deps = ["Qux"]
uuid = "6f418443-bd2e-4783-b551-cdbac608adf2"
path = "deps/Foo2.jl"

[[Bar]]
uuid = "2a550a13-6bab-4a91-a4ee-dff34d6b99d0"
path = "deps/Bar"
[Bar.deps]
Baz = "6801f525-dc68-44e8-a4e8-cabd286279e7"
Foo = "6f418443-bd2e-4783-b551-cdbac608adf2"

[[Baz]]
uuid = "6801f525-dc68-44e8-a4e8-cabd286279e7"
git-tree-sha1 = "efc7e24c53d6a328011975294a2c75fed2f9800a"
[Baz.deps]
Foo = "6f418443-bd2e-4783-b551-cdbac608adf2"
Qux = "b5ec9b9c-e354-47fd-b367-a348bdc8f909"

[[Qux]]
uuid = "b5ec9b9c-e354-47fd-b367-a348bdc8f909"
path = "deps/Qux.jl"
6 changes: 6 additions & 0 deletions pkg/julia/manifest/testdata/julia_v1.0_format/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "TestProject"
uuid = "84c38c17-0c6f-4d12-a694-d20b69c16777"

[deps]
Foo = "767738be-2f1f-45a9-b806-0234f3164144"
Bar = "2a550a13-6bab-4a91-a4ee-dff34d6b99d0"

0 comments on commit f112af8

Please sign in to comment.