| // Copyright 2023 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 jiri contains jiri manifest schema definitions copied from Jiri's |
| // source code. |
| // |
| // Only fields relevant to roller configuration are included, others are |
| // omitted. |
| package jiri |
| |
| import ( |
| "encoding/xml" |
| "errors" |
| "fmt" |
| "io" |
| "os" |
| ) |
| |
| type Manifest struct { |
| Projects []Project `xml:"projects>project"` |
| Packages []Package `xml:"packages>package"` |
| XMLName struct{} `xml:"manifest"` |
| } |
| |
| // Project represents a jiri project. |
| type Project struct { |
| // Name is the project name. |
| Name string `xml:"name,attr,omitempty"` |
| |
| // Remote is the project remote. |
| Remote string `xml:"remote,attr,omitempty"` |
| |
| // RemoteBranch is the name of the remote branch to track. |
| RemoteBranch string `xml:"remotebranch,attr,omitempty"` |
| } |
| |
| // Package struct represents the <package> tag in manifest files. |
| type Package struct { |
| // Name represents the remote cipd path of the package. |
| Name string `xml:"name,attr"` |
| |
| // Version represents the version tag of the cipd package. |
| Version string `xml:"version,attr"` |
| } |
| |
| // LoadManifest reads a Jiri manifest from disk. |
| func LoadManifest(path string) (*Manifest, error) { |
| b, err := os.ReadFile(path) |
| if err != nil { |
| return nil, err |
| } |
| var manifest Manifest |
| if err := xml.Unmarshal(b, &manifest); err != nil { |
| if errors.Is(err, io.EOF) { |
| return nil, fmt.Errorf("invalid XML in %s", path) |
| } |
| return nil, err |
| } |
| return &manifest, nil |
| } |