Add AllMetadataFiles() method to track deps.
Improve METADATA parsing error message. Example error message (for an unqoted string url starting with ssh:): ============ error in project "<redacted>" METADATA "<redacted>/METADATA": proto: (line 4:12): invalid value for string type: ssh 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 ============ Bug: 254534552 Test: m droid dist cts alllicensemetadata Change-Id: Ie5c0adc7362941e455dd522baaa31f2913d7db5f
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user