The assets rake tasks re-run themselves after fixing the environment variables. This makes it impossible to change $0 at all. It's a variable so the code shouldn't assume that it's remained the same.
@Talby can you post an example on what you're trying to achieve and what does exactly fail?
@drogus If in my own app i set $0 to something manually, and then try and do the example rake task if fails since $0 != the command used to run the rake task.
@Talby I've looked into this and the reason is that assets:precompile tries to rerun some of the tasks. I've managed to fix part of the problem and opened a pull request for sprockets-rails.
What assets:precompile essentially does is running 2 other tasks:
rake assets:precompile:nondigest # only if you use digests
If you would like to avoid using $0, you can just run those 2 tasks with proper env vars:
rake assets:precompile:primary RAILS_ENV=production RAILS_GROUPS=assets
rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
If you do that, rake tasks should not be rerun with $0 usage.
I'm closing this issue, since this is a problem with sprockets-rails. My pull request will fix the problem with running those 2 tasks, but after it's applied you will still need to set RAILS_ENV and RAILS_GROUPS env variables in order to avoid restarting - this will not be likely fixed soon.