doc.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. package rust
  15. import (
  16. "android/soong/android"
  17. )
  18. func init() {
  19. android.RegisterParallelSingletonType("rustdoc", RustdocSingleton)
  20. }
  21. func RustdocSingleton() android.Singleton {
  22. return &rustdocSingleton{}
  23. }
  24. type rustdocSingleton struct{}
  25. func (n *rustdocSingleton) GenerateBuildActions(ctx android.SingletonContext) {
  26. docDir := android.PathForOutput(ctx, "rustdoc")
  27. docZip := android.PathForOutput(ctx, "rustdoc.zip")
  28. rule := android.NewRuleBuilder(pctx, ctx)
  29. zipCmd := rule.Command().BuiltTool("soong_zip").
  30. FlagWithOutput("-o ", docZip).
  31. FlagWithArg("-C ", docDir.String()).
  32. FlagWithArg("-D ", docDir.String())
  33. ctx.VisitAllModules(func(module android.Module) {
  34. if !module.Enabled() {
  35. return
  36. }
  37. if m, ok := module.(*Module); ok {
  38. if m.docTimestampFile.Valid() {
  39. zipCmd.Implicit(m.docTimestampFile.Path())
  40. }
  41. }
  42. })
  43. rule.Build("rustdoc-zip", "Zipping all built Rust documentation...")
  44. ctx.Phony("rustdoc", docZip)
  45. }