blob: 650ae3d890a9507526366098268936ad0e9256c8 [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() {
7 python -c "import os.path; print os.path.relpath('$1', '$2')"
8}
9
10PLAYGROUND_REL_PATH=$(dirname $0)
11WORKING_DIR=$(pwd)
12
13# create gradle symlinks
14rm -rf gradle
15ln -s "${PLAYGROUND_REL_PATH}/gradle" gradle
16rm -rf gradlew
17ln -s "${PLAYGROUND_REL_PATH}/gradlew" gradlew
18rm -rf gradlew.bat
19ln -s "${PLAYGROUND_REL_PATH}/gradlew.bat" gradlew.bat
20
21ANDROIDX_IDEA_DIR="${PLAYGROUND_REL_PATH}/../.idea"
22
23# cleanup .idea, we'll re-create it
24rm -rf .idea
25mkdir .idea
26
27# create idea directories first .idea config directories that are tracked in git
28git 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
32TRACKED_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
35for IDEA_CONFIG_FILE in "${TRACKED_IDEA_FILES[@]}"
36do
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
46done