Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse dependency architecture even without version #868

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ List of contributors, in chronological order:
* William Manley (https://github.com/wmanley)
* Shengjing Zhu (https://github.com/zhsj)
* Nabil Bendafi (https://github.com/nabilbendafi)
* Raphael Medaer (https://github.com/rmedaer)
20 changes: 13 additions & 7 deletions deb/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ func ParseDependencyVariants(variants string) (l []Dependency, err error) {
return
}

// ParseDependencyArch parses the dependency name in format "pkg:any" into name and architecture
func ParseDependencyArch(d *Dependency) {
if strings.ContainsRune(d.Pkg, ':') {
parts := strings.SplitN(d.Pkg, ":", 2)
d.Pkg, d.Architecture = parts[0], parts[1]
if d.Architecture == "any" {
d.Architecture = ""
}
}
}

// ParseDependency parses dependency in format "pkg (>= 1.35) [arch]" into parts
func ParseDependency(dep string) (d Dependency, err error) {
if strings.HasSuffix(dep, "}") {
Expand All @@ -252,6 +263,7 @@ func ParseDependency(dep string) (d Dependency, err error) {
if !strings.HasSuffix(dep, ")") {
d.Pkg = strings.TrimSpace(dep)
d.Relation = VersionDontCare
ParseDependencyArch(&d)
return
}

Expand All @@ -262,13 +274,7 @@ func ParseDependency(dep string) (d Dependency, err error) {
}

d.Pkg = strings.TrimSpace(dep[0:i])
if strings.ContainsRune(d.Pkg, ':') {
parts := strings.SplitN(d.Pkg, ":", 2)
d.Pkg, d.Architecture = parts[0], parts[1]
if d.Architecture == "any" {
d.Architecture = ""
}
}
ParseDependencyArch(&d)

rel := ""
if dep[i+1] == '>' || dep[i+1] == '<' || dep[i+1] == '=' {
Expand Down
4 changes: 4 additions & 0 deletions deb/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,8 @@ func (s *VersionSuite) TestDependencyString(c *C) {
d, _ = ParseDependency("dpkg")
d.Architecture = "i386"
c.Check(d.String(), Equals, "dpkg [i386]")

d, _ = ParseDependency("dpkg:any")
c.Check(d.Pkg, Equals, "dpkg")
c.Check(d.Architecture, Equals, "")
}