[cfe-dev] [RFC] -frelative-path option to change __FILE__

Jordan Rose jordan_rose at apple.com
Fri Dec 7 11:53:27 PST 2012


Hi, all. We have a longstanding bug sitting on us (okay, me) about pruning the length of __FILE__, either to just the basename or to a relative source path. (For those inside Apple, this is <rdar://problem/4440158> and related.) The usual solution for this is just to embed a strrchr call in a second macro, but that's not so nice for globals, and doesn't handle the relative path case so well.

I propose a new flag, tentatively named -frelative-path=, which handles this by setting __FILE__ to a canonicalized relative path if it is set. I'm going to use ~/foo/bar/../baz/baz.cpp as the file name in these examples:

-frelative-path= (or absent)
	/Users/jrose/foo/bar/../baz/baz.cpp
-frelative-path=.
	baz.cpp
-frelative-path=/
	/Users/jrose/foo/baz/baz.cpp
-frelative-path=/Users/jrose/foo
	baz/baz.cpp
-frelative-path=../.. (always shows two folders up from the current source file)
	foo/baz/baz.cpp

Thoughts? Ideas on the flag name? Pushback? Missing use cases?

Jordan



More information about the cfe-dev mailing list