blob: 177ca1b04fa647e31c64d998de23103e683e3d8c [file] [log] [blame]
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001#!/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 Kalauskas39b0deb2018-07-10 12:01:03 -070019if [[ -z "$1" ]]; then
Colin Cross6c6e6cd2019-05-08 14:30:12 -070020 echo "usage: $0 <classpath> <name> <outDir> <rspFiles>..." >&2
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000021 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
Colin Cross6c6e6cd2019-05-08 14:30:12 -070030name=$2
31out_dir=$3
32shift 3
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000033
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070034# Path in the build file may be relative to the build file, we need to make them
35# absolute
36prefix="$(pwd)"
37
38get_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 Szczepaniak4b5fe9d2018-02-13 14:32:54 +000046
47# Print preamble
Colin Cross6c6e6cd2019-05-08 14:30:12 -070048echo "<modules><module name=\"${name}\" type=\"java-production\" outputDir=\"${out_dir}\">"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000049
50# Print classpath entries
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070051for file in $(echo "$classpath" | tr ":" "\n"); do
52 path="$(get_abs_path "$file")"
53 echo " <classpath path=\"${path}\"/>"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000054done
55
56# For each rsp file, print source entries
57while (( "$#" )); do
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070058 for file in $(cat "$1"); do
59 path="$(get_abs_path "$file")"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000060 if [[ $file == *.java ]]; then
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070061 echo " <javaSourceRoots path=\"${path}\"/>"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000062 elif [[ $file == *.kt ]]; then
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070063 echo " <sources path=\"${path}\"/>"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000064 else
65 echo "Unknown source file type ${file}"
66 exit 1
67 fi
68 done
69
70 shift
71done
72
73echo "</module></modules>"