blob: 1e03f72e00fe6adfe03a91ae1770da0c8bc3167a [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
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000020 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
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070033# 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}
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000045
46# Print preamble
47echo "<modules><module name=\"name\" type=\"java-production\" outputDir=\"${out_dir}\">"
48
49# Print classpath entries
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070050for file in $(echo "$classpath" | tr ":" "\n"); do
51 path="$(get_abs_path "$file")"
52 echo " <classpath path=\"${path}\"/>"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000053done
54
55# For each rsp file, print source entries
56while (( "$#" )); do
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070057 for file in $(cat "$1"); do
58 path="$(get_abs_path "$file")"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000059 if [[ $file == *.java ]]; then
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070060 echo " <javaSourceRoots path=\"${path}\"/>"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000061 elif [[ $file == *.kt ]]; then
Peter Kalauskas39b0deb2018-07-10 12:01:03 -070062 echo " <sources path=\"${path}\"/>"
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +000063 else
64 echo "Unknown source file type ${file}"
65 exit 1
66 fi
67 done
68
69 shift
70done
71
72echo "</module></modules>"