blob: b103d5435d31bc3ba018518328c780d9bed594d7 [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
29# symlink to build source
30symlink "${PLAYGROUND_REL_PATH}/../buildSrc" buildSrc
Yigit Boyarab52dda2020-07-16 14:54:56 -070031
32ANDROIDX_IDEA_DIR="${PLAYGROUND_REL_PATH}/../.idea"
33
34# cleanup .idea, we'll re-create it
35rm -rf .idea
36mkdir .idea
37
38# create idea directories first .idea config directories that are tracked in git
39git ls-tree -d -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR|xargs mkdir -p
40
41# get a list of all .idea files that are in git tree
42# we excluse vcs as it is used for multiple repo setup which we don't need in playground
43TRACKED_IDEA_FILES=( $(git ls-tree -r HEAD --name-only --full-name $ANDROIDX_IDEA_DIR| grep -v vcs| grep -v Compose) )
44
45# create a symlink for each one of them
46for IDEA_CONFIG_FILE in "${TRACKED_IDEA_FILES[@]}"
47do
48 # path to the actual .idea config file
49 ORIGINAL_FILE="$PLAYGROUND_REL_PATH/../$IDEA_CONFIG_FILE"
Yigit Boyar5592a0c2022-05-03 12:40:17 -070050 symlink $ORIGINAL_FILE $IDEA_CONFIG_FILE
51 # force add the file to git
Yigit Boyarab52dda2020-07-16 14:54:56 -070052 git add -f $IDEA_CONFIG_FILE
Jeff Gaston5633a812021-08-13 11:34:58 -040053done