Setting PATH environment variable on ant build.xml works on cygwin but not on cmd or PowerShell - powershell

I was trying to set PATH enviroment variable on an ant build.xml through this answer.
It works on cygwin but not on cmd or PowerShell.
Some information:
Apache Ant 1.6.5 (I know there is a newer version (1.8.4), but for internal reasons I have to use this older version)
Powershell v2.0
cmd v6.1.7601
cygwin 2.774
Windows 7

You may need to use the exec task a little differently on Windows/cmd environments.
Let's use the windows command set as an example. set will print environment variables. A normal exec task running a set command might look like:
<exec executable="set" outputproperty="set.output">
<env key="MY_VAR" value="MY_VAL"/>
<echo message="${set.output}"/>
</exec>
But using this form of the exec task should throw an IOException: The system cannont find the file specified.
When running ant under windows cmd shell, the exec task can also be invoked via cmd, like this:
<exec executable="cmd" outputproperty="set.output">
<arg line="/c set"/>
<env key="MY_VAR" value="MY_VAL"/>
<echo message="${set.output}"/>
</exec>
This is the equivalent command; the actual command executed is cmd /c set, which is running set in a cmd sub-process.
The reason why this is necessary is only a little complicated and is due to the way that the commands are located by Win32 ::CreateProcess. The ant exec docs briefly explain this.
Note that I haven't tried either of these using PowerShell, so I have no experience which, if either, will work.
In my own ant build scripts I typically have two versions of each target that require special handling for windows platforms, with an isWindows test that looks like this:
<target name="check-windows">
<condition property="isWindows">
<os family="windows"/>
</condition>
</target>
Then I can switch between versions of the same task using:
<target name="my-target-notwindows" depends="check-windows" unless="isWindows>
...
</target>
<target name="my-target-windows" depends="check-windows" if="isWindows>
...
</target>
<target name="my-target" depends="my-target-notwindows,my-target-windows">
...
</target>

Unfortunatelly was an ant bug related to 1.6.5 version. I was able to update to 1.8.4 and everything works fine.

Related

Building Windows 8 Phone App on Command Line

I'm currently porting an existing cross platform framework to Windows Phone 8.
The build process is fully automated and we are using a rock solid CI system.
I can build and deploy Windows Phone 8 samples from Visual Studio (Express 2012),
but now I need to integrate that into our build scripts.
Did anybody ever successfully build (and deploy) a Win Phone 8 app via the commandline?
(Or ant, make, scons, whatever...)
If yes, how?
Any hints are welcome.
I used the following bat file to build WP7 code (+ant automation on top of it). It may be helpful for you.
build.bat
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.xml /t:BuildAndCopy /p:Revision=123
where build.xml is something like (build itself goes under BuildAll target)
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<Major>1</Major>
<Minor>0</Minor>
<Build>0</Build>
<Revision>x</Revision>
<OutputPath>Build\</OutputPath>
<OutputPathDebug>..\Build\Debug\</OutputPathDebug>
<OutputPathRelease>..\Build\</OutputPathRelease>
</PropertyGroup>
<Target Name="BuildAll" DependsOnTargets="Clean; Version">
<msbuild Projects="SomeApp.sln" Properties="Configuration=Release;OutputPath=$(OutputPathRelease)"/>
<msbuild Projects="SomeApp.sln" Properties="Configuration=Debug;OutputPath=$(OutputPathDebug)"/>
</Target>
<Target Name="Clean">
<RemoveDir Directories="$(OutputPath)" Condition="Exists('$(OutputPath)')"/>
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')"/>
</Target>
<Target Name="Version">
<Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>
<XmlUpdate
Namespace=""
XmlFileName="WindowsPhone\Properties\WMAppManifest.xml"
XPath="//App[#Version]//#Version"
Value="$(Major).$(Minor).$(Build).$(Revision)"/>
</Target>
<ItemGroup>
<AppFiles Include="$(OutputPath)\**\*.xap"/>
</ItemGroup>
<Target Name="BuildAndCopy" DependsOnTargets="BuildAll">
<Copy
SourceFiles="#(AppFiles)"
DestinationFiles="#(AppFiles->'\\fs\Public\projects\mobile\SomeAppWP\$(Major).$(Minor).$(Build).$(Revision)\%(RecursiveDir)%(Filename)%(Extension)')"
/>
<Copy
SourceFiles="#(AppFiles)"
DestinationFiles="#(AppFiles->'\\fs\Public\projects\mobile\SomeAppWP\latest\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>
</Project>
It should be easy. I'll assume you have the following file structure
$/WP8App/SampleApp.sln
You will have to use the paths and solution file in your project. Execute the following instructions, and make sure to update solution file and path:
Open a command prompt
Execute: %VS110COMNTOOLS%vsvars32.bat
Execute: %VS110COMNTOOLS%..\..\VC\WPSDK\WP80\vcvarsphoneall.bat
Execute: MSBuild "WP8App/SampleApp.sln" /t:rebuild
/p:Configuration=Release /p:Platform="Any CPU" /v:d
Please notice:
The computer where you're going to run these commands should have the development environment for WP8 already set up.
If your application uses native libraries (such as PlayerFramework http://playerframework.codeplex.com/ which are installed into VS, these libraries should also be installed before running the commands)
I have used this process on VS2012 Pro and VS2012 Premium and Jenkins as Build Server.
Good luck,
Herb
Thanks to Sergei's MSBuild.exe hint I was able to build a simple sample via the command line.
https://github.com/AndreasOM/wp8-directx-commandline
There is a build.bat included, which should be enough to get you started to build for "windows phone 8" with the build system of your choice.
It's fairly hacky at the moment,
but once I get the current project done
I will clean it up.
Hint:
Never define a "CL" environment variable when working with "CL.exe" ;)

