Discard duplicate operations to copy files to snapshot

Header include directories are copied into the snapshot separately for
each cc library that exports them. However, the same include
directories can be exported by multiple libraries which caused ninja
error because two separate rules (albeit identical) were defined to
create the same files.

This avoids the duplicate ninja rules by detecting and discarding
duplicate copies, i.e. where the source and destination are the same.
It will also report an error if two or more different source files are
copied to the same destination.

Bug: 142918168
Test: m nothing
      added test and verified it produced two identical copy rules
      fixed code and verified duplicate copy rules had been eliminated

Change-Id: I39e37405035bee5093f96e03248e9e29ed30962c
This commit is contained in:
Paul Duffin
2019-12-11 18:34:15 +00:00
parent ac6e608da7
commit c62a5107f8
2 changed files with 61 additions and 7 deletions

View File

@@ -184,6 +184,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
sdk: s,
version: "current",
snapshotDir: snapshotDir.OutputPath,
copies: make(map[string]string),
filesToZip: []android.Path{bp.path},
bpFile: bpFile,
prebuiltModules: make(map[string]*bpModule),
@@ -337,6 +338,11 @@ type snapshotBuilder struct {
version string
snapshotDir android.OutputPath
bpFile *bpFile
// Map from destination to source of each copy - used to eliminate duplicates and
// detect conflicts.
copies map[string]string
filesToZip android.Paths
zipsToMerge android.Paths
@@ -345,13 +351,22 @@ type snapshotBuilder struct {
}
func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) {
path := s.snapshotDir.Join(s.ctx, dest)
s.ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: src,
Output: path,
})
s.filesToZip = append(s.filesToZip, path)
if existing, ok := s.copies[dest]; ok {
if existing != src.String() {
s.ctx.ModuleErrorf("conflicting copy, %s copied from both %s and %s", dest, existing, src)
return
}
} else {
path := s.snapshotDir.Join(s.ctx, dest)
s.ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: src,
Output: path,
})
s.filesToZip = append(s.filesToZip, path)
s.copies[dest] = src.String()
}
}
func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string) {