在 ant 构建文件中获取 shell 配置文件?

发布于 2024-09-10 07:32:28 字数 320 浏览 3 评论 0原文

我正在使用 Cruisecontrol 和 ant 构建一些旧版可执行文件,这些可执行文件也依赖于 shell 配置文件来正确设置环境变量。有没有办法在当前进程中使用 ant 执行此配置文件,以便 makefiles ant 调用正确获取环境变量?

另一个解决方案是是否有一种方法可以将配置文件源添加到我正在调用的子 make 文件中。

编辑:我想我的问题不清楚。我知道需要传递哪些环境变量才能使用 exec/env 任务。但是,我不知道如何让 ant 从通常通过 获取的 shell 配置文件中获取值。 /usr/local/profile/foo.profile

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.profile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲墙角沉默 2024-09-17 07:32:28

我根据 ant 本身如何获取环境变量找出了如何做到这一点。

<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"/>

再往下,我可以使用 exec 标签将它们传递给 sub make 调用。例如:

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

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>
请持续率性 2024-09-17 07:32:28

您将无法在当前进程中执行 make。

看看ant 任务,使用它来执行您的 make 构建。环境变量仍然可用于 make 过程,事实上您可以使用 newenvironment 属性显式关闭它。以下简单的 exec 应该保留 make 中的所有环境变量:

<exec executable="make" />

如果您需要额外的环境变量,或者想要通过 ant 构建维护它们,您可以通过添加 元素在 exec 任务中使用它们像这样:

<exec executable="make" >
    <env key="ENV_KEY" value="ENV_VALUE"/>
</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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文