+9

Build cmd has no environment (OSX)

Oktay Acikalin 13 år siden opdateret af Nabil Boukala 11 år siden 12
Is it correct that a build script starts with nearly no environment on OSX? I would have assumed that my .profile would have been parsed before executing the cmd.
For now I had to run bash with --login to get it. Is there a better way to do this?
I believe that this is correct for the way OS X works: .profile is parsed by the shell, and neither Sublime Text X nor the spawned process is a child of any shell process, so I would not expect .profile to be parsed at any point. Let me know if my understanding is incorrect.
+1
I've tried to run it via Finder, Dock and iTerm/Terminal. The Finder and Dock seem to be started without sourcing .profile, therefore nearly no env vars. When run from a terminal it gets all variables as I wished.
Do you think that it's awkward to implement an optionally definable shell command (e.g. "bash --login") to use as a wrapper for all shell calls from the config files? This way one could choose (by configuration) to either run them isolated or from a specific point of view (e.g. virtualenv or a custom wrapper which loads a proper virtualenv or shell env according to path etc. - at least that's what I would want to brew for myself...).
Python's subprocess module, which is used to implement the exec command, and hence the build systems, supports a parameter shell=True (False by default), that may well do what you want.

If you're feeling keen, can you try editing Packages/Default/exec.py, line 25, add the shell=True parameter, and see if that works for you?

If so, I can easily add 'shell' as a parameter in .sublime-bulid files
It's a little bit better but it doesn't source the .profile 'cause bash isn't called as a login shell.

An optional parameter shell=False|True would be good anyway for people who know what they do.

I've now added these lines before line 19 as an example:

        arg_list_prefix = ['bash', '-l', '-c']
        if arg_list_prefix:
            from pipes import quote
            arg_list = map(quote, arg_list)
            arg_list = arg_list_prefix + [' '.join(arg_list)]

I would really like to define this arg_list_prefix in my configuration file.
I also replaced the first line of my code above with these:

        settings = sublime.load_settings("Global.sublime-settings")
        arg_list_prefix = settings.get("arg_list_prefix", [])
i agree with theblacklion, it would be good to wrap build script calls with bash --login. Otherwise on MacOS X you are stuck with whatever environment is inherited from the parent process (launchd), which is configured by nonstandard files (/etc/launchd.conf, ~/.MacOSX/environment.plist)
+1
How about a more general mechanism than just calling "bash --login"?

What I really need are per-project environment settings. These could be simply defined in the project file for now and via a GUI at some future date.

When using popen, these could be pushed into the "env" argument.

You could, of course, also have an option in the build definition: "execution_shell" = True or somesuch.
Please take a look at this: http://www.sublimetext.com/forum/viewtopic.php?f=5&t=1699
It covers bash and virtualenv but could be easily adopted to other languages as well.
I really hope that Jon brings something like my arg list wrapper into the core...
Also +1 for "project specific setting/env overwrites".
+1

Build systems don't even have the environment defined in ~/.MacOSX/environment.plist — I have PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin there, but build systems run with PATH=/usr/bin:/bin:/usr/sbin:/sbin and make doesn't find my gettext tools in /usr/local/bin.


OSX 10.6.8, ST2 build 2139

I'm having the same problem. OS X 10.7.2, ST2 build 2156.

Strangely, I did manage to get the PATH variable to be recognized by ST2 a week ago, by adding
launchctl setenv PATH $PATH
to my ~/.bash_profile (after I'd set PATH). It seemed to take a reboot or two after I did that, but finally it just started working - I was able to hit CMD+B in ST2 and it would find the build program in my custom path instead of spit out "File not found". Now, I've just updated ST2 to the latest build and it's apparently broken again!

I wish I knew the correct way to get PATH recognized in ST2... I'm just not following the rest of the suggestions here (unfortunately I'm not a Python guy, yet).
Has there been a resolution on this issue?  This had been a problem for https://github.com/uipoet/sublime-jshint/issues/21, and we had to scope the PATH option just for Mac for the plugin to work.

I had no env variables defined when running CMD+B in sublime text. I created a link (sudo ln -s "/Applications/SublimeText2.app/Contents/SharedSupport/bin/subl" ~/bin/subl) as explained in the documentation.

Then when I run ST from the shell using subl &, CMD+B works fine and gets all that is defined in my .profile

Kundesupport af UserEcho