blob: 342b6a63043b1eb8925299b2152bfe341c4e6ced [file] [log] [blame]
Jared Duke841329a2025-03-07 00:18:37 +00001// Copyright 2025 Google Inc. All rights reserved.
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 java
16
17import (
18 "android/soong/android"
19
20 "github.com/google/blueprint"
21)
22
23var traceReferences = pctx.AndroidStaticRule("traceReferences",
24 blueprint.RuleParams{
25 Command: `${config.TraceReferencesCmd} ` +
26 // Note that we suppress missing def errors, as we're only interested
27 // in the direct deps between the sources and target.
28 `--map-diagnostics:MissingDefinitionsDiagnostic error none ` +
29 `--keep-rules ` +
30 `--output ${out} ` +
31 `--target ${in} ` +
32 // `--source` and `--lib` are already prepended to each
33 // jar reference in the sources and libs joined string args.
34 `${sources} ` +
35 `${libs}`,
36 CommandDeps: []string{"${config.TraceReferencesCmd}"},
37 }, "sources", "libs")
38
39// Generates keep rules in output corresponding to any references from sources
40// (a list of jars) onto target (the referenced jar) that are not included in
41// libs (a list of external jars).
42func TraceReferences(ctx android.ModuleContext, sources android.Paths, target android.Path, libs android.Paths,
43 output android.WritablePath) {
44 ctx.Build(pctx, android.BuildParams{
45 Rule: traceReferences,
46 Input: target,
47 Output: output,
48 Implicits: append(sources, libs...),
49 Args: map[string]string{
50 "sources": android.JoinWithPrefix(sources.Strings(), "--source "),
51 "libs": android.JoinWithPrefix(libs.Strings(), "--lib "),
52 },
53 })
54}