开发者

Sourcing a shell profile in an ant build file?

I am using cruisecontrol and ant to build some legacy executables that also depend on a shell profile to setup env vars properly. Is there a way to exec this profile using ant in the current process so the makefiles ant calls get the env vars correctly?

Another solution would be if there is a way to add the profile sourcing to the sub make files I'm calling.

Edit: I guess I wasn't clear in my question. I know what env varibles need to be passed to make using the exec/env tasks. However, I don't know how to have ant grab the values from a shell profile that is usually sourced via: . /usr/local/profile/foo.开发者_StackOverflow社区profile


I figured out how to do it based off of how ant itself sources env variables.

<exec executable="ksh" dir="${foo.dir}" 
      failonerror="true" output="${foo.dir}/env.properties">
    <arg value="-c" />
    <arg value=". /usr/local/profiles/profile.foo; set" />
</exec>
<property file="${foo.dir}/env.properties" prefix="env"/>

Further down I can then pass them to sub make calls using the exec tags. For example:

<exec executable="make" dir="${bar.dir}" failonerror="true">
    <env key="ORACLE_HOME" value="${env.ORACLE_HOME}" />
</exec>


You will not be able to execute make in the current process.

Take a look at the ant <exec> task, use this to execute your make build. The environment variables will still be available for the make process, in fact you can turn this off explicitly with the newenvironment attribute. The following simple exec should retain all environment variables in make:

<exec executable="make" />

If you need extra environment variables, or want to maintain them through your ant build you can use them in the exec task by adding <env> elements like so:

<exec executable="make" >
    <env key="ENV_KEY" value="ENV_VALUE"/>
</exec>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