| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package main |
| |
| import ( |
| "encoding/xml" |
| "fmt" |
| "io" |
| "io/ioutil" |
| ) |
| |
| type manifest struct { |
| XMLName xml.Name `xml:"manifest"` |
| PackageList packages `xml:"packages"` |
| } |
| |
| type packages struct { |
| XMLName xml.Name `xml:"packages"` |
| Packages []packageDef `xml:"package"` |
| } |
| |
| type packageDef struct { |
| XMLName xml.Name `xml:"package"` |
| Name string `xml:"name,attr"` |
| Version string `xml:"version,attr"` |
| } |
| |
| // Resolve the recipes package given a manifest input. |
| func resolveRecipesPackage(r io.Reader) (*packageDef, error) { |
| bytes, err := ioutil.ReadAll(r) |
| if err != nil { |
| return nil, fmt.Errorf("could not read input") |
| } |
| var manifest manifest |
| err = xml.Unmarshal(bytes, &manifest) |
| if err != nil { |
| return nil, fmt.Errorf("could not parse input as packages XML") |
| } |
| for _, pkg := range manifest.PackageList.Packages { |
| if pkg.Name != recipesPackageName { |
| continue |
| } |
| return &pkg, nil |
| } |
| return nil, fmt.Errorf("could not find recipes package") |
| } |