Reputation: 42957
I have the following problem: I have to execute different operation in the case the operating system is Linux and in the case the operating system is MacOs.
So I have create the following Ant script targets:
<condition property="unix">
<os family="unix" />
</condition>
<condition property="mac">
<os family="mac" />
</condition>
<target name="initUnixPath" if="unix" depends="clean">
<echo message="initUnixPath: SETTING UNIX PATH" />
<property name="path">/usr/share/XCloud/appl/lib/</property>
</target>
<target name="initMacPath" if="mac" depends="clean">
<echo message="initMacPath: SETTING MAC PATH" />
<property name="path">${basedir}/../../../Mac/CrystalIce/CrystalIce/CrystalIce/Build/Products/Debug/CrystalIce.app/Contents/Resources/java/</property>
</target>
<!-- Copy SharedLib jar files: -->
<!--<copy todir="${basedir}/../../../../../../../../usr/share/XCloud/appl/lib">-->
<!--<copy todir="/usr/share/XCloud/appl/lib">-->
<echo message="${path}" />
<copy todir="${path}">
<fileset dir="${basedir}/../../SharedLib" />
</copy>
..................................................
..................................................
COPY OTHER FILES
When it go to execute the init target this target depends from the initUnixPath and initMacPat targets
So happens the following thing:
1) If I execute it on a Linux machine it first execute the initUnixPath that set the path property to the correct value: "/usr/share/XCloud/appl/lib/", then execute the initMacPath and do nothing because the Linux machine is not a MacOs machine. So execute the init target and copy the files in the right location: "/usr/share/XCloud/appl/lib/"
2) If I execute it on a MacOs machine it first execute the initUnixPath (because MacOs is a BSD based system so it is a UNIX machine) that set the path property to the WRONG value "/usr/share/XCloud/appl/lib/" (because this is the path for Linux system and not for MacOs), then execute the initMacPath (because it match) and try to set the CORRECT path for MacOs system ("${basedir}/../../../../../../../../usr/share/XCloud/appl/lib") but it can't do it because the property is just setted and can't be change !!!)
So I have a problem because on a MacOs machine I have that path value is setted to the wrong Linux path ("/usr/share/XCloud/appl/lib/") and not to the right MacOs path ("${basedir}/../../../../../../../../usr/share/XCloud/appl/lib")
The only solution that I have found is to change the order of the dependency in the init target from:
<target name="init" depends="initUnixPath, initMacPath ">
to:
<target name="init" depends="initMacPath, initUnixPath ">
So it is a Mac set the correct path for the MacOs system, then enter in initUnixPath try to set the Linux path but it can't (and work well on Mac)
If it is a Linux system try to exexute initMacPath but Linux is not Mac so exit from this target and execute initUnixPath where correctly set the Linux path (and work well on Linux)
But this seems to me a very dirty solution !!!
So I am asking if I can detect more precisely if it is a LINUX SYSTEM (and not a generic UNIX System). Can I do it?
Tnx
Andrea
Upvotes: 1
Views: 893
Reputation: 107040
I always symbolically link binaries I install to /usr/local/bin
. This way, I don't have to worry whether it was installed in /Applications
or /opt
or /usr/share
, etc. If you don't see the executable in that location (via <available/>
task), fail the build with instructions on what to do.
<property name="bin.link.dir" value="/usr/local/bin"/>
<available file="${bin.link.dir}/xcloud" <!-- Or whatever the app -->
property="xcloud.app.available"/> <!-- Or whatever the app -->
<fail>
Could not find required app...
download it from yadda, yadda, yadda...
Install it by blah, blah, blah...
Then create a symbolic link to ${link.dir}...
<condition>
<not>
<isset property="xcloud.app.available"/>
</not>
</condition>
</fail>
You can also use the uname
command if it is a Unix type system to see if it's Linux or not:
<!-- outputs "Darwin" on Mac and "Linux" on Linux -->
<exec executable="uname"
os="unix"
outputproperty="os.type"/>
<condition property="linux.os">
<equals arg1="${os.type}" arg2="Linux"/>
</condition>
Upvotes: 1