5

I use Qt Creator with custom build system (ninja). The issue is that the $PATH variable passed to the Qt Creator IDE is absolutely vanilla: /usr/bin:/bin:/usr/sbin:/sbin.

So I have to write bash -c '/path/to/ninja list of targets' instead of just ninja list of targets, or perform build steps in a terminal, not in the IDE.

I tried all known recipes to set up the $PATH.

  • ~/.bash_profile and ~/.profile
  • /etc/paths
  • /etc/paths.d/*
  • /etc/launchd.conf (setenv PATH .....)
  • ~/Library/LaunchAgents/*.plist (sh -c 'launchtcl setenv PATH $PATH:.....')
  • /Library/LaunchAgents/*.plist

The idea of using launch agenes is described in a StackOverflow answer.

None works! Any arbitrary environment var in my custom .plist file sets correctly, - any but the PATH. (I have tested it simply: created a custom build step echo xzxzxz=$XZXZXZ path=$PATH where xzxzxz is also set in my launch agent).

It's interesting that if I launch Qt Creator from bash session ('/Applications/Qt Creator.app/Contents/MacOS/Qt Creator' &), it gets correct PATH, same as the bash itself.

Also it's interesting that the PATH assigned with the launch agent is later overwritten. There I wrote sh -c 'launchctl setenv PATH $PATH:/HELLOWORLD', but I don't see that HELLOWORLD in echo $PATH. So, there are a race condition, someone rebuilds the PATH from /etc/paths and /etc/paths.d later.

Thus:

  • is there an exhaustive and up-to-date explanation how to set up environment variables, and particularly PATH, on OSX 10.10 ?
  • why the PATH becomes vanilla?
  • how to win with Qt Creator?
Community
  • 1
  • 1
Nickolay Merkin
  • 2,673
  • 1
  • 16
  • 14
  • The path becomes vanilla, since graphical applications have no need for one. Finder sets a vanilla path for you, and that's the correct behavior on OS X. If you wish a path that your shell gives you, you need to run `login` and then run your application from the shell - or run something else to extract the path from a shell thus started. This has *nada* to do with Qt Creator. You need to run the shell to parse your shell scripts to extract the PATH from them, pretty much. It won't "just" happen. A non-vanilla path could easily make your session inoperable. That'd be bad. – Kuba hasn't forgotten Monica Jun 17 '15 at 23:08
  • I think that the simplest solution would be a small script that extracts your path from the shell and imbues the project configuration file with it. – Kuba hasn't forgotten Monica Jun 18 '15 at 23:48

1 Answers1

2

You could just update the path to the build environment of your project inside Qt Creator.

Newer versions (>3.3 AFAIR, 3.4 for certain) allow to set environment overrides in each the kit, so that you could have it for all projects using those.

Tobias Hunger
  • 560
  • 2
  • 9
  • Yess! It is a solution - to set up environment variables directly inside IDE. But I still cannot understand what happened with PATH variable on the input. – Nickolay Merkin Jun 17 '15 at 14:33
  • @NickolayMerkin Why did you expect a path in a graphical environment that wasn't even started from the shell? You act as if everything was started through your shell, and your login shell is the one that knows what *your* PATH is. No shell, no PATH. After all, you set PATH in scripts that run only when the shell runs. On OS X, a graphical session doesn't touch the shell, not even for startup. – Kuba hasn't forgotten Monica Jun 17 '15 at 23:10
  • @KubaOber Because it would be common. Windows does that, Linux does that, only OSX cuts all ropes. As you can see, I tried setting environment using OSX-specific, looking like true way - launch daemon. Not the shell!!! And my testing variable, XZXZXZ, has been set and passed. – Nickolay Merkin Jun 18 '15 at 08:49
  • @Nickolay: Sorry, my Qt Creator foo is strong, but my Mac foo is weak:-)No idea how to change the environment it passes to UI applications there. – Tobias Hunger Jun 18 '15 at 15:39
  • @NickolayMerkin Windows doesn't do what Unix does. It stores the path in the registry settings, and uses it directly without invoking the shell. On Unices, there's no registry, and the path is specified implicitly in scripts that must be executed in order to obtain it. I'm not even completely sure if all Unices use the path from the login shell to set up the X session. I'd personally consider it a security risk, and a source of hard to track bugs. If your application wishes to run an executable, it should store its full path. Qt Creator correctly forces a clean path, even on Unices, IIRC. – Kuba hasn't forgotten Monica Jun 18 '15 at 23:46