Eclipse conditional path variables

Is it possible to set conditional path variables in Eclipse? This would be useful for instance for a custom builder (which is stored with the project in Indigo - I think this wasn't the case in old Eclipse versions) to call a different program under a different platform.
So what I'm looking for would be a something along the lines of:
${if{${system:OS}=='Windows'}compiler.exe${else}compiler.sh
If you would specifically like to invoke different compilers on different platforms, then you can use Ant or Make to detect your platform and call different programs.
In your project's properties, go to "Builders" and create a new build step. If you're using GNU Make as a builder, you can use syntax like the following in your 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
In Ant build scripts, conditional execution is determined by attributes like if, unless, and depends. The <os family=xxx> tag tells you what OS you're running on. Here's an example from 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>
I solved it by running a windows .exe file as a post-build step.
This is fine under Windows, but in Linux, I had to preface the command with wine.
To solve the OS conditional problem, I made an environment variable in Eclipse:
wineLinux=wine
And then constructed the post build-step like this:
${wine${OsType}} window_file.exe args
The system variable OsType will expand to Linux and the environment variable wineLinux that was created in the previous step will expand to wine.

acceleoCompiler not showing output in console output with ant

I am using acceleoCompiler inside an ant script and when i run the ant script everything shows an output except acceleoCompiler.
For instance, [javac] and [mkdir] shows up. But nothing relating to acceleoCompiler shows up. Am i doing something wrong?
The ant script:
<eclipse.refreshLocal resource="${F_FOLDER}/bin/" depth="infinite"/>
<eclipse.refreshLocal resource="${FE_FOLDER}/bin/" depth="infinite"/>
<mkdir dir="${F_OUTPUT}"/>
<mkdir dir="${FE_OUTPUT}"/>
<javac
srcdir="${F_SRC}generator/"
destdir="${FR_OUTPUT}"
executable="${JAVA_JDK}/javac"
fork="true"
includeantruntime="false"
failonerror="false"
/>
<javac
srcdir="${FE_SRC}generator/"
destdir="${FE_OUTPUT}"
executable="${JAVA_JDK}/javac"
fork="true"
includeantruntime="false"
failonerror="false"
/>
<acceleoCompiler sourceFolder="${F_SRC}"
outputFolder="${F_OUTPUT}"
dependencies=""
binaryResource="true"
packagesToRegister="org.eclipse.emf.ecore.EcorePackage">
</acceleoCompiler>
<acceleoCompiler sourceFolder="${F_SRC}"
outputFolder="${FE_OUTPUT}"
dependencies=""
binaryResource="true"
packagesToRegister="org.eclipse.emf.ecore.EcorePackage">
</acceleoCompiler>
The absence of logging messages doesn't mean you're doing anything wrong. If you look at the source for mkdir or javac you'll see that they call the Ant Task method log() in most cases. The Acceleo Ant task however only calls log() if it finds a problem - if all is well it is silent and enigmatic.
References:
Ant mkdir task source.
AcceleoCompiler source via the Acceleo wiki FAQ.

How do I suppress warnings in NAnt when using the solution task?

We have a .NET 1.1 solution that we are compiling using NAnt with a "solution" task.
One of the projects throws multiple warnings for missing XML comments. I know which warnings I need to suppress (from http://bytes.com/topic/net/answers/177026-suppress-missing-xml-comment-warning-during-compile), but I can't see how. The csc task has a configuration element that can be used for this, but I can't see an equivalent for solution.
Is this even possible? How can I do it?
Replace NAnt's <solution> task by NAntContrib's <msbuild> task. You can pass solution files to MSBuild as well as project files and you can pass MSBuild properties like WarningLevel then. Find an example here.
I tend to prefer running an exec task for msbuild. This will suppress all warnings:
<exec program="${msbuild_exe_path}">
<arg line='"${solution_path}"' />
<arg line="/property:WarningLevel=0" />
<!-- SNIP -->
</exec>
More info on warning level settings: http://msdn.microsoft.com/en-us/library/13b90fz7.aspx
Getting msbuild to work on .net 1.1: http://blogs.msdn.com/b/jomo_fisher/archive/2004/11/29/271748.aspx

How can I execute a Perl script using the Ant exec task?

I currently have this in my Ant build script:
<exec dir="${basedir}" executable="perl">
<arg line="${basedir}/version.pl -major"/>
</exec>
However, when that runs, I get this error message:
[exec] Could not open -major
[exec] Result: 2
To me, that says that what I have is trying to run a file called -major, which doesn't exist. The file is version.pl which takes an argument of -major.
How can I alter this to run version.pl with the argument -major?
Note that I am running the ant script on a Solaris machine, however cross-platform or solutions for other OSes are welcome for posterity.
I made a quick little Perl script that didn't do a whole lot and ran it just fine passing command line arguments to it using Ant 1.5 on a Solaris box.
<project name="perly" basedir="." default="run">
<target name="run">
<exec executable="perl" dir="${basedir}">
<arg value="version.pl"/>
<arg value="-major"/>
</exec>
</target>
</project>
$ ant run
What I can't quite understand is how you are getting "Could not open -major". Is this a custom die message or something? Is there supposed to be a filename passed instead of major?
You can try this:
<exec executable="perl" dir="${basedir}">
<arg value="version.pl"/>
<arg value="-major"/>
</exec>
On windows that is
Try this if it works:
<exec dir="${basedir}" executable="./test.pl">
<arg line="-major"/>
</exec>
From the ant exec doc:
dir: the directory in which the command should be executed.
So i guess it does a cd to the $dir and exec the $executable (shebang set)