if !exists never sees file

In a ports Makefile, the following if statement never evaluates to false, i.e. never thinks the file exists:
Makefile:
pre-fetch:
.if !exists(${DISTDIR}/${DIST_SUBDIR}/${MAVEN_CACHE_FILE})
        ls -alh ${DISTDIR}/${DIST_SUBDIR}/${MAVEN_CACHE_FILE}
        ${MKDIR} ${DISTDIR}/${DIST_SUBDIR}
        # Do a bunch of other stuff...
.endif

The ls in the third line is just for testing, and shows us that the file is indeed there!
===> cassandra4-4.1.2 depends on executable: ant - found
ls -alh /usr/ports/distfiles/cassandra/apache-cassandra-4.1.2-repo.tar.xz
-rw-r--r-- 1 root wheel 75M Jul 9 10:55 /usr/ports/distfiles/cassandra/apache-cassandra-4.1.2-repo.tar.xz
/bin/mkdir -p /usr/ports/distfiles/cassandra

There are several other .ifs in the Makefile, and they all work as expected, though none of them involve checking the existence of a file.

So pre-fetch code always runs, downloading the maven dependencies anew, and this port can't be built offline.
What's wrong with the syntax here? Thanks in advance for your insight.
 
The port Makefile has the target and .if the other way around:
Code:
.if !exists(${DISTDIR}/${DIST_SUBDIR}/${MAVEN_CACHE_FILE})
pre-fetch:
 
Inserting an .error ${DISTDIR}/${DIST_SUBDIR}/${MAVEN_CACHE_FILE} after the .if shows that DISTDIR is undefined at that time, so likely you need to include the bsd.port.pre.mk earlier somehow.
 
It doesn't seem to work whether I enclose the target with the conditional or put the conditional inside of the target but enclose the rest of the target's contents. I assume the later is what you mean by putting the check inside the recipe.
 
It doesn't seem to work whether I enclose the target with the conditional or put the conditional inside of the target but enclose the rest of the target's contents. I assume the later is what you mean by putting the check inside the recipe.
No, with "inside the recipe", I meant "let the shell do it", e.g. like this:
Code:
pre-fetch:
        if [ -f "${DISTDIR}/${DIST_SUBDIR}/${MAVEN_CACHE_FILE}" ]; then \
            ${MKDIR} ${DISTDIR}/${DIST_SUBDIR} \
            # [...] \
        fi
It's an option, might be ugly for larger blocks. Alternative is what yuripv79 suggested.
 
Why oops?
I was saying the same thing you wrote about shell check with a "what zirias meant is the following", and as soon as I hit "post", I saw your post right there, few seconds before mine :D So I edit it into a "oops".

EDIT: interesting, is there a way to see post edits here?
 
I can see a "history" button on each post. But I'm sure it's because of my mod/admin privileges, don't think it's available for any one else (including the original poster).
 
Thanks for your suggestions. I've moved the pre-fetch target to the end of the target list, just after .include <bsd.port.pre.mk>. (Moving the include up before all targets, in an attempt to keep the targets in the "correct" order, throws a bunch of "duplicate script for target..." warnings.) Nesting ~16 lines of code into a single shell line concatenated by a bunch of ...; \...s feels too difficult to get right and maintain.
 
Back
Top