This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 262404 - Allow the use of environment variables in build environment
Summary: Allow the use of environment variables in build environment
Status: REOPENED
Alias: None
Product: cnd
Classification: Unclassified
Component: Toolchain (show other bugs)
Version: 8.1
Hardware: PC Mac OS X
: P3 normal (vote)
Assignee: Alexander Simon
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-10 22:42 UTC by johanp
Modified: 2017-03-30 14:56 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description johanp 2016-06-10 22:42:59 UTC
Allow the use of environment variables in build environment.

I'm building a medium sized non-trivial C/C++ system on OS X using GNU autotools with netbeans. When running the build from a standard terminal in OS X everything works just fine (or when running NetBeans on Linux with the same source). However, I'm having great difficulties getting the build to work entirely within Netbeans on OS X.

The problem, as far as I can tell, is that the build seems to be happening in a a very clean shell with almost no environment variables set. Especially the PATH variable seems to only be set to "/usr/bin" which means that all necessary local tools in "/usr/local/bin" is not found in the configuration step.

Furthermore this is not as easy to fix by just adding some PATH setting in another top-level make file since this environment really needs to be in the shell since the configuration pre-build step needs to know where it can find various tools.

Due to the intricacy of the autotools it is not possible to adjust the path inside the config script early enough so that the tools haven't already started doing their magic. It really needs to be set as an environment variable before the process starts. I tried adding a PATH setting in the make command but Netbeans just barfs at that saying that the "export PATH=..." is not a valid command.

I'm recording this as a defect since it is impossible to go around and it breaks the builds and is a different behaviour from NetBeans on for example Linux (where the exact same source work just fine in all aspects)

You already support the option to set environment variables for running a program but not for building. This should be a fairly straight forward addition and I can think of several occasion (apart from my specific problem) where control over the build environment is crucial especially for projects that are build on multiple platforms.

The only semi-workaround is to always do an initial configuration and build from an external terminal and then do builds that only implies recompiling trivial dependencies from within NetBeans. Any more complex builds will require stepping out of NetBeans.
Comment 1 johanp 2016-06-11 07:46:09 UTC
The only workaround (I finally realized after having some issues of getting NetBeans to accept the commands) is to add some some shell commands as a customized pre-Build:

So for example I need to add a hardcoded path such as:

/bin/sh -c "export PATH='/usr/local/bin:/bin:/usr/bin'; export XML_CATALOG_FILES="/usr/local/etc/xml/catalog"; ./configure --prefix=/usr/local CC=${IDE_CC}  CFLAGS='-g3 -gdwarf-2' "

in the pre-Build command dialogue of NetBeans

However, I still hink there needs to be an option (in analogue to the run environment possibility). It is also very unclear, to me, on what environment NetBeans is actually using.
Comment 2 Alexander Simon 2016-06-14 13:17:29 UTC
Hi johanp,

Could you clarify how did you start Netbeans?

Netbeans should inherit terminal env if you start Netbeans from terminal.
If you start Netbeans as application by MAC GUI, env inside Netbeans is initialized in other way.

Alexander
Comment 3 johanp 2016-06-14 14:17:08 UTC
I start Netbeans from the UI (the normal OS X way for UI applications). Shame to say (and I'm embarrassed..) it hasn't occurred to me to start it from the terminal on OS X (as I do on other systems) since it normally requires specifying the full path under the Application folder and it is a very "un OS X" way to start GUI applications.

I tried it and starting from the command line gives (of course) the correct environment. It is only when started from the UI the environment is not set.

Not sure on the best way to resolve this. Perhaps when Netbeans start it would be possible to "dummy" start a terminal and run a small script which outputs the environment variables defined and stores them. When the shell is later on directly started one of the Posix calls which allows the environment to be passed in as an argument could be used to start the command shell.

Seems like a "clutch"-solution though ...

The only other way I can think of is to add a small "start netbeans" script/program which is added to the "/bin" path so that it is easier to start netbeans directly from a terminal and also detach the started Netbeans from it's controlling terminal and put in the background.
Comment 4 Alexander Simon 2016-06-14 16:06:09 UTC
Inheritance env from parent process (terminal) is a standard way to setup env inside Netbeans.
You can also google how to setup env for Mac applications (for example edit *.plist).
So it is not a bug. You can reopen the issue as an enhancement.
Comment 5 kpalsson 2016-11-28 13:28:30 UTC
Alexander, that argument is bogus.  If that argument was valid, there wouldn't be an option for setting environment variables for the RUN command.  What we're asking for is the same setting, but for the BUILD command. 

And no, it's completely inappropriate to set my user environment and then start netbeans.  You know netbeans can have multiple projects and multiple configurations at the same time right?  I want that too.  I don't want to exit netbeans, change an environment variable and restart netbeans.  That's madness.  Please come up with a substantially better reason for closing this.
Comment 6 Vladimir Voskresensky 2016-11-28 13:46:48 UTC
(In reply to kpalsson from comment #5)
> Alexander, that argument is bogus.  If that argument was valid, there
> wouldn't be an option for setting environment variables for the RUN command.
> What we're asking for is the same setting, but for the BUILD command. 
Have you tried Launchers?
http://wiki.netbeans.org/NewAndNoteworthyNB82#UI_for_Run.2FDebug_launchers

Btw, you can open corresponding nbproject/launcher.properties and nbproject/private/launcher.properties to read comments.

I think you can specify ENV vars there as well and then you will have submenu in project context menu instead of plain Run/Build
Comment 7 Vladimir Voskresensky 2016-11-29 13:42:25 UTC
Btw, due to https://netbeans.org/bugzilla/show_bug.cgi?id=269165
in build command you need to specify
sh -e "your build command using $ENV_VAR"