From f112af857aa86ef68d681c8142822df82db17624 Mon Sep 17 00:00:00 2001 From: Octogonapus Date: Fri, 9 Feb 2024 12:21:13 -0500 Subject: [PATCH] Fix parsing Julia v1.0 Manifests --- pkg/julia/manifest/parse.go | 18 ++++++++++-- pkg/julia/manifest/parse_test.go | 6 ++++ pkg/julia/manifest/parse_testcase.go | 15 ++++++++++ .../testdata/julia_v1.0_format/Manifest.toml | 28 +++++++++++++++++++ .../testdata/julia_v1.0_format/Project.toml | 6 ++++ 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 pkg/julia/manifest/testdata/julia_v1.0_format/Manifest.toml create mode 100644 pkg/julia/manifest/testdata/julia_v1.0_format/Project.toml diff --git a/pkg/julia/manifest/parse.go b/pkg/julia/manifest/parse.go index 06cbaafc..68e648ed 100644 --- a/pkg/julia/manifest/parse.go +++ b/pkg/julia/manifest/parse.go @@ -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) } @@ -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 = "..." diff --git a/pkg/julia/manifest/parse_test.go b/pkg/julia/manifest/parse_test.go index 60785d91..a3ef555f 100644 --- a/pkg/julia/manifest/parse_test.go +++ b/pkg/julia/manifest/parse_test.go @@ -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 { diff --git a/pkg/julia/manifest/parse_testcase.go b/pkg/julia/manifest/parse_testcase.go index 8740abfe..ce6c2742 100644 --- a/pkg/julia/manifest/parse_testcase.go +++ b/pkg/julia/manifest/parse_testcase.go @@ -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"}}, + } ) diff --git a/pkg/julia/manifest/testdata/julia_v1.0_format/Manifest.toml b/pkg/julia/manifest/testdata/julia_v1.0_format/Manifest.toml new file mode 100644 index 00000000..a5a89306 --- /dev/null +++ b/pkg/julia/manifest/testdata/julia_v1.0_format/Manifest.toml @@ -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" diff --git a/pkg/julia/manifest/testdata/julia_v1.0_format/Project.toml b/pkg/julia/manifest/testdata/julia_v1.0_format/Project.toml new file mode 100644 index 00000000..9d42e37c --- /dev/null +++ b/pkg/julia/manifest/testdata/julia_v1.0_format/Project.toml @@ -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"