Home | History | Annotate | Download | only in scripts
      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 
     19 if [ -z "$1" ]; then
     20   echo "usage: $0 <classpath> <outDir> <rspFiles>..." >&2
     21   exit 1
     22 fi
     23 
     24 # Classpath variable has a tendency to be prefixed by "-classpath", remove it.
     25 if [[ $1 == "-classpath" ]]; then
     26   shift
     27 fi;
     28 
     29 classpath=$1
     30 out_dir=$2
     31 shift 2
     32 
     33 # Path in the build file are relative to the build file, we need to make them absolute.
     34 prefix=`pwd`
     35 
     36 # Print preamble
     37 echo "<modules><module name=\"name\" type=\"java-production\" outputDir=\"${out_dir}\">"
     38 
     39 # Print classpath entries
     40 for file in $(echo $classpath | tr ":" "\n"); do
     41   echo "  <classpath path=\"${prefix}/${file}\"/>"
     42 done
     43 
     44 # For each rsp file, print source entries
     45 while (( "$#" )); do
     46   for file in $(cat $1); do
     47     if [[ $file == *.java ]]; then
     48       echo "  <javaSourceRoots path=\"${prefix}/${file}\"/>"
     49     elif [[ $file == *.kt ]]; then
     50       echo "  <sources path=\"${prefix}/${file}\"/>"
     51     else
     52       echo "Unknown source file type ${file}"
     53       exit 1
     54     fi
     55   done
     56 
     57   shift
     58 done
     59 
     60 echo "</module></modules>"
     61