Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Helper script to kick-off a playground project setup. |
| 3 | # This is intended to be used when we create a new Playground project or update existing ones |
| 4 | # if we do structural changes in Playground's setup. |
| 5 | |
| 6 | function relativize() { |
| 7 | python -c "import os.path; print os.path.relpath('$1', '$2')" |
| 8 | } |
| 9 | |
| 10 | PLAYGROUND_REL_PATH=$(dirname $0) |
| 11 | WORKING_DIR=$(pwd) |
| 12 | |
| 13 | # create gradle symlinks |
| 14 | rm -rf gradle |
| 15 | ln -s "${PLAYGROUND_REL_PATH}/gradle" gradle |
| 16 | rm -rf gradlew |
| 17 | ln -s "${PLAYGROUND_REL_PATH}/gradlew" gradlew |
| 18 | rm -rf gradlew.bat |
| 19 | ln -s "${PLAYGROUND_REL_PATH}/gradlew.bat" gradlew.bat |
Yigit Boyar | a4abb18 | 2020-07-31 21:44:05 -0700 | [diff] [blame] | 20 | rm -rf gradle.properties |
| 21 | ln -s "${PLAYGROUND_REL_PATH}/androidx-shared.properties" gradle.properties |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 22 | |
| 23 | ANDROIDX_IDEA_DIR="${PLAYGROUND_REL_PATH}/../.idea" |
| 24 | |
| 25 | # cleanup .idea, we'll re-create it |
| 26 | rm -rf .idea |
| 27 | mkdir .idea |
| 28 | |
| 29 | # create idea directories first .idea config directories that are tracked in git |
| 30 | git ls-tree -d -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR|xargs mkdir -p |
| 31 | |
| 32 | # get a list of all .idea files that are in git tree |
| 33 | # we excluse vcs as it is used for multiple repo setup which we don't need in playground |
| 34 | TRACKED_IDEA_FILES=( $(git ls-tree -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR| grep -v vcs| grep -v Compose) ) |
| 35 | |
| 36 | # create a symlink for each one of them |
| 37 | for IDEA_CONFIG_FILE in "${TRACKED_IDEA_FILES[@]}" |
| 38 | do |
| 39 | # path to the actual .idea config file |
| 40 | ORIGINAL_FILE="$PLAYGROUND_REL_PATH/../$IDEA_CONFIG_FILE" |
| 41 | TARGET_DIR=$(dirname $IDEA_CONFIG_FILE) |
| 42 | # relativize it wrt to the file we'll create |
| 43 | REL_PATH=$(relativize $ORIGINAL_FILE $TARGET_DIR ) |
| 44 | # symlink to the original idea file |
| 45 | ln -s $REL_PATH $IDEA_CONFIG_FILE |
| 46 | # forse add the file to git |
| 47 | git add -f $IDEA_CONFIG_FILE |
| 48 | done |