Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 1 | // Copyright 2021 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 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | func init() { |
| 22 | android.RegisterSingletonType("rustdoc", RustdocSingleton) |
| 23 | } |
| 24 | |
| 25 | func RustdocSingleton() android.Singleton { |
| 26 | return &rustdocSingleton{} |
| 27 | } |
| 28 | |
| 29 | type rustdocSingleton struct{} |
| 30 | |
| 31 | func (n *rustdocSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Matthew Maurer | ca68c49 | 2021-08-20 13:02:25 -0700 | [diff] [blame] | 32 | docDir := android.PathForOutput(ctx, "rustdoc") |
| 33 | docZip := android.PathForOutput(ctx, "rustdoc.zip") |
| 34 | rule := android.NewRuleBuilder(pctx, ctx) |
| 35 | zipCmd := rule.Command().BuiltTool("soong_zip"). |
| 36 | FlagWithOutput("-o ", docZip). |
| 37 | FlagWithArg("-C ", docDir.String()). |
| 38 | FlagWithArg("-D ", docDir.String()) |
| 39 | |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 40 | ctx.VisitAllModules(func(module android.Module) { |
| 41 | if !module.Enabled() { |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | if m, ok := module.(*Module); ok { |
| 46 | if m.docTimestampFile.Valid() { |
Matthew Maurer | ca68c49 | 2021-08-20 13:02:25 -0700 | [diff] [blame] | 47 | zipCmd.Implicit(m.docTimestampFile.Path()) |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | }) |
Matthew Maurer | ca68c49 | 2021-08-20 13:02:25 -0700 | [diff] [blame] | 51 | rule.Build("rustdoc-zip", "Zipping all built Rust documentation...") |
| 52 | ctx.Phony("rustdoc", docZip) |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 53 | } |