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