-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[driver] Add -working-directory option #14746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
@jrose-apple I'd appreciate your feedback on this patch. The general approach I took was to make this a driver-only option and eagerly resolve all relative paths in the driver. If you pass -working-directory, the frontend should only see absolute paths. For now I didn't touch the code in Another thing: using this option shouldn't affect the incremental build if all your paths were absolute to begin with, but because we add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it'll work. Only a few comments.
lib/Driver/Driver.cpp
Outdated
// although having a different working directory is probably incorrect. | ||
auto xcc = Opts->getOption(options::OPT_Xcc); | ||
DAL->AddSeparateArg(/*BaseArg=*/nullptr, xcc, "-working-directory"); | ||
DAL->AddSeparateArg(/*BaseArg=*/nullptr, xcc, workingDirectory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not do this here. Put it in addCommonFrontendOptions
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there somewhere I should be stashing the working directory so that it's available directly in that function, or should I get it from the argument list (and call make_absolute) again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think doing that is fine.
lib/Driver/Driver.cpp
Outdated
} | ||
} | ||
} | ||
|
||
/// Form a filename based on \p base in \p result, optionally setting its | ||
/// extension to \p newExt and in \p workingDirectory. | ||
static void filenameFromBaseAndExt(StringRef base, StringRef newExt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I think this function name needs a verb if the result isn't in the return value.
I don't really care about preserving that. I don't see people adding or removing |
Oh, and here are some more options that might refer to paths:
|
I reordered your list:
Will do!
These already work, presumably because they're aliases of options that have the right flags. I will add a test for
These are |
I don't really care what happens here but I'd like to be consistent for all aliases.
I'm okay with you not doing so. I just wanted to make sure it was an explicit decision. |
Adds a -working-directory option which can be used to modify how relative paths are resolved. It affects all other paths used in driver options (controlled by a new ArgumentIsPath flag on options) as well as the contents of output file maps and auxilliary file paths generated implicitly by the compiler itself. rdar://37713856
a7be8af
to
20cb3e3
Compare
@jrose-apple updated patch per your feedback. For the aliases that I touched, I copied all the flags from the aliased options for consistency. |
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check with @jrose-apple but I think at least the movement to a field in Compilation would be good. Otherwise looks ok to me.
const OutputFileMap *OFM, const ToolChain &TC, | ||
Compilation &C) const; | ||
const OutputFileMap *OFM, StringRef workingDirectory, | ||
const ToolChain &TC, Compilation &C) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer to make this a field on the Compilation object. It's of a similar provenance to the other things stored there and it looks like you're having to thread it through lots of calls that already take a Compilation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh fun. I was following the example of OutputFileMap
, OutputInfo
and ToolChain
. Now that I look more carefully at Compilation
, I see we have fields for all three of those (and they appear to me to be the same objects), so I don't know why we also thread them through every call too. I'm happy to move working dir into Compilation assuming @jrose-apple agrees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love it because it seems like something that's only used while building up the Compilation, and not something you need once it's fully-built and ready to, well, compile things. But maybe that distinction's only in my head.
(Originally, none of the three things you mentioned were in Compilation. They've all migrated there because of batch mode, which needs to construct jobs "late".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OutputFileMap held in the compilation is a derived one (holding all the aux and intermediates in a compilation), whereas the one being passed around as args here is an input. This is a somewhat recent development and perhaps not ideal, but they're not the same object.
The ToolChain and OutputInfo args are the same as those being threaded around though, it's true; I guess we can just pull them out of Compilation now (they're new arrivals).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok. On matters of taste here I'm happy to defer to @jrose-apple, passed-as-an-arg it is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll admit I don't love another argument being passed around either. I'm just not sure Compilation is the place to put it. And Ben doesn't have to be the one to clean this up.
PathStorage.insert(PathStorage.begin(), workingDirectory.begin(), | ||
workingDirectory.end()); | ||
llvm::sys::path::append(PathStorage, PathStrCopy); | ||
return StringRef(PathStorage.data(), PathStorage.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm misunderstanding, I think you're returning a StringRef to a local buffer that goes out of scope here (i.e. invalid memory).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, yes, I misread.
Adds a -working-directory option which can be used to modify how
relative paths are resolved. It affects all other paths used in driver
options (controlled by a new ArgumentIsPath flag on options) as well as
the contents of output file maps and auxilliary file paths generated
implicitly by the compiler itself.
rdar://37713856