Skip to content

Commit 188f4cc

Browse files
committed
Fixed dot graph dependencies naming
1 parent ecd6cba commit 188f4cc

2 files changed

Lines changed: 50 additions & 21 deletions

File tree

internal/ospackage/ospackage.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ package ospackage
22

33
// PackageInfo holds everything you need to fetch + verify one artifact.
44
type PackageInfo struct {
5-
Name string // e.g. file name "abseil-cpp.rpm"
6-
Type string // e.g. "rpm", "deb", "apk"
7-
Description string // e.g. "Abseil C++ Common Libraries"
8-
Origin string // e.g. "Intel", the vendor or supplier of the package
9-
License string // e.g. "Apache-2.0"
10-
Version string // e.g. "7.88.1-10+deb12u5"
11-
Arch string // e.g. "x86_64", "noarch", "src"
12-
URL string // download URL
13-
Checksums []Checksum
14-
Provides []string // capabilities this package provides (rpm:entry names)
15-
Requires []string // capabilities this package requires
16-
RequiresVer []string // version constraints for the required capabilities
17-
Files []string // list of files in this package (rpm:files)
18-
PkgName string // name of the package
5+
Name string // e.g. file name "abseil-cpp.rpm"
6+
Type string // e.g. "rpm", "deb", "apk"
7+
Description string // e.g. "Abseil C++ Common Libraries"
8+
Origin string // e.g. "Intel", the vendor or supplier of the package
9+
License string // e.g. "Apache-2.0"
10+
Version string // e.g. "7.88.1-10+deb12u5"
11+
Arch string // e.g. "x86_64", "noarch", "src"
12+
URL string // download URL
13+
Checksums []Checksum
14+
Provides []string // capabilities this package provides (rpm:entry names)
15+
Requires []string // capabilities this package requires
16+
RequiresVer []string // version constraints for the required capabilities
17+
Files []string // list of files in this package (rpm:files)
18+
PkgName string // name of the package
19+
RequiresPkgNames []string // canonical package names of resolved dependencies (used for DOT graph generation)
1920
}
2021

2122
// Checksum holds the algorithm and value of a checksum.

internal/ospackage/rpmutils/resolver.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,38 @@ func GenerateDot(pkgs []ospackage.PackageInfo, file string, pkgSources map[strin
188188
if pkg.Name == "" {
189189
continue
190190
}
191-
// Extract clean package name for display (e.g., "libgcrypt" instead of "libgcrypt-1.10.3-1.azl3.x86_64.rpm")
192191
// Note: Multiple package versions (e.g., glibc-2.38 and glibc-2.35) will both produce "glibc"
193192
// This causes duplicate node declarations in the DOT file, which is valid - GraphViz merges them.
194193
// For visualization purposes, we only care about package relationships, not specific versions.
195-
cleanName := extractBasePackageNameFromFile(pkg.Name)
194+
cleanName := pkg.PkgName
195+
if cleanName == "" {
196+
// Fallback to Name if PkgName is not set (for backward compatibility with test data)
197+
cleanName = pkg.Name
198+
}
196199
if _, err := fmt.Fprintf(writer, " \"%s\";\n", cleanName); err != nil {
197200
return fmt.Errorf("writing DOT node for %s: %w", cleanName, err)
198201
}
199-
for _, dep := range pkg.Requires {
202+
// Use RequiresPkgNames if available (populated during dependency resolution with canonical names)
203+
// Otherwise fall back to Requires with extraction logic for backward compatibility
204+
dependencies := pkg.RequiresPkgNames
205+
if len(dependencies) == 0 {
206+
dependencies = pkg.Requires
207+
}
208+
209+
for _, dep := range dependencies {
200210
if dep == "" {
201211
continue
202212
}
203-
// Extract clean dependency name for edges (handles capabilities and package requirements)
204-
cleanDep := extractBaseRequirement(dep)
205-
// Also trim package filenames (e.g., "glibc-2.38-16.azl3.x86_64.rpm" -> "glibc")
206-
cleanDep = extractBasePackageNameFromFile(cleanDep)
213+
cleanDep := dep
214+
215+
// If using fallback Requires field, apply extraction to handle filenames and capabilities
216+
if len(pkg.RequiresPkgNames) == 0 {
217+
// Extract clean dependency name for edges (handles capabilities and package requirements)
218+
cleanDep = extractBaseRequirement(dep)
219+
// Also trim package filenames (e.g., "glibc-2.38-16.azl3.x86_64.rpm" -> "glibc")
220+
cleanDep = extractBasePackageNameFromFile(cleanDep)
221+
}
222+
207223
edgeKey := cleanName + "|" + cleanDep
208224
if edgesWritten[edgeKey] {
209225
continue
@@ -791,6 +807,12 @@ func ResolveDependencies(requested []ospackage.PackageInfo, all []ospackage.Pack
791807
// Append to parent's Requires field even if already resolved
792808
if resultPkg, exists := resultMap[cur.Name]; exists {
793809
resultPkg.Requires = append(resultPkg.Requires, filename)
810+
// Also populate RequiresPkgNames with the canonical package name for DOT graph generation
811+
if depPkg, depExists := resultMap[filename]; depExists && depPkg.PkgName != "" {
812+
resultPkg.RequiresPkgNames = append(resultPkg.RequiresPkgNames, depPkg.PkgName)
813+
} else {
814+
resultPkg.RequiresPkgNames = append(resultPkg.RequiresPkgNames, filename)
815+
}
794816
}
795817

796818
continue
@@ -812,6 +834,12 @@ func ResolveDependencies(requested []ospackage.PackageInfo, all []ospackage.Pack
812834
// Update the parent's Requires field with the chosen candidate's name
813835
if resultPkg, exists := resultMap[cur.Name]; exists {
814836
resultPkg.Requires = append(resultPkg.Requires, chosenCandidate.Name)
837+
// Also populate RequiresPkgNames with the canonical package name for DOT graph generation
838+
if chosenCandidate.PkgName != "" {
839+
resultPkg.RequiresPkgNames = append(resultPkg.RequiresPkgNames, chosenCandidate.PkgName)
840+
} else {
841+
resultPkg.RequiresPkgNames = append(resultPkg.RequiresPkgNames, chosenCandidate.Name)
842+
}
815843
}
816844

817845
// Add chosen candidate to the queue for further processing

0 commit comments

Comments
 (0)