Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame^] | 1 | // Copyright 2020 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package cc |
| 15 | |
| 16 | import ( |
| 17 | "strings" |
| 18 | |
| 19 | "android/soong/android" |
| 20 | ) |
| 21 | |
| 22 | var ( |
| 23 | headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} |
| 24 | ) |
| 25 | |
| 26 | type snapshotLibraryInterface interface { |
| 27 | exportedFlagsProducer |
| 28 | libraryInterface |
| 29 | } |
| 30 | |
| 31 | var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil) |
| 32 | var _ snapshotLibraryInterface = (*libraryDecorator)(nil) |
| 33 | |
| 34 | func exportedHeaders(ctx android.SingletonContext, l exportedFlagsProducer) android.Paths { |
| 35 | var ret android.Paths |
| 36 | |
| 37 | // Headers in the source tree should be globbed. On the contrast, generated headers |
| 38 | // can't be globbed, and they should be manually collected. |
| 39 | // So, we first filter out intermediate directories (which contains generated headers) |
| 40 | // from exported directories, and then glob headers under remaining directories. |
| 41 | for _, path := range append(l.exportedDirs(), l.exportedSystemDirs()...) { |
| 42 | dir := path.String() |
| 43 | // Skip if dir is for generated headers |
| 44 | if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) { |
| 45 | continue |
| 46 | } |
| 47 | exts := headerExts |
| 48 | // Glob all files under this special directory, because of C++ headers. |
| 49 | if strings.HasPrefix(dir, "external/libcxx/include") { |
| 50 | exts = []string{""} |
| 51 | } |
| 52 | for _, ext := range exts { |
| 53 | glob, err := ctx.GlobWithDeps(dir+"/**/*"+ext, nil) |
| 54 | if err != nil { |
| 55 | ctx.Errorf("%#v\n", err) |
| 56 | return nil |
| 57 | } |
| 58 | for _, header := range glob { |
| 59 | if strings.HasSuffix(header, "/") { |
| 60 | continue |
| 61 | } |
| 62 | ret = append(ret, android.PathForSource(ctx, header)) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Collect generated headers |
| 68 | for _, header := range append(l.exportedGeneratedHeaders(), l.exportedDeps()...) { |
| 69 | // TODO(b/148123511): remove exportedDeps after cleaning up genrule |
| 70 | if strings.HasSuffix(header.Base(), "-phony") { |
| 71 | continue |
| 72 | } |
| 73 | ret = append(ret, header) |
| 74 | } |
| 75 | |
| 76 | return ret |
| 77 | } |
| 78 | |
| 79 | func copyFile(ctx android.SingletonContext, path android.Path, out string) android.OutputPath { |
| 80 | outPath := android.PathForOutput(ctx, out) |
| 81 | ctx.Build(pctx, android.BuildParams{ |
| 82 | Rule: android.Cp, |
| 83 | Input: path, |
| 84 | Output: outPath, |
| 85 | Description: "Cp " + out, |
| 86 | Args: map[string]string{ |
| 87 | "cpFlags": "-f -L", |
| 88 | }, |
| 89 | }) |
| 90 | return outPath |
| 91 | } |
| 92 | |
| 93 | func writeStringToFile(ctx android.SingletonContext, content, out string) android.OutputPath { |
| 94 | outPath := android.PathForOutput(ctx, out) |
| 95 | ctx.Build(pctx, android.BuildParams{ |
| 96 | Rule: android.WriteFile, |
| 97 | Output: outPath, |
| 98 | Description: "WriteFile " + out, |
| 99 | Args: map[string]string{ |
| 100 | "content": content, |
| 101 | }, |
| 102 | }) |
| 103 | return outPath |
| 104 | } |