1#!/bin/bash -e 2 3# Copyright 2018 Google Inc. All rights reserved. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Generates kotlinc module xml file to standard output based on rsp files 18 19if [[ -z "$1" ]]; then 20 echo "usage: $0 <classpath> <outDir> <rspFiles>..." >&2 21 exit 1 22fi 23 24# Classpath variable has a tendency to be prefixed by "-classpath", remove it. 25if [[ $1 == "-classpath" ]]; then 26 shift 27fi; 28 29classpath=$1 30out_dir=$2 31shift 2 32 33# Path in the build file may be relative to the build file, we need to make them 34# absolute 35prefix="$(pwd)" 36 37get_abs_path () { 38 local file="$1" 39 if [[ "${file:0:1}" == '/' ]] ; then 40 echo "${file}" 41 else 42 echo "${prefix}/${file}" 43 fi 44} 45 46# Print preamble 47echo "<modules><module name=\"name\" type=\"java-production\" outputDir=\"${out_dir}\">" 48 49# Print classpath entries 50for file in $(echo "$classpath" | tr ":" "\n"); do 51 path="$(get_abs_path "$file")" 52 echo " <classpath path=\"${path}\"/>" 53done 54 55# For each rsp file, print source entries 56while (( "$#" )); do 57 for file in $(cat "$1"); do 58 path="$(get_abs_path "$file")" 59 if [[ $file == *.java ]]; then 60 echo " <javaSourceRoots path=\"${path}\"/>" 61 elif [[ $file == *.kt ]]; then 62 echo " <sources path=\"${path}\"/>" 63 else 64 echo "Unknown source file type ${file}" 65 exit 1 66 fi 67 done 68 69 shift 70done 71 72echo "</module></modules>" 73