Skip to content

Commit 0b25d25

Browse files
committed
fixed: dependency lookup cache query fails, if lookup key is present in multiple entries
1 parent 9e2edf9 commit 0b25d25

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

kscript

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,17 @@ fi
209209
if [ $(grep "^// DEPS" ${scriptFile} | wc -l) -gt 0 ]; then
210210
echo "[ERROR] Dependencies must be declared by using the line prefix //DEPS" 1>&2; exit 1;
211211
fi
212-
dependencies=$(grep "^//DEPS" ${scriptFile} | cut -f2- -d' ' | trim | tr ',;\n' ' ')
212+
213+
## find all //DEPS directives and concatenate their values
214+
dependencies=$(grep "^//DEPS" ${scriptFile} | cut -f2- -d' ' | trim | tr ',;\n' ' ' | sed 's/ $//g')
213215

214216

215217
## First try dependency cache directly to avoid jvm launch for resdeps.kts
216-
# fix me more consistent use of ${TMPDIR}
217218
dependency_cache="${KSCRIPT_CACHE_DIR}/dependency_cache.txt"
218219
if [ -n "$dependencies" ] && [ -f "$dependency_cache" ]; then
219-
classpath=$(grep -F $(echo ${dependencies} | tr ' ' ';')" " ${dependency_cache} | cut -d' ' -f2)
220+
# https://stackoverflow.com/questions/22861580/bash-script-check-if-a-file-contains-a-specific-line
221+
depQuery="$(echo ${dependencies} | tr ' ' ';')"
222+
classpath=$(awk '$1 == "'$depQuery'"' ${dependency_cache} | cut -d' ' -f2)
220223
fi
221224

222225
## If there are dependencies but cache-lookup failed we run resdeps.kts
@@ -289,16 +292,12 @@ elif [[ $scriptFileExt == ".kt" ]]; then
289292
fi
290293

291294

292-
echo "classpath is '${classpath}'"
293-
294-
295295
# build cache-jar if it does not yet exist
296296
if [ ! -f "${jarFile}" ]; then
297297
## remove previous (now outdated) cache jars
298298
rm -f .$(basename ${scriptFile} .kts).*.jar
299299

300300

301-
echo "kotlinc -classpath "${classpath}" -d ${jarFile} ${scriptFile}"
302301
kotlinc -classpath "${classpath}" -d ${jarFile} ${scriptFile}
303302

304303
if [ $? -eq 1 ]; then

misc/playground.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,15 @@ JAR_CMD=jar
7474
(cd ${TMPDIR}/tt/ && ${JAR_CMD:=jar} cvf foojar.jar *)
7575
unzip -vl ${TMPDIR}/tt/foojar.jar
7676

77+
78+
#### dependency lookp
79+
80+
if [ ! -z $(grep "$STRING" "$FILE") ]; then echo "FOUND"; fi
81+
grep "^"$(echo ${dependencies} | tr ' ' ';')" " "${dependency_cache}"
82+
83+
grep -F "^"$(echo ${dependencies} | tr ' ' ';')" " ${dependency_cache} | cut -d' ' -f2
84+
85+
if [ ! -z $(grep "^"$(echo ${dependencies} | tr ' ' ';')" " "${dependency_cache}") ]; then echo "FOUND"; fi
86+
classpath=$(grep -F $(echo ${dependencies} | tr ' ' ';')" " ${dependency_cache} | cut -d' ' -f2)
87+
88+
awk '$1 == "'"${dependencies}"'"' ${dependency_cache}

0 commit comments

Comments
 (0)