Is there a way to access unfiltered environment variable data under superenv?


(David E Wheeler) #1

I get why the environment is filtered to prevent build issues (some discussion here. But sometimes there needs to be a way for users to specify information required for a build. For example, a common way to specify the path to build tools that require the Oracle Instant client is to specify the $ORACLE_HOME environment variable.

Is it possible to access the original environment variables somehow? For example, in a Requirement I’m building if I want to check for SQL*Plus, I might do something like this, if I could, say, look at the user land environment variables via a Stdenv field:

satisfy(build_env: false) { ENV.Stdenv.include?("ORACLE_HOME") }

Would be useful In a formula install method, as well:

def install
    ENV["ORACLE_HOME"] = ENV.Stdenv["ORACLE_HOME"]
    system "make"
    system "make install
end

I haven’t found a way to access the unfiltered environment without turning off superenv altogether, but perhaps I’ve over looked it?

Thanks,

David


(Sean Molenaar) #2

@MikeMcQuaid might have a better answer to this.


(Mike McQuaid) #3

This is not possible. You can only access HOMEBREW_* variables and the original, non-filtered PATH.


(David E Wheeler) #4

Would you be open to a feature request (or patch—I’d need some pointers) adding support for looking up values in a hash representing the original environment?

Failing that, is there some other way I can pass options to a formula? The option feature appears to support only boolean --with-*/--without--* options.


(Mike McQuaid) #5

Sorry, I don’t think we would. It would all be need to done at the Bash level and hidden from the main process. In a case like this I would recommend figuring out a way to use the PATH or a (new) HOMEBREW_* variable.


(David E Wheeler) #6

I’m a little confused. Doesn’t the environment get filtered in ruby space before anything is shelled out? I’m just thinking of some way to examine the values that were set in the environment at the time brew started, even though they are no longer in the environment. This would allow formulas to find stuff set by the user and copy it strictly on an as-needed bases:

def install
    ENV["ORACLE_HOME"] = self.originalUnfilteredEnvironmentValues["ORACLE_HOME"]
    # ...
end

Nothing in originalUnfilteredEnvironmentValues would be present in ENV unless a formula specifically copied it. Thereafter, a copied variable would presumably be accessible by commands run via system, not nothing else.

If that’s not possible, is there some documentation for how to add a "(new) HOMEBREW_* variable? I don’t see anything about it in a quick skim of the cookbook.


(Mike McQuaid) #7

The environment is filtered in Bash before we’re in Ruby. We preserve only the existing PATH and any HOMEBREW_* variables.

You don’t need to do anything really. Just set it in the environment and access it as expected. They aren’t filtered.


(David E Wheeler) #8

You don’t need to do anything really. Just set it in the environment and access it as expected. They aren’t filtered.

Yeah, just discovered that by experimentation. Might I suggest mentioning that in the Cookbook?

I will document that the user should set HOMEBREW_ORACLE_HOME to get the build to work.

Thanks!