aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java/JavaProtoCommonApi.java
blob: e8aaec8016c16ee2932e02b295854bf0667add66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.skylarkbuildapi.java;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleContextApi;
import com.google.devtools.build.lib.skylarkbuildapi.TransitiveInfoCollectionApi;
import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.syntax.EvalException;

/**
 * Helper class for Java proto compilation.
 */
@SkylarkModule(name = "java_proto_common", doc = "Helper class for Java proto compilation.")
public interface JavaProtoCommonApi<FileT extends FileApi,
    SkylarkRuleContextT extends SkylarkRuleContextApi,
    TransitiveInfoCollectionT extends TransitiveInfoCollectionApi> {

  @SkylarkCallable(
      name = "create_java_lite_proto_compile_action",
      // This function is experimental for now.
      documented = false,
      parameters = {
          @Param(
              name = "ctx",
              positional = true,
              named = false,
              type = SkylarkRuleContextApi.class,
              doc = "The rule context."
          ),
          @Param(
              name = "target",
              positional = true,
              named = false,
              type = TransitiveInfoCollectionApi.class,
              doc = "The target."
          ),
          @Param(
              name = "src_jar",
              positional = false,
              named = true,
              type = FileApi.class
          ),
          @Param(
              name = "proto_toolchain_attr",
              positional = false,
              named = true,
              type = String.class
          ),
          @Param(
              name = "flavour",
              positional = false,
              named = true,
              type = String.class,
              defaultValue = "java"
          )
      }
  )
  public void createProtoCompileAction(
      SkylarkRuleContextT skylarkRuleContext,
      TransitiveInfoCollectionT target,
      FileT sourceJar,
      String protoToolchainAttr,
      String flavour) throws EvalException;

  @SkylarkCallable(
      name = "has_proto_sources",
      doc = "Returns whether the given proto_library target contains proto sources. If there are no"
          + " sources it means that the proto_library is an alias library, which exports its"
          + " dependencies.",
      parameters = {
        @Param(
            name = "target",
            positional = true,
            named = false,
            type = TransitiveInfoCollectionApi.class,
            doc = "The proto_library target."
        ),
      }
  )
  public boolean hasProtoSources(TransitiveInfoCollectionT target);

  @SkylarkCallable(
    name = "toolchain_deps",
    // This function is experimental for now.
    documented = false,
    parameters = {
      @Param(
          name = "ctx",
          positional = true,
          named = false,
          type = SkylarkRuleContextApi.class,
          doc = "The rule context."
      ),
      @Param(name = "proto_toolchain_attr", positional = false, named = true, type = String.class)
    }
  )
  public JavaInfoApi<FileT> getRuntimeToolchainProvider(
      SkylarkRuleContextT skylarkRuleContext, String protoToolchainAttr) throws EvalException;

  @SkylarkCallable(
    name = "javac_opts",
    // This function is experimental for now.
    documented = false,
    parameters = {
      @Param(
          name = "ctx",
          positional = true,
          named = false,
          type = SkylarkRuleContextApi.class,
          doc = "The rule context."
      ),
      @Param(name = "java_toolchain_attr", positional = false, named = true, type = String.class)
    }
  )
  // TODO(b/78512644): migrate callers to passing explicit proto javacopts or using custom
  // toolchains, and delete
  public ImmutableList<String> getJavacOpts(
      SkylarkRuleContextT skylarkRuleContext, String javaToolchainAttr) throws EvalException;
}