blob: 2769a05ff7ea35416e8e43959403238d1db26a15 [file] [log] [blame]
Yigit Boyarab52dda2020-07-16 14:54:56 -07001#!/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
6function relativize() {
Yigit Boyar5592a0c2022-05-03 12:40:17 -07007 python3 -c "import os.path; print(os.path.relpath('$1', '$2'))"
Yigit Boyarab52dda2020-07-16 14:54:56 -07008}
9
10PLAYGROUND_REL_PATH=$(dirname $0)
11WORKING_DIR=$(pwd)
12
Yigit Boyar5592a0c2022-05-03 12:40:17 -070013# helper symlink function that will also normalize the paths.
14function 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
24symlink "${PLAYGROUND_REL_PATH}/gradle" gradle
25symlink "${PLAYGROUND_REL_PATH}/gradlew" gradlew
26symlink "${PLAYGROUND_REL_PATH}/gradlew.bat" gradlew.bat
27# symlink to the properties file that is shared w/ androidx main
28symlink "${PLAYGROUND_REL_PATH}/androidx-shared.properties" gradle.properties
Yigit Boyarab52dda2020-07-16 14:54:56 -070029
30ANDROIDX_IDEA_DIR="${PLAYGROUND_REL_PATH}/../.idea"
31
32# cleanup .idea, we'll re-create it
33rm -rf .idea
34mkdir .idea
35
36# create idea directories first .idea config directories that are tracked in git
37git 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
41TRACKED_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
44for IDEA_CONFIG_FILE in "${TRACKED_IDEA_FILES[@]}"
45do
46 # path to the actual .idea config file
47 ORIGINAL_FILE="$PLAYGROUND_REL_PATH/../$IDEA_CONFIG_FILE"
Yigit Boyar5592a0c2022-05-03 12:40:17 -070048 symlink $ORIGINAL_FILE $IDEA_CONFIG_FILE
49 # force add the file to git
Yigit Boyarab52dda2020-07-16 14:54:56 -070050 git add -f $IDEA_CONFIG_FILE
Jeff Gaston5633a812021-08-13 11:34:58 -040051done