xref: /aosp_15_r20/tools/treble/build/treble_build/app/repo.go (revision 105f628577ac4ba0e277a494fbb614ed8c12a994)
1*105f6285SAndroid Build Coastguard Worker// Copyright 2022 The Android Open Source Project
2*105f6285SAndroid Build Coastguard Worker//
3*105f6285SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*105f6285SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*105f6285SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*105f6285SAndroid Build Coastguard Worker//
7*105f6285SAndroid Build Coastguard Worker//      http://www.apache.org/licenses/LICENSE-2.0
8*105f6285SAndroid Build Coastguard Worker//
9*105f6285SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*105f6285SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*105f6285SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*105f6285SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*105f6285SAndroid Build Coastguard Worker// limitations under the License.
14*105f6285SAndroid Build Coastguard Workerpackage app
15*105f6285SAndroid Build Coastguard Worker
16*105f6285SAndroid Build Coastguard Workerimport (
17*105f6285SAndroid Build Coastguard Worker	"encoding/xml"
18*105f6285SAndroid Build Coastguard Worker	"io/ioutil"
19*105f6285SAndroid Build Coastguard Worker)
20*105f6285SAndroid Build Coastguard Worker
21*105f6285SAndroid Build Coastguard Workertype RepoRemote struct {
22*105f6285SAndroid Build Coastguard Worker	Name     string `xml:"name,attr"`
23*105f6285SAndroid Build Coastguard Worker	Revision string `xml:"fetch,attr"`
24*105f6285SAndroid Build Coastguard Worker}
25*105f6285SAndroid Build Coastguard Workertype RepoDefault struct {
26*105f6285SAndroid Build Coastguard Worker	Remote   string `xml:"remote,attr"`
27*105f6285SAndroid Build Coastguard Worker	Revision string `xml:"revision,attr"`
28*105f6285SAndroid Build Coastguard Worker}
29*105f6285SAndroid Build Coastguard Workertype RepoProject struct {
30*105f6285SAndroid Build Coastguard Worker	Groups   string  `xml:"groups,attr"`
31*105f6285SAndroid Build Coastguard Worker	Name     string  `xml:"name,attr"`
32*105f6285SAndroid Build Coastguard Worker	Revision string  `xml:"revision,attr"`
33*105f6285SAndroid Build Coastguard Worker	Path     string  `xml:"path,attr"`
34*105f6285SAndroid Build Coastguard Worker	Remote   *string `xml:"remote,attr"`
35*105f6285SAndroid Build Coastguard Worker}
36*105f6285SAndroid Build Coastguard Workertype RepoManifest struct {
37*105f6285SAndroid Build Coastguard Worker	XMLName  xml.Name      `xml:"manifest"`
38*105f6285SAndroid Build Coastguard Worker	Remotes  []RepoRemote  `xml:"remote"`
39*105f6285SAndroid Build Coastguard Worker	Default  RepoDefault   `xml:"default"`
40*105f6285SAndroid Build Coastguard Worker	Projects []RepoProject `xml:"project"`
41*105f6285SAndroid Build Coastguard Worker}
42*105f6285SAndroid Build Coastguard Worker
43*105f6285SAndroid Build Coastguard Worker// Parse a repo manifest file
44*105f6285SAndroid Build Coastguard Workerfunc ParseXml(filename string) (*RepoManifest, error) {
45*105f6285SAndroid Build Coastguard Worker	data, err := ioutil.ReadFile(filename)
46*105f6285SAndroid Build Coastguard Worker	if err != nil {
47*105f6285SAndroid Build Coastguard Worker		return nil, err
48*105f6285SAndroid Build Coastguard Worker	}
49*105f6285SAndroid Build Coastguard Worker	v := &RepoManifest{}
50*105f6285SAndroid Build Coastguard Worker	err = xml.Unmarshal(data, &v)
51*105f6285SAndroid Build Coastguard Worker	if err != nil {
52*105f6285SAndroid Build Coastguard Worker		return nil, err
53*105f6285SAndroid Build Coastguard Worker	}
54*105f6285SAndroid Build Coastguard Worker	return v, nil
55*105f6285SAndroid Build Coastguard Worker}
56