How to set environment variables when building? [message #161722] |
Thu, 12 January 2006 08:03  |
Eclipse User |
|
|
|
Originally posted by: fabricio.dea.inpe.br
I have a workspace with some different projects, which I switch all the
time.
In this workspace, I created some "External Tools" configurations to call
scripts that depends on the name of the output of the current project (I
pass the executable's name as argument to some scripts).
When I change the project that I'm working in the workspace I have to
change the name of the output in all of my External Tools configurations.
Sometimes I forgot to do this and... well, the result is not good.
I would like to use an environment variable and set its value when I
command a build, so when the external tool is called I could use this env.
var. to inform the executable's name without worry about change the
arguments of the scripts every time I change a project.
How can I do this? I tried the "Environment" tab in the "C/C++ Make
Project" item (Project Properties), but it appears not to have effect
outside of the build process.
Any sugestion will be appreciated.
Thank you in advance,
Fabricio.
|
|
|
|
Re: How to set environment variables when building? [message #164635 is a reply to message #161722] |
Fri, 24 February 2006 17:34  |
Eclipse User |
|
|
|
Fabricio-
I wanted to do exactly this also, but didn't see an answer. So i have
created my own kluge.
I have created my own plug-in based on the "Managed Build System
Extensibility Document" that is part of the "CDT Plug-in Developer
Guide" in Eclipse help.
In the extensions view of my new plug-in, i have a projectType that is
then connected to a configuration. When i create a new project using my
plug-in, i have to be sure to select my project type and configuration
so that my plug-in additions get used.
Back in the plug-in code, under the configuration extension, the
Extension Element Details includes a postbuildStep where i have entered:
package ${PROJECT_NAME}
Since this line shows up in my Makefile, the sample below creates
${PROJECT_NAME} as a makefile macro. But i first made it work as an
environment variable with almost exactly the same code.
Back under the projectType extension, in the Extension Element Details i
have entered under the projectMacroSupplier:
com.myproject.ProjectMacro.
For the environment variable, you would enter your java supplier class
under the projectEnvironmentSupplier.
The code below is from the java source in my plug-in. It implements
IProjectBuildMacroSupplier, while the environment variable supplier will
implement IProjectEnvironmentVariableSupplier. The interesting thing is
that the project object knows the name of the project stored in the
owner field. Both it and the accessor are private, so the real klugy
part here is that i had to grab the id and pull the project name out of it.
If i don't hear from other folks that this was unnecessary, i should
file an enhancement request in Bugzilla to make this variable available
to the rest of the makefile build process.
-Keithen
package com.myproject;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.managedbuilder.macros.IProjectBuildMacroSupp lier;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacro;
public class ProjectMacro implements IProjectBuildMacroSupplier {
static final int ENV_NUM_PARAMS = 1;
static final String PROJECT_NAME = "PROJECT_NAME"; //$NON-NLS-1$
public IBuildMacro getMacro(String macroName,
IManagedProject project,
IBuildMacroProvider provider) {
if (macroName.equals(PROJECT_NAME)) {
// The build system knows the name of the project as it builds the Makefile.
// There should be no need for me to add this kluge.
// FIXME Replace with real Makefile project name macro.
String projectNameValue = project.getBaseId();
projectNameValue = projectNameValue.substring(0,
projectNameValue.indexOf('.'));
return new BuildMacro(PROJECT_NAME, IBuildMacro.VALUE_TEXT,
projectNameValue); //$NON-NLS-1$
}
return null;
}
public IBuildMacro[] getMacros(IManagedProject project,
IBuildMacroProvider provider) {
IBuildMacro[] tmp = new IBuildMacro[ENV_NUM_PARAMS];
tmp[0] = getMacro(PROJECT_NAME, project, provider);
return tmp;
}
}
Fabricio de Novaes Kucinskis wrote:
> I have a workspace with some different projects, which I switch all the
> time.
>
> In this workspace, I created some "External Tools" configurations to
> call scripts that depends on the name of the output of the current
> project (I pass the executable's name as argument to some scripts).
>
> When I change the project that I'm working in the workspace I have to
> change the name of the output in all of my External Tools
> configurations. Sometimes I forgot to do this and... well, the result is
> not good.
>
> I would like to use an environment variable and set its value when I
> command a build, so when the external tool is called I could use this
> env. var. to inform the executable's name without worry about change the
> arguments of the scripts every time I change a project.
>
> How can I do this? I tried the "Environment" tab in the "C/C++ Make
> Project" item (Project Properties), but it appears not to have effect
> outside of the build process.
>
> Any sugestion will be appreciated.
> Thank you in advance,
>
>
> Fabricio.
>
|
|
|
Powered by
FUDForum. Page generated in 0.03432 seconds