77
88set -ex pipefail
99
10+ if [ -z " $TORCHCHAT_ROOT " ]; then
11+ echo " Defaulting TORCHCHAT_ROOT to $PWD since it is unset."
12+ TORCHCHAT_ROOT=$PWD
13+ fi
14+
1015install_pip_dependencies () {
1116 echo " Intalling common pip packages"
1217 pip3 install wheel " cmake>=3.19" ninja zstd
@@ -20,21 +25,54 @@ function find_cmake_prefix_path() {
2025 MY_CMAKE_PREFIX_PATH=$path
2126}
2227
23- clone_executorch () {
24- echo " Cloning executorch to ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} /src"
25- rm -rf ${TORCHCHAT_ROOT} / ${ET_BUILD_DIR}
28+ clone_executorch_internal () {
29+ rm -rf ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} /src
30+
2631 mkdir -p ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} /src
2732 pushd ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} /src
2833 git clone https://github.com/pytorch/executorch.git
2934 cd executorch
3035 git checkout $( cat ${TORCHCHAT_ROOT} /install/.pins/et-pin.txt)
31- echo " Install executorch : submodule update"
36+ echo " Install ExecuTorch : submodule update"
3237 git submodule sync
3338 git submodule update --init
3439
3540 popd
3641}
3742
43+ clone_executorch () {
44+ echo " Cloning ExecuTorch to ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} /src"
45+
46+ # Check if executorch is already cloned and has the correct version
47+ if [ -d " ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} /src/executorch" ]; then
48+ pushd ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} /src/executorch
49+
50+ # Check if the repo is clean
51+ git_status=$( git status --porcelain)
52+ if [ -n " $git_status " ]; then
53+ echo " ExecuTorch repo is not clean. Removing and recloning."
54+ popd
55+ clone_executorch_internal
56+ return
57+ fi
58+
59+ # Check if the version is the same
60+ current_version=$( git rev-parse HEAD)
61+ desired_version=$( cat ${TORCHCHAT_ROOT} /install/.pins/et-pin.txt)
62+
63+ if [ " $current_version " == " $desired_version " ]; then
64+ echo " ExecuTorch is already cloned with the correct version. Skipping clone."
65+ popd
66+ return
67+ fi
68+
69+ echo " ExecuTorch is already cloned but has the wrong version. Removing and recloning."
70+ popd
71+ fi
72+
73+ clone_executorch_internal
74+ }
75+
3876install_executorch_python_libs () {
3977 if [ ! -d " ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} " ]; then
4078 echo " Directory ${TORCHCHAT_ROOT} /${ET_BUILD_DIR} does not exist."
0 commit comments