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 15package rust 16 17import ( 18 "android/soong/android" 19) 20 21func init() { 22 android.RegisterSingletonType("rustdoc", RustdocSingleton) 23} 24 25func RustdocSingleton() android.Singleton { 26 return &rustdocSingleton{} 27} 28 29type rustdocSingleton struct{} 30 31func (n *rustdocSingleton) GenerateBuildActions(ctx android.SingletonContext) { 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 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() { 47 zipCmd.Implicit(m.docTimestampFile.Path()) 48 } 49 } 50 }) 51 rule.Build("rustdoc-zip", "Zipping all built Rust documentation...") 52 ctx.Phony("rustdoc", docZip) 53} 54