blob: fe3581b42451a5bd126daca3fab2320348b81f98 [file] [log] [blame]
Dan Albert06feee92021-03-19 15:06:02 -07001// 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) {
Matthew Maurerca68c492021-08-20 13:02:25 -070032 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 Albert06feee92021-03-19 15:06:02 -070040 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 Maurerca68c492021-08-20 13:02:25 -070047 zipCmd.Implicit(m.docTimestampFile.Path())
Dan Albert06feee92021-03-19 15:06:02 -070048 }
49 }
50 })
Matthew Maurerca68c492021-08-20 13:02:25 -070051 rule.Build("rustdoc-zip", "Zipping all built Rust documentation...")
52 ctx.Phony("rustdoc", docZip)
Dan Albert06feee92021-03-19 15:06:02 -070053}