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 |
| 20 | |
| 21 | ANDROIDX_IDEA_DIR="${PLAYGROUND_REL_PATH}/../.idea" |
| 22 | |
| 23 | # cleanup .idea, we'll re-create it |
| 24 | rm -rf .idea |
| 25 | mkdir .idea |
| 26 | |
| 27 | # create idea directories first .idea config directories that are tracked in git |
| 28 | git ls-tree -d -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR|xargs mkdir -p |
| 29 | |
| 30 | # get a list of all .idea files that are in git tree |
| 31 | # we excluse vcs as it is used for multiple repo setup which we don't need in playground |
| 32 | TRACKED_IDEA_FILES=( $(git ls-tree -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR| grep -v vcs| grep -v Compose) ) |
| 33 | |
| 34 | # create a symlink for each one of them |
| 35 | for IDEA_CONFIG_FILE in "${TRACKED_IDEA_FILES[@]}" |
| 36 | do |
| 37 | # path to the actual .idea config file |
| 38 | ORIGINAL_FILE="$PLAYGROUND_REL_PATH/../$IDEA_CONFIG_FILE" |
| 39 | TARGET_DIR=$(dirname $IDEA_CONFIG_FILE) |
| 40 | # relativize it wrt to the file we'll create |
| 41 | REL_PATH=$(relativize $ORIGINAL_FILE $TARGET_DIR ) |
| 42 | # symlink to the original idea file |
| 43 | ln -s $REL_PATH $IDEA_CONFIG_FILE |
| 44 | # forse add the file to git |
| 45 | git add -f $IDEA_CONFIG_FILE |
| 46 | done |