This is an archive of the discontinued LLVM Phabricator instance.

Let the OS take care of the current working directory
Needs ReviewPublic

Authored by espindola on Mar 31 2017, 2:31 PM.

Details

Reviewers
modocache
rnk
Summary

This make the internal shell a bit more like a regular shell. When 'cd' is executed, it just use chdir for example. This is more reliable as it is really hard to audit everything that might use the current working directory.

This works as is because we always chdir at the start of a test execution.

The next steps probably are

  • Change the environment to be managed the same way.
  • Implement export
  • Implement environment variables expansion like $PATH
  • Maybe use subprocess.run to have an fully isolated process for each test run. I think this is pretty much necessary if we are to implement subshells

Diff Detail

Event Timeline

rafael created this revision.Mar 31 2017, 2:31 PM
rafael retitled this revision from Let the OS take case of the current working directory to Let the OS take care of the current working directory.Mar 31 2017, 2:33 PM
rnk edited edge metadata.Mar 31 2017, 5:36 PM

chdir isn't thread safe, and lit still supports running the tests with threads. It looks like there are portability issues with requiring multiprocessing everywhere, so I think this change would require conditionally launching a child python process to implement the internal shell. That also kind of sucks, though, since python process startup isn't fast.

I also kind of liked emulating the shell environment. It seemed cleaner than manipulating global state. That's a minor concern, though.

I think you're right, if we want to implement subshells and ulimit, we need to create a process and manipulate its environment, cwd, etc. What we have stops just short of that, since I've basically assumed that we will never implement shell variable expansion or subshells. I'd be happy if lit could do more basic environment variable manipulation (export), but subshells felt like a bridge too far. I figured tests that needed this stuff could call bash directly and have a REQUIRES: bash line or something.

Do you think we can reasonably implement variable expansion? The last time I looked at it, it seemed too hard, and I worked around the problem by adding more lit substitutions. Maybe it would be OK if we just implemented the ${} expansion syntax?

espindola commandeered this revision.Mar 15 2018, 8:53 AM
espindola added a reviewer: rafael.