Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?xml version="1.0"?>
<project name="Proj" default="dist" basedir=".">
<description>
Builds proj.
</description>
<property name="dist" location="dist"/>
<property name="proj1" location="proj1"/>
<property name="proj2" location="proj2"/>
<property name="sh_sbx" location="shared-sandbox"/>
<property environment="env"/>
<condition property="cabal.bin" value="${env.CABAL_PATH}/cabal" else="cabal">
<os family="windows"/>
</condition>
<condition property="new.path" value="${env.GHC_HOME}/bin;${env.GHC_HOME}/mingw/bin;${env.MSYS_HOME}/bin;${env.PATH}" else="${env.PATH}">
<os family="windows"/>
</condition>
<condition property="bin.ext" value=".exe" else="">
<os family="windows"/>
</condition>
<property name="proj1.bin" location="${proj1}/dist/build/proj1/proj1${bin.ext}"/>
<property name="proj2.bin" location="${proj2}/dist/build/proj2/proj2${bin.ext}"/>
<condition property="isSandboxExists">
<available file="${sh_sbx}" type="dir"/>
</condition>
<macrodef name="cabal.configure">
<attribute name="dir"/>
<attribute name="property"/>
<sequential>
<exec executable="${cabal.bin}" dir="@{dir}" resultproperty="@{property}">
<env key="PATH" path="${new.path}/"/>
<arg value="configure"/>
</exec>
</sequential>
</macrodef>
<macrodef name="cabal.cmn">
<attribute name="dir"/>
<element name="args" optional="yes"/>
<sequential>
<exec executable="${cabal.bin}" dir="@{dir}" failonerror="yes">
<env key="PATH" path="${new.path}/"/>
<args/>
</exec>
</sequential>
</macrodef>
<macrodef name="cabal">
<attribute name="dir"/>
<attribute name="target"/>
<sequential>
<cabal.cmn dir="@{dir}">
<args>
<arg value="@{target}"></arg>
</args>
</cabal.cmn>
</sequential>
</macrodef>
<target name="clean_sbx" description="Removes shared sandbox.">
<echo level="info">************** Shared sandbox removing **************</echo>
<delete dir="${sh_sbx}">
<fileset file="${proj1}/cabal.sandbox.config"/>
<fileset file="${proj2}/cabal.sandbox.config"/>
</delete>
</target>
<target name="init_sbx" description="Initialized shared sandbox for both binaries." unless="isSandboxExists">
<echo level="info">************** Shared sandbox initializing **************</echo>
<mkdir dir="${sh_sbx}"/>
<cabal.cmn dir="${sh_sbx}">
<args>
<arg value="sandbox"/>
<arg value="init"/>
<arg value="--sandbox=."/>
</args>
</cabal.cmn>
<cabal.cmn dir="${sh_sbx}">
<args>
<arg value="sandbox"/>
<arg value="add-source"/>
<arg value="../../kontiki"/>
<arg value="--sandbox=."/>
</args>
</cabal.cmn>
<cabal.cmn dir="${proj1}">
<args>
<arg value="sandbox"/>
<arg value="init"/>
<arg value="--sandbox=${sh_sbx}"/>
</args>
</cabal.cmn>
<cabal.cmn dir="${proj2}">
<args>
<arg value="sandbox"/>
<arg value="init"/>
<arg value="--sandbox=${sh_sbx}"/>
</args>
</cabal.cmn>
</target>
<target name="check_sbx" description="Very simple shared sandbox consistency check. Works only when added new library.">
<echo level="info">************** Shared sandbox checking **************</echo>
<cabal.configure dir="${proj1}" property="supRes"/>
<cabal.configure dir="${proj2}" property="hbRes"/>
<condition property="isConfigured">
<and>
<equals arg1="${supRes}" arg2="0"/>
<equals arg1="${hbRes}" arg2="0"/>
</and>
</condition>
</target>
<target name="prepare_sbx" depends="init_sbx, check_sbx" unless="isConfigured" description="Installs all needed libraries into shared sandbox.">
<echo level="info">************** Installing libraries from hackage nto shared sandbox **************</echo>
<cabal dir="${basedir}" target="update"/>
<cabal.cmn dir="${proj1}">
<args>
<arg value="install"/>
<arg value="--dependencies-only"/>
</args>
</cabal.cmn>
<cabal.cmn dir="${proj2}">
<args>
<arg value="install"/>
<arg value="--dependencies-only"/>
</args>
</cabal.cmn>
</target>
<target name="build" depends="prepare_sbx" description="Build proj1 binary.">
<echo level="info">************** Proj1 build **************</echo>
<cabal dir="${proj1}" target="build"/>
<echo level="info">************** Proj2 build **************</echo>
<cabal dir="${proj2}" target="build"/>
<echo level="info">************** Building is finshed **************</echo>
</target>
<target name="clean" description="Clean builds.">
<echo level="info">************** Cleannig builds and distribution **************</echo>
<delete dir="${dist}"/>
<cabal dir="${proj1}" target="clean"/>
<cabal dir="${proj2}" target="clean"/>
</target>
<target name="dist" depends="clean, build" description="Generate a distribution.">
<echo level="info">************** Making distribution **************</echo>
<mkdir dir="${dist}"/>
<tar destfile="${dist}/dist.tar.gz" compression="gzip">
<tarfileset file="${proj1.bin}"/>
<tarfileset file="${proj2.bin}"/>
</tar>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment