blob: ac645d8e90123611efd89aaf34e6cd8f3e77e56c [file] [log] [blame]
Janak Ramakrishnanee85e552015-04-18 20:14:04 +00001#!/bin/bash
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00002# Copyright 2015 The Bazel Authors. All rights reserved.
Janak Ramakrishnanee85e552015-04-18 20:14:04 +00003#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Generates an IntelliJ project in Bazel.
17
18set -o errexit
19cd $(dirname "$0")
20cd ..
21
22mkdir -p .idea/
23cp -R scripts/resources/idea/*.* .idea/
24source scripts/get_all_bazel_paths.sh
25
Janak025b1892015-07-13 15:15:31 +000026readonly compiler_file=.idea/compiler.xml
27cat >$compiler_file <<'EOH'
28<?xml version="1.0" encoding="UTF-8"?>
29<project version="4">
30 <component name="CompilerConfiguration">
31 <excludeFromCompile>
32EOH
33for android_file in $ANDROID_IMPORTING_FILES; do
34 echo " <file url=\"\$PROJECT_DIR\$/${android_file}\" />" >> $compiler_file
35done
36cat >>$compiler_file <<'EOF'
37 </excludeFromCompile>
38 <resourceExtensions />
39 <wildcardResourcePatterns>
40 <entry name="!?*.java" />
41 <entry name="!?*.form" />
42 <entry name="!?*.class" />
43 <entry name="!?*.groovy" />
44 <entry name="!?*.scala" />
45 <entry name="!?*.flex" />
46 <entry name="!?*.kt" />
47 <entry name="!?*.clj" />
48 <entry name="!?*.aj" />
49 </wildcardResourcePatterns>
50 <annotationProcessing>
51 <profile default="true" name="Default" enabled="true">
Carmi Grushkod30ae4d2015-11-19 14:07:21 +000052 <processor name="com.google.auto.value.processor.AutoValueProcessor" />
Janak025b1892015-07-13 15:15:31 +000053 <processorPath useClasspath="true" />
54 </profile>
55 </annotationProcessing>
56 </component>
57</project>
58EOF
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000059
60readonly iml_file=bazel.iml
Carmi Grushkod30ae4d2015-11-19 14:07:21 +000061# Code generated by AutoValue is put in $MODULE_DIR/out/generated; adding it as a Source Root
62# allows IntelliJ to find it while editing. (that is, generated classes won't be marked as unknown.)
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000063cat > $iml_file <<EOH
64<?xml version="1.0" encoding="UTF-8"?>
65<module type="JAVA_MODULE" version="4">
66 <component name="NewModuleRootManager">
Janak025b1892015-07-13 15:15:31 +000067 <output url="file://\$MODULE_DIR\$/out" />
Carmi Grushkod30ae4d2015-11-19 14:07:21 +000068 <content url="file://\$MODULE_DIR$/out/generated">
69 <sourceFolder url="file://\$MODULE_DIR$/out/generated" isTestSource="false" generated="true" />
70 </content>
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000071 <content url="file://\$MODULE_DIR\$/src">
72EOH
73
74for source in ${JAVA_PATHS}; do
75 if [[ $source == *"javatests" ]]; then
76 is_test_source="true"
77 elif [[ $source == *"test/java" ]]; then
78 is_test_source="true"
79 else
80 is_test_source="false"
81 fi
82 echo ' <sourceFolder url="file://$MODULE_DIR$/'"${source}\" isTestSource=\"${is_test_source}\" />" >> $iml_file
83done
84cat >> $iml_file <<'EOF'
85 </content>
86 <content url="file://$MODULE_DIR$/third_party/java">
87EOF
88
89THIRD_PARTY_JAVA_PATHS="$(ls third_party/java | sort -u | sed -e 's%$%/java%')"
90
91for third_party_java_path in ${THIRD_PARTY_JAVA_PATHS}; do
92 echo ' <sourceFolder url="file://$MODULE_DIR$/third_party/java/'${third_party_java_path}'" isTestSource="false" />' >> $iml_file
93done
94cat >> $iml_file <<'EOF'
95 </content>
96 <orderEntry type="sourceFolder" forTests="false" />
97EOF
98
Janak025b1892015-07-13 15:15:31 +000099# Write a module-library entry, usually a jar file but occasionally a directory.
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000100function write_jar_entry() {
Janak025b1892015-07-13 15:15:31 +0000101 local root_file=$1
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000102 if [[ $# > 1 ]]; then
103 local source_path=$2
104 else
105 local source_path=""
106 fi
Janak025b1892015-07-13 15:15:31 +0000107 local protocol="file"
108 local file_end=""
109 if [[ $root_file == *.jar ]]; then
110 protocol="jar"
111 file_end="!"
112 fi
113 local readonly basename=${root_file##*/}
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000114 cat >> $iml_file <<EOF
115 <orderEntry type="module-library">
116 <library name="${basename}">
117 <CLASSES>
Janak025b1892015-07-13 15:15:31 +0000118 <root url="${protocol}://\$MODULE_DIR\$/${root_file}${file_end}/" />
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000119 </CLASSES>
120 <JAVADOC />
121EOF
122 if [[ -z "${source_path}" ]]; then
123 echo " <SOURCES />" >> $iml_file
124 else
125 cat >> $iml_file <<EOF
126 <SOURCES>
127 <root url="jar:/\$MODULE_DIR\$/${source_path}!/" />
128 </SOURCES>
129EOF
130 fi
Janak025b1892015-07-13 15:15:31 +0000131 if [[ $protocol == "file" ]]; then
132 cat >> $iml_file <<EOF
133 <jarDirectory url="file://\$MODULE_DIR\$/${root_file}" recursive="false" />
134EOF
135 fi
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000136 cat >> $iml_file <<'EOF'
137 </library>
138 </orderEntry>
139EOF
140}
141
Janak Ramakrishnan443c7302016-02-22 18:56:34 +0000142# Slight hack to make sure (1) our langtools is picked up before the SDK
143# default, but that (2) SDK is picked up before auto-value, because that
144# apparently causes problems for auto-value otherwise.
145readonly javac_jar="third_party/java/jdk/langtools/javac.jar"
146write_jar_entry "$javac_jar"
147
148cat >> $iml_file <<'EOF'
149 <orderEntry type="inheritedJdk" />
150EOF
151
Lukacs Berki80706202016-06-17 05:42:52 +0000152for path_pair in ${GENERATED_PATHS}; do
153 write_jar_entry ${path_pair//:/ }
154done
155
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000156for jar in ${THIRD_PARTY_JAR_PATHS}; do
Janak Ramakrishnan443c7302016-02-22 18:56:34 +0000157 if [[ jar != "$javac_jar" ]]; then
158 write_jar_entry $jar
159 fi
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000160done
161
Janak025b1892015-07-13 15:15:31 +0000162write_jar_entry "bazel-bin/src/main/protobuf"
163
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000164cat >> $iml_file <<'EOF'
165 </component>
166</module>
167EOF
Carmi Grushkod30ae4d2015-11-19 14:07:21 +0000168
169echo
170echo Done. Project file: $iml_file