views:

40

answers:

1

Hello,

I'm totally new to scripting but I got sick and tired of compiling my native code for Android manually so I wrote a little .sh script and a .bat file to run this script in cygwin. Both files are placed in the root of a project, in the .sh file the NDK directory is set and then by running the .bat file I compile my native code.

The problem is that I want to do it dynamically so I use %CD% to get the current directory ( which should be the project folder) and start the .sh file in that directory.

Here are both files:

.bat :

@echo off

::Used to surpess a warning about dos directory format.
set CYGWIN=nodosfilewarning

C:\cygwin\bin\bash --login -i %CD%\./compile.sh

pause

.sh:

#!/bin/bash

#Run this script through compileNative.bat This will compile the native code of this Project
#IF this file is changed under windows use "tr -d '\r' < edited.sh > final.sh " to remove the bad line endings.
#Keep both this and the .bat file in the project root.
# Set this to the base NDKDir
NDKDIR=C:/Android/NDK/


#Get the base dir so we can change the directory to the base dir.
BASEDIR=`dirname $0`

echo 
echo Compiling Native code. Refresh Workspace after this is done!
echo 
#Change to the directory of the project, change this is if the project movies.
cd $BASEDIR

#Run the ndk build file. Change this to the correct location.
$NDKDIR./ndk-build

When I open the .bat file from the folder in windows it runs just fine. When I run it from eclipse though it seems that %CD% gives me "C:/Eclipse". What annoys me more is the fact that it ran all morning, but that suddenly it started doing this.

So my question is, am I using %CD% in the wrong way or why can this happen. Obviously this is not a big drama. But it is a little annoying problem I can't seem to figure out.

Some Help would be great.

A: 

I suggest creating an External tool configuration for this (the Green Run icon with a red box - or lock, right next to the Run/Debug icons). The external tool can launch scripts, with predefined environment variables, or working directories.

To set these directories dynamically (e.g. based on the currently selected project), you can use platform variables, such as ${container_loc} or ${resource_loc} - use the Variables... button to get a list of available variables.

Update: this way you can probably add the cygwin script directly, without the need of the bat file.

Zoltán Ujhelyi
Today I finally got to test your suggestion. It works like a charm, now it doesn't even open a new window, but I can see it in the Eclipse console.I did keep the bat file since I don't want to spend too much time on this. But I guess you are right about it and it would be possible to do it without the bat file too.Thank you very much!
Pandoro