blob: 5bc7441c88ecff36a476fc563dc5263654a616e9 [file] [log] [blame]
Colin Cross21fc9bb2019-01-18 15:05:09 -08001// Copyright 2019 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 "strings"
20
21 "github.com/google/blueprint"
22)
23
24var kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
25 blueprint.RuleParams{
26 Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" && mkdir -p "$classesDir" "$srcJarDir" && ` +
27 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
28 `${config.GenKotlinBuildFileCmd} $classpath $classesDir $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
29 `${config.KotlincCmd} $kotlincFlags ` +
30 `-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile && ` +
31 `${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir`,
32 CommandDeps: []string{
33 "${config.KotlincCmd}",
34 "${config.KotlinCompilerJar}",
35 "${config.GenKotlinBuildFileCmd}",
36 "${config.SoongZipCmd}",
37 "${config.ZipSyncCmd}",
38 },
39 Rspfile: "$out.rsp",
40 RspfileContent: `$in`,
41 },
42 "kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile")
43
44func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
45 srcFiles, srcJars android.Paths,
46 flags javaBuilderFlags) {
47
48 inputs := append(android.Paths(nil), srcFiles...)
49
50 var deps android.Paths
51 deps = append(deps, flags.kotlincClasspath...)
52 deps = append(deps, srcJars...)
53
54 ctx.Build(pctx, android.BuildParams{
55 Rule: kotlinc,
56 Description: "kotlinc",
57 Output: outputFile,
58 Inputs: inputs,
59 Implicits: deps,
60 Args: map[string]string{
61 "classpath": flags.kotlincClasspath.FormJavaClassPath("-classpath"),
62 "kotlincFlags": flags.kotlincFlags,
63 "srcJars": strings.Join(srcJars.Strings(), " "),
64 "classesDir": android.PathForModuleOut(ctx, "kotlinc", "classes").String(),
65 "srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(),
66 "kotlinBuildFile": android.PathForModuleOut(ctx, "kotlinc-build.xml").String(),
67 // http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8
68 "kotlinJvmTarget": "1.8",
69 },
70 })
71}