Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9eacaa0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Move gen-kotlin-build-file.sh to python"

parents 5e291c23 9b1aa0cb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ func init() {
	pctx.SourcePathVariable("JavaKytheExtractorJar", "prebuilts/build-tools/common/framework/javac_extractor.jar")
	pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")

	pctx.SourcePathVariable("GenKotlinBuildFileCmd", "build/soong/scripts/gen-kotlin-build-file.sh")
	pctx.HostBinToolVariable("GenKotlinBuildFileCmd", "gen-kotlin-build-file.py")

	pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
	pctx.SourcePathVariable("PackageCheckCmd", "build/soong/scripts/package-check.sh")
+8 −4
Original line number Diff line number Diff line
@@ -31,7 +31,9 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports
		Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` +
			`mkdir -p "$classesDir" "$srcJarDir" "$emptyDir" && ` +
			`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
			`${config.GenKotlinBuildFileCmd} $classpath "$name" $classesDir $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
			`${config.GenKotlinBuildFileCmd} --classpath "$classpath" --name "$name"` +
			` --out_dir "$classesDir" --srcs "$out.rsp" --srcs "$srcJarDir/list"` +
			` --out "$kotlinBuildFile" && ` +
			`${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` +
			`-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` +
			`${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` +
@@ -74,7 +76,7 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
		Inputs:      srcFiles,
		Implicits:   deps,
		Args: map[string]string{
			"classpath":       flags.kotlincClasspath.FormJavaClassPath("-classpath"),
			"classpath":       flags.kotlincClasspath.FormJavaClassPath(""),
			"kotlincFlags":    flags.kotlincFlags,
			"srcJars":         strings.Join(srcJars.Strings(), " "),
			"classesDir":      android.PathForModuleOut(ctx, "kotlinc", "classes").String(),
@@ -93,7 +95,9 @@ var kapt = pctx.AndroidRemoteStaticRule("kapt", android.RemoteRuleSupports{Goma:
		Command: `rm -rf "$srcJarDir" "$kotlinBuildFile" "$kaptDir" && ` +
			`mkdir -p "$srcJarDir" "$kaptDir/sources" "$kaptDir/classes" && ` +
			`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
			`${config.GenKotlinBuildFileCmd} $classpath "$name" "" $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
			`${config.GenKotlinBuildFileCmd} --classpath "$classpath" --name "$name"` +
			` --srcs "$out.rsp" --srcs "$srcJarDir/list"` +
			` --out "$kotlinBuildFile" && ` +
			`${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` +
			`-Xplugin=${config.KotlinKaptJar} ` +
			`-P plugin:org.jetbrains.kotlin.kapt3:sources=$kaptDir/sources ` +
@@ -162,7 +166,7 @@ func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile an
		Inputs:         srcFiles,
		Implicits:      deps,
		Args: map[string]string{
			"classpath":         flags.kotlincClasspath.FormJavaClassPath("-classpath"),
			"classpath":         flags.kotlincClasspath.FormJavaClassPath(""),
			"kotlincFlags":      flags.kotlincFlags,
			"srcJars":           strings.Join(srcJars.Strings(), " "),
			"srcJarDir":         android.PathForModuleOut(ctx, "kapt", "srcJars").String(),
+13 −1
Original line number Diff line number Diff line
@@ -152,5 +152,17 @@ python_test_host {
python_binary_host {
    name: "lint-project-xml",
    main: "lint-project-xml.py",
    srcs: ["lint-project-xml.py"],
    srcs: [
        "lint-project-xml.py",
        "ninja_rsp.py",
    ],
}

python_binary_host {
    name: "gen-kotlin-build-file.py",
    main: "gen-kotlin-build-file.py",
    srcs: [
        "gen-kotlin-build-file.py",
        "ninja_rsp.py",
    ],
}
+94 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
# Copyright 2018 Google Inc. 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.

# Generates kotlinc module xml file to drive kotlinc

import argparse
import os

from ninja_rsp import NinjaRspFileReader

def parse_args():
  """Parse commandline arguments."""

  def convert_arg_line_to_args(arg_line):
    for arg in arg_line.split():
      if arg.startswith('#'):
        return
      if not arg.strip():
        continue
      yield arg

  parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
  parser.convert_arg_line_to_args = convert_arg_line_to_args
  parser.add_argument('--out', dest='out',
                      help='file to which the module.xml contents will be written.')
  parser.add_argument('--classpath', dest='classpath', action='append', default=[],
                      help='classpath to pass to kotlinc.')
  parser.add_argument('--name', dest='name',
                      help='name of the module.')
  parser.add_argument('--out_dir', dest='out_dir',
                      help='directory to which kotlinc will write output files.')
  parser.add_argument('--srcs', dest='srcs', action='append', default=[],
                      help='file containing whitespace separated list of source files.')
  parser.add_argument('--common_srcs', dest='common_srcs', action='append', default=[],
                      help='file containing whitespace separated list of common multiplatform source files.')

  return parser.parse_args()

def main():
  """Program entry point."""
  args = parse_args()

  if not args.out:
    raise RuntimeError('--out argument is required')

  if not args.name:
    raise RuntimeError('--name argument is required')

  with open(args.out, 'w') as f:
    # Print preamble
    f.write('<modules>\n')
    f.write('  <module name="%s" type="java-production" outputDir="%s">\n' % (args.name, args.out_dir or ''))

    # Print classpath entries
    for c in args.classpath:
      for entry in c.split(':'):
        path = os.path.abspath(entry)
        f.write('    <classpath path="%s"/>\n' % path)

    # For each rsp file, print source entries
    for rsp_file in args.srcs:
      for src in NinjaRspFileReader(rsp_file):
        path = os.path.abspath(src)
        if src.endswith('.java'):
          f.write('    <javaSourceRoots path="%s"/>\n' % path)
        elif src.endswith('.kt'):
          f.write('    <sources path="%s"/>\n' % path)
        else:
          raise RuntimeError('unknown source file type %s' % file)

    for rsp_file in args.common_srcs:
      for src in NinjaRspFileReader(rsp_file):
        path = os.path.abspath(src)
        f.write('    <sources path="%s"/>\n' % path)
        f.write('    <commonSources path="%s"/>\n' % path)

    f.write('  </module>\n')
    f.write('</modules>\n')

if __name__ == '__main__':
  main()

scripts/gen-kotlin-build-file.sh

deleted100755 → 0
+0 −73
Original line number Diff line number Diff line
#!/bin/bash -e

# Copyright 2018 Google Inc. 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.

# Generates kotlinc module xml file to standard output based on rsp files

if [[ -z "$1" ]]; then
  echo "usage: $0 <classpath> <name> <outDir> <rspFiles>..." >&2
  exit 1
fi

# Classpath variable has a tendency to be prefixed by "-classpath", remove it.
if [[ $1 == "-classpath" ]]; then
  shift
fi;

classpath=$1
name=$2
out_dir=$3
shift 3

# Path in the build file may be relative to the build file, we need to make them
# absolute
prefix="$(pwd)"

get_abs_path () {
  local file="$1"
  if [[ "${file:0:1}" == '/' ]] ; then
    echo "${file}"
  else
    echo "${prefix}/${file}"
  fi
}

# Print preamble
echo "<modules><module name=\"${name}\" type=\"java-production\" outputDir=\"${out_dir}\">"

# Print classpath entries
for file in $(echo "$classpath" | tr ":" "\n"); do
  path="$(get_abs_path "$file")"
  echo "  <classpath path=\"${path}\"/>"
done

# For each rsp file, print source entries
while (( "$#" )); do
  for file in $(cat "$1"); do
    path="$(get_abs_path "$file")"
    if [[ $file == *.java ]]; then
      echo "  <javaSourceRoots path=\"${path}\"/>"
    elif [[ $file == *.kt ]]; then
      echo "  <sources path=\"${path}\"/>"
    else
      echo "Unknown source file type ${file}"
      exit 1
    fi
  done

  shift
done

echo "</module></modules>"
Loading