#!/bin/bash # Copyright 2015 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Generates an IntelliJ project in Bazel. set -o errexit cd $(dirname "$0") cd .. mkdir -p .idea/ cp -R scripts/resources/idea/*.* .idea/ source scripts/get_all_bazel_paths.sh readonly compiler_file=.idea/compiler.xml cat >$compiler_file <<'EOH' EOH for android_file in $ANDROID_IMPORTING_FILES; do echo " " >> $compiler_file done cat >>$compiler_file <<'EOF' EOF readonly iml_file=bazel.iml # Code generated by AutoValue is put in $MODULE_DIR/out/generated; adding it as a Source Root # allows IntelliJ to find it while editing. (that is, generated classes won't be marked as unknown.) cat > $iml_file < EOH for source in ${JAVA_PATHS}; do if [[ $source == *"javatests" ]]; then is_test_source="true" elif [[ $source == *"test/java" ]]; then is_test_source="true" else is_test_source="false" fi echo ' " >> $iml_file done cat >> $iml_file <<'EOF' EOF THIRD_PARTY_JAVA_PATHS="$(ls third_party/java | sort -u | sed -e 's%$%/java%')" for third_party_java_path in ${THIRD_PARTY_JAVA_PATHS}; do echo ' ' >> $iml_file done cat >> $iml_file <<'EOF' EOF # Write a module-library entry, usually a jar file but occasionally a directory. function write_jar_entry() { local root_file=$1 if [[ $# > 1 ]]; then local source_path=$2 else local source_path="" fi local protocol="file" local file_end="" if [[ $root_file == *.jar ]]; then protocol="jar" file_end="!" fi local readonly basename=${root_file##*/} cat >> $iml_file < EOF if [[ -z "${source_path}" ]]; then echo " " >> $iml_file else cat >> $iml_file < EOF fi if [[ $protocol == "file" ]]; then cat >> $iml_file < EOF fi cat >> $iml_file <<'EOF' EOF } for jar in ${THIRD_PARTY_JAR_PATHS}; do write_jar_entry $jar done for path_pair in ${GENERATED_PATHS}; do write_jar_entry ${path_pair//:/ } done write_jar_entry "bazel-bin/src/main/protobuf" cat >> $iml_file <<'EOF' EOF echo echo Done. Project file: $iml_file