Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 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 | |
Peter Kalauskas | 39b0deb | 2018-07-10 12:01:03 -0700 | [diff] [blame] | 19 | if [[ -z "$1" ]]; then |
Colin Cross | 6c6e6cd | 2019-05-08 14:30:12 -0700 | [diff] [blame] | 20 | echo "usage: $0 <classpath> <name> <outDir> <rspFiles>..." >&2 |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 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 |
Colin Cross | 6c6e6cd | 2019-05-08 14:30:12 -0700 | [diff] [blame] | 30 | name=$2 |
| 31 | out_dir=$3 |
| 32 | shift 3 |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 33 | |
Peter Kalauskas | 39b0deb | 2018-07-10 12:01:03 -0700 | [diff] [blame] | 34 | # Path in the build file may be relative to the build file, we need to make them |
| 35 | # absolute |
| 36 | prefix="$(pwd)" |
| 37 | |
| 38 | get_abs_path () { |
| 39 | local file="$1" |
| 40 | if [[ "${file:0:1}" == '/' ]] ; then |
| 41 | echo "${file}" |
| 42 | else |
| 43 | echo "${prefix}/${file}" |
| 44 | fi |
| 45 | } |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 46 | |
| 47 | # Print preamble |
Colin Cross | 6c6e6cd | 2019-05-08 14:30:12 -0700 | [diff] [blame] | 48 | echo "<modules><module name=\"${name}\" type=\"java-production\" outputDir=\"${out_dir}\">" |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 49 | |
| 50 | # Print classpath entries |
Peter Kalauskas | 39b0deb | 2018-07-10 12:01:03 -0700 | [diff] [blame] | 51 | for file in $(echo "$classpath" | tr ":" "\n"); do |
| 52 | path="$(get_abs_path "$file")" |
| 53 | echo " <classpath path=\"${path}\"/>" |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 54 | done |
| 55 | |
| 56 | # For each rsp file, print source entries |
| 57 | while (( "$#" )); do |
Peter Kalauskas | 39b0deb | 2018-07-10 12:01:03 -0700 | [diff] [blame] | 58 | for file in $(cat "$1"); do |
| 59 | path="$(get_abs_path "$file")" |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 60 | if [[ $file == *.java ]]; then |
Peter Kalauskas | 39b0deb | 2018-07-10 12:01:03 -0700 | [diff] [blame] | 61 | echo " <javaSourceRoots path=\"${path}\"/>" |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 62 | elif [[ $file == *.kt ]]; then |
Peter Kalauskas | 39b0deb | 2018-07-10 12:01:03 -0700 | [diff] [blame] | 63 | echo " <sources path=\"${path}\"/>" |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 64 | else |
| 65 | echo "Unknown source file type ${file}" |
| 66 | exit 1 |
| 67 | fi |
| 68 | done |
| 69 | |
| 70 | shift |
| 71 | done |
| 72 | |
| 73 | echo "</module></modules>" |