Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 2 | # Copyright 2015 The Bazel Authors. All rights reserved. |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 3 | # |
| 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 | |
| 18 | set -o errexit |
| 19 | cd $(dirname "$0") |
| 20 | cd .. |
| 21 | |
| 22 | mkdir -p .idea/ |
| 23 | cp -R scripts/resources/idea/*.* .idea/ |
| 24 | source scripts/get_all_bazel_paths.sh |
| 25 | |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 26 | readonly compiler_file=.idea/compiler.xml |
| 27 | cat >$compiler_file <<'EOH' |
| 28 | <?xml version="1.0" encoding="UTF-8"?> |
| 29 | <project version="4"> |
| 30 | <component name="CompilerConfiguration"> |
| 31 | <excludeFromCompile> |
| 32 | EOH |
| 33 | for android_file in $ANDROID_IMPORTING_FILES; do |
| 34 | echo " <file url=\"\$PROJECT_DIR\$/${android_file}\" />" >> $compiler_file |
| 35 | done |
| 36 | cat >>$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 Grushko | d30ae4d | 2015-11-19 14:07:21 +0000 | [diff] [blame] | 52 | <processor name="com.google.auto.value.processor.AutoValueProcessor" /> |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 53 | <processorPath useClasspath="true" /> |
| 54 | </profile> |
| 55 | </annotationProcessing> |
| 56 | </component> |
| 57 | </project> |
| 58 | EOF |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 59 | |
| 60 | readonly iml_file=bazel.iml |
Carmi Grushko | d30ae4d | 2015-11-19 14:07:21 +0000 | [diff] [blame] | 61 | # 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 Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 63 | cat > $iml_file <<EOH |
| 64 | <?xml version="1.0" encoding="UTF-8"?> |
| 65 | <module type="JAVA_MODULE" version="4"> |
| 66 | <component name="NewModuleRootManager"> |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 67 | <output url="file://\$MODULE_DIR\$/out" /> |
Carmi Grushko | d30ae4d | 2015-11-19 14:07:21 +0000 | [diff] [blame] | 68 | <content url="file://\$MODULE_DIR$/out/generated"> |
| 69 | <sourceFolder url="file://\$MODULE_DIR$/out/generated" isTestSource="false" generated="true" /> |
| 70 | </content> |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 71 | <content url="file://\$MODULE_DIR\$/src"> |
| 72 | EOH |
| 73 | |
| 74 | for 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 |
| 83 | done |
| 84 | cat >> $iml_file <<'EOF' |
| 85 | </content> |
| 86 | <content url="file://$MODULE_DIR$/third_party/java"> |
| 87 | EOF |
| 88 | |
| 89 | THIRD_PARTY_JAVA_PATHS="$(ls third_party/java | sort -u | sed -e 's%$%/java%')" |
| 90 | |
| 91 | for 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 |
| 93 | done |
| 94 | cat >> $iml_file <<'EOF' |
| 95 | </content> |
| 96 | <orderEntry type="sourceFolder" forTests="false" /> |
| 97 | EOF |
| 98 | |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 99 | # Write a module-library entry, usually a jar file but occasionally a directory. |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 100 | function write_jar_entry() { |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 101 | local root_file=$1 |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 102 | if [[ $# > 1 ]]; then |
| 103 | local source_path=$2 |
| 104 | else |
| 105 | local source_path="" |
| 106 | fi |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 107 | 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 Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 114 | cat >> $iml_file <<EOF |
| 115 | <orderEntry type="module-library"> |
| 116 | <library name="${basename}"> |
| 117 | <CLASSES> |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 118 | <root url="${protocol}://\$MODULE_DIR\$/${root_file}${file_end}/" /> |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 119 | </CLASSES> |
| 120 | <JAVADOC /> |
| 121 | EOF |
| 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> |
| 129 | EOF |
| 130 | fi |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 131 | if [[ $protocol == "file" ]]; then |
| 132 | cat >> $iml_file <<EOF |
| 133 | <jarDirectory url="file://\$MODULE_DIR\$/${root_file}" recursive="false" /> |
| 134 | EOF |
| 135 | fi |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 136 | cat >> $iml_file <<'EOF' |
| 137 | </library> |
| 138 | </orderEntry> |
| 139 | EOF |
| 140 | } |
| 141 | |
Janak Ramakrishnan | 443c730 | 2016-02-22 18:56:34 +0000 | [diff] [blame] | 142 | # 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. |
| 145 | readonly javac_jar="third_party/java/jdk/langtools/javac.jar" |
| 146 | write_jar_entry "$javac_jar" |
| 147 | |
| 148 | cat >> $iml_file <<'EOF' |
| 149 | <orderEntry type="inheritedJdk" /> |
| 150 | EOF |
| 151 | |
Lukacs Berki | 8070620 | 2016-06-17 05:42:52 +0000 | [diff] [blame] | 152 | for path_pair in ${GENERATED_PATHS}; do |
| 153 | write_jar_entry ${path_pair//:/ } |
| 154 | done |
| 155 | |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 156 | for jar in ${THIRD_PARTY_JAR_PATHS}; do |
Janak Ramakrishnan | 443c730 | 2016-02-22 18:56:34 +0000 | [diff] [blame] | 157 | if [[ jar != "$javac_jar" ]]; then |
| 158 | write_jar_entry $jar |
| 159 | fi |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 160 | done |
| 161 | |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 162 | write_jar_entry "bazel-bin/src/main/protobuf" |
| 163 | |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 164 | cat >> $iml_file <<'EOF' |
| 165 | </component> |
| 166 | </module> |
| 167 | EOF |
Carmi Grushko | d30ae4d | 2015-11-19 14:07:21 +0000 | [diff] [blame] | 168 | |
| 169 | echo |
| 170 | echo Done. Project file: $iml_file |