Merge "Add AllMetadataFiles() method to track deps." am: 904dd87a75 am: 389f4adfb0

Original change: https://android-review.googlesource.com/c/platform/build/+/2275192

Change-Id: I6234d098fb6b0f60ad6ccc7fe485ccb439592266
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2022-10-28 05:40:25 +00:00
committed by Automerger Merge Worker

View File

@@ -118,6 +118,7 @@ func (pm *ProjectMetadata) UrlsByTypeName() ProjectUrlMap {
// a `ProjectMetadata`, pm (can be nil even without error), or a non-nil `err`.
type projectIndex struct {
project string
path string
pm *ProjectMetadata
err error
done chan struct{}
@@ -230,6 +231,19 @@ func (ix *Index) MetadataForProjects(projects ...string) ([]*ProjectMetadata, er
return result, nil
}
// AllMetadataFiles returns the sorted list of all METADATA files read thus far.
func (ix *Index) AllMetadataFiles() []string {
files := []string(nil)
ix.projects.Range(func(key, value any) bool {
pi := value.(*projectIndex)
if pi.path != "" {
files = append(files, pi.path)
}
return true
})
return files
}
// readMetadataFile tries to read and parse a METADATA file at `path` for `project`.
func (ix *Index) readMetadataFile(pi *projectIndex, path string) {
f, err := ix.rootFS.Open(path)
@@ -250,9 +264,24 @@ func (ix *Index) readMetadataFile(pi *projectIndex, path string) {
pm := &ProjectMetadata{project: pi.project}
err = uo.Unmarshal(data, &pm.proto)
if err != nil {
pi.err = fmt.Errorf("error in project %q metadata %q: %w", pi.project, path, err)
pi.err = fmt.Errorf(`error in project %q METADATA %q: %v
METADATA and METADATA.android files must parse as text protobufs
defined by
build/soong/compliance/project_metadata_proto/project_metadata.proto
* unknown fields don't matter
* check invalid ENUM names
* check quoting
* check unescaped nested quotes
* check the comment marker for protobuf is '#' not '//'
if importing a library that uses a different sort of METADATA file, add
a METADATA.android file beside it to parse instead
`, pi.project, path, err)
return
}
pi.path = path
pi.pm = pm
}