Track dependencies when reading notice files

Track which files are read by the notice file indexer and add a flag
to textnotice and htmlnotice to support writing them out.

Bug: 207445310
Test: textnotice_test
Test: htmlnotice_test
Change-Id: Ib74706b8a87a5ed9268a0fe37982ecf89f4e227d
diff --git a/tools/compliance/noticeindex.go b/tools/compliance/noticeindex.go
index 58b1c3b..7bebe3d 100644
--- a/tools/compliance/noticeindex.go
+++ b/tools/compliance/noticeindex.go
@@ -62,6 +62,8 @@
 	targetHashes map[*TargetNode]map[hash]struct{}
 	// projectName maps project directory names to project name text.
 	projectName map[string]string
+	// files lists all the files accessed during indexing
+	files []string
 }
 
 // IndexLicenseTexts creates a hashed index of license texts for `lg` and `rs`
@@ -71,14 +73,17 @@
 		rs = ResolveNotices(lg)
 	}
 	ni := &NoticeIndex{
-		lg, rs, ShippedNodes(lg), rootFS,
-		make(map[string]hash),
-		make(map[hash][]byte),
-		make(map[hash]map[string]map[string]struct{}),
-		make(map[string]map[hash]map[string]struct{}),
-		make(map[string]map[hash]struct{}),
-		make(map[*TargetNode]map[hash]struct{}),
-		make(map[string]string),
+		lg:             lg,
+		rs:             rs,
+		shipped:        ShippedNodes(lg),
+		rootFS:         rootFS,
+		hash:           make(map[string]hash),
+		text:           make(map[hash][]byte),
+		hashLibInstall: make(map[hash]map[string]map[string]struct{}),
+		installHashLib: make(map[string]map[hash]map[string]struct{}),
+		libHash:        make(map[string]map[hash]struct{}),
+		targetHashes:   make(map[*TargetNode]map[hash]struct{}),
+		projectName:    make(map[string]string),
 	}
 
 	// index adds all license texts for `tn` to the index.
@@ -208,6 +213,13 @@
 	return c
 }
 
+// InputNoticeFiles returns the list of files that were hashed during IndexLicenseTexts.
+func (ni *NoticeIndex) InputNoticeFiles() []string {
+	files := append([]string(nil), ni.files...)
+	sort.Strings(files)
+	return files
+}
+
 // HashLibs returns the ordered array of library names using the license text
 // hashed as `h`.
 func (ni *NoticeIndex) HashLibs(h hash) []string {
@@ -449,6 +461,8 @@
 		ni.text[hash] = text
 	}
 
+	ni.files = append(ni.files, file)
+
 	return nil
 }