【问题标题】:Eclipse conditional path variablesEclipse 条件路径变量
【发布时间】:2012-02-21 13:52:01
【问题描述】:

是否可以在 Eclipse 中设置条件路径变量?这对于例如自定义构建器(它与 Indigo 中的项目一起存储 - 我认为在旧 Eclipse 版本中不是这种情况)在不同平台下调用不同程序很有用。

所以我正在寻找的是类似的东西:

${if{${system:OS}=='Windows'}compiler.exe${else}compiler.sh

【问题讨论】:

    标签: eclipse path-variables


    【解决方案1】:

    如果您特别想在不同平台上调用不同的编译器,那么您可以使用 Ant 或 Make 来检测您的平台并调用不同的程序。

    在您项目的属性中,转到“构建器”并创建一个新的构建步骤。如果您使用 GNU Make 作为构建器,您可以在 Makefile 中使用如下语法:

    # Only MS-DOS/Windows builds of GNU Make check for the MAKESHELL variable
    # On those platforms, the default is command.com, which is not what you want
    MAKESHELL := cmd.exe
    
    # Ask make what OS it's running on
    MAKE_OS := $(shell $(MAKE) -v)
    
    # On Windows, GNU Make is built using either MinGW or Cygwin 
    ifeq ($(findstring mingw, $(MAKE_OS)), mingw)
    BUILD_COMMAND := compiler.exe
    
    else ifeq ($(findstring cygwin, $(MAKE_OS)), cygwin)
    BUILD_COMMAND := compiler.exe
    
    else ifeq ($(findstring darwin, $(MAKE_OS)), darwin)
    BUILD_COMMAND := compiler-osx.sh
    
    else ifeq ($(findstring linux, $(MAKE_OS)), linux)
    BUILD_COMMAND := compiler.sh
    
    endif
    

    在 Ant 构建脚本中,条件执行由 ifunlessdepends 等属性决定。 <os family=xxx> 标签告诉您正在运行的操作系统。下面是 devdaily 的一个例子:

    <?xml version="1.0"?>
    
    <!--
      An Ant build script that demonstrates how to test to see
      which operating system (computer platform) the Ant build
      script is currently running on. Currently tests for Mac OS X,
      Windows, and Unix systems.
      Created by Alvin Alexander, DevDaily.com
    -->
    
    <project default="OS-TEST" name="Ant Operating System Test" >
    
      <!-- set the operating system test properties -->
      <condition property="isMac">
        <os family="mac" />
      </condition>
    
      <condition property="isWindows">
        <os family="windows" />
      </condition>
    
      <condition property="isUnix">
        <os family="unix" />
      </condition>
    
      <!-- define the operating system specific targets -->
      <target name="doMac" if="isMac">
        <echo message="Came into the Mac target" />
        <!-- do whatever you want to do here for Mac systems -->
      </target>
    
      <target name="doWindows" if="isWindows">
        <echo message="Came into the Windows target" />
      </target>
    
      <target name="doUnix" if="isUnix">
        <echo message="Came into the Unix target" />
      </target>
    
      <!-- define our main/default target -->
      <target name="OS-TEST" depends="doMac, doWindows, doUnix">
        <echo message="Running OS-TEST target" />
      </target>
    
    </project>
    

    【讨论】:

    • 感谢您的回答。我知道使用 ant(或任何其他构建工具)的可能性,但我认为 Eclipse 可能有一种方法可以直接支持基于平台的分支。显然没有。因此,您的答案作为问题的一般解决方案是最好的。
    【解决方案2】:

    我通过运行 windows .exe 文件作为构建后步骤解决了这个问题。

    在 Windows 下这很好,但在 Linux 中,我必须在命令前加上 wine

    为了解决OS条件问题,我在Eclipse中做了一个环境变量:

    wineLinux=wine
    

    然后像这样构建后期构建步骤:

    ${wine${OsType}}  window_file.exe args
    

    系统变量OsType将扩展为Linux,在上一步中创建的环境变量wineLinux将扩展为wine

    【讨论】:

      猜你喜欢
      • 2010-12-02
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多