[PECOFF] Resolve file name in the driver, not in InputElement.

llvm-svn: 224209
This commit is contained in:
Rui Ueyama 2014-12-14 02:50:29 +00:00
parent e9b455184f
commit 11c4874d83
3 changed files with 24 additions and 21 deletions

View File

@ -31,8 +31,6 @@ public:
PECOFFFileNode(PECOFFLinkingContext &ctx, StringRef path)
: FileNode(path), _ctx(ctx), _parsed(false) {}
ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
/// \brief Parse the input file to lld::File.
std::error_code parse(const LinkingContext &ctx,
raw_ostream &diagnostics) override;
@ -49,8 +47,6 @@ class PECOFFLibraryNode : public PECOFFFileNode {
public:
PECOFFLibraryNode(PECOFFLinkingContext &ctx, StringRef path)
: PECOFFFileNode(ctx, path) {}
ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
};
} // namespace lld

View File

@ -282,6 +282,25 @@ static bool parseManifest(StringRef option, bool &enable, bool &embed,
return true;
}
StringRef getObjectPath(PECOFFLinkingContext &ctx, StringRef path) {
std::string result;
if (isCOFFLibraryFileExtension(path)) {
result =ctx.searchLibraryFile(path);
} else if (llvm::sys::path::extension(path).empty()) {
result = path.str() + ".obj";
} else {
result = path;
}
return ctx.allocate(result);
}
StringRef getLibraryPath(PECOFFLinkingContext &ctx, StringRef path) {
std::string result = isCOFFLibraryFileExtension(path)
? ctx.searchLibraryFile(path)
: ctx.searchLibraryFile(path.str() + ".lib");
return ctx.allocate(result);
}
// Returns true if the given file is a Windows resource file.
static bool isResoruceFile(StringRef path) {
llvm::sys::fs::file_magic fileType;
@ -1340,9 +1359,11 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
for (StringRef path : inputFiles) {
path = ctx.allocate(path);
if (isCOFFLibraryFileExtension(path)) {
libraries.push_back(std::unique_ptr<FileNode>(new PECOFFLibraryNode(ctx, path)));
libraries.push_back(std::unique_ptr<FileNode>(
new PECOFFLibraryNode(ctx, getLibraryPath(ctx, path))));
} else {
files.push_back(std::unique_ptr<FileNode>(new PECOFFFileNode(ctx, path)));
files.push_back(std::unique_ptr<FileNode>(
new PECOFFFileNode(ctx, getObjectPath(ctx, path))));
}
}
@ -1365,7 +1386,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
for (const StringRef path : defaultLibs)
if (!ctx.hasNoDefaultLib(path))
libraries.push_back(std::unique_ptr<FileNode>(
new PECOFFLibraryNode(ctx, ctx.allocate(path.lower()))));
new PECOFFLibraryNode(ctx, getLibraryPath(ctx, path.lower()))));
if (files.empty() && !isReadingDirectiveSection) {
diag << "No input files\n";

View File

@ -40,18 +40,4 @@ std::error_code PECOFFFileNode::parse(const LinkingContext &ctx,
return ctx.registry().parseFile(std::move(mb.get()), _files);
}
ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
if (isCOFFLibraryFileExtension(_path))
return _ctx.searchLibraryFile(_path);
if (llvm::sys::path::extension(_path).empty())
return _ctx.allocate(_path.str() + ".obj");
return _path;
}
ErrorOr<StringRef> PECOFFLibraryNode::getPath(const LinkingContext &) const {
if (isCOFFLibraryFileExtension(_path))
return _ctx.searchLibraryFile(_path);
return _ctx.searchLibraryFile(_ctx.allocate(_path.str() + ".lib"));
}
} // end anonymous namespace