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() { |
Yigit Boyar | 5592a0c | 2022-05-03 12:40:17 -0700 | [diff] [blame] | 7 | python3 -c "import os.path; print(os.path.relpath('$1', '$2'))" |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 8 | } |
| 9 | |
| 10 | PLAYGROUND_REL_PATH=$(dirname $0) |
| 11 | WORKING_DIR=$(pwd) |
| 12 | |
Yigit Boyar | 5592a0c | 2022-05-03 12:40:17 -0700 | [diff] [blame] | 13 | # helper symlink function that will also normalize the paths. |
| 14 | function symlink() { |
| 15 | SRC=$1 |
| 16 | TARGET=$2 |
| 17 | TARGET_PARENT_DIR=$(dirname $TARGET) |
| 18 | REL_PATH_TO_TARGET_PARENT=$(relativize $SRC $WORKING_DIR/$TARGET_PARENT_DIR) |
| 19 | rm -rf $TARGET |
| 20 | ln -s $REL_PATH_TO_TARGET_PARENT $TARGET |
| 21 | } |
| 22 | |
| 23 | # symlink to the gradle folder in playground-common |
| 24 | symlink "${PLAYGROUND_REL_PATH}/gradle" gradle |
| 25 | symlink "${PLAYGROUND_REL_PATH}/gradlew" gradlew |
| 26 | symlink "${PLAYGROUND_REL_PATH}/gradlew.bat" gradlew.bat |
| 27 | # symlink to the properties file that is shared w/ androidx main |
| 28 | symlink "${PLAYGROUND_REL_PATH}/androidx-shared.properties" gradle.properties |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 29 | |
| 30 | ANDROIDX_IDEA_DIR="${PLAYGROUND_REL_PATH}/../.idea" |
| 31 | |
| 32 | # cleanup .idea, we'll re-create it |
| 33 | rm -rf .idea |
| 34 | mkdir .idea |
| 35 | |
| 36 | # create idea directories first .idea config directories that are tracked in git |
| 37 | git ls-tree -d -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR|xargs mkdir -p |
| 38 | |
| 39 | # get a list of all .idea files that are in git tree |
| 40 | # we excluse vcs as it is used for multiple repo setup which we don't need in playground |
| 41 | TRACKED_IDEA_FILES=( $(git ls-tree -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR| grep -v vcs| grep -v Compose) ) |
| 42 | |
| 43 | # create a symlink for each one of them |
| 44 | for IDEA_CONFIG_FILE in "${TRACKED_IDEA_FILES[@]}" |
| 45 | do |
| 46 | # path to the actual .idea config file |
| 47 | ORIGINAL_FILE="$PLAYGROUND_REL_PATH/../$IDEA_CONFIG_FILE" |
Yigit Boyar | 5592a0c | 2022-05-03 12:40:17 -0700 | [diff] [blame] | 48 | symlink $ORIGINAL_FILE $IDEA_CONFIG_FILE |
| 49 | # force add the file to git |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 50 | git add -f $IDEA_CONFIG_FILE |
Jeff Gaston | 5633a81 | 2021-08-13 11:34:58 -0400 | [diff] [blame] | 51 | done |