//
//===----------------------------------------------------------------------===//
//
-// This program is a utility that aims to be a dropin replacement for
-// Darwin's dsymutil.
-//
+// This program is a utility that aims to be a dropin replacement for Darwin's
+// dsymutil.
//===----------------------------------------------------------------------===//
#include "dsymutil.h"
desc("Embed warnings in the linked DWARF debug info."),
cat(DsymCategory));
-static bool createPlistFile(llvm::StringRef Bin, llvm::StringRef BundleRoot) {
+static Error createPlistFile(llvm::StringRef Bin, llvm::StringRef BundleRoot) {
if (NoOutput)
- return true;
+ return Error::success();
// Create plist file to write to.
llvm::SmallString<128> InfoPlist(BundleRoot);
llvm::sys::path::append(InfoPlist, "Contents/Info.plist");
std::error_code EC;
llvm::raw_fd_ostream PL(InfoPlist, EC, llvm::sys::fs::F_Text);
- if (EC) {
- WithColor::error() << "cannot create plist file " << InfoPlist << ": "
- << EC.message() << '\n';
- return false;
- }
+ if (EC)
+ return make_error<StringError>(
+ "cannot create Plist: " + toString(errorCodeToError(EC)), EC);
CFBundleInfo BI = getBundleInfo(Bin);
<< "</plist>\n";
PL.close();
- return true;
+ return Error::success();
}
-static bool createBundleDir(llvm::StringRef BundleBase) {
+static Error createBundleDir(llvm::StringRef BundleBase) {
if (NoOutput)
- return true;
+ return Error::success();
llvm::SmallString<128> Bundle(BundleBase);
llvm::sys::path::append(Bundle, "Contents", "Resources", "DWARF");
- if (std::error_code EC = create_directories(Bundle.str(), true,
- llvm::sys::fs::perms::all_all)) {
- WithColor::error() << "cannot create directory " << Bundle << ": "
- << EC.message() << "\n";
- return false;
- }
- return true;
+ if (std::error_code EC =
+ create_directories(Bundle.str(), true, llvm::sys::fs::perms::all_all))
+ return make_error<StringError>(
+ "cannot create bundle: " + toString(errorCodeToError(EC)), EC);
+
+ return Error::success();
}
static bool verify(llvm::StringRef OutputFile, llvm::StringRef Arch) {
Expected<OwningBinary<Binary>> BinOrErr = createBinary(OutputFile);
if (!BinOrErr) {
- errs() << OutputFile << ": " << toString(BinOrErr.takeError());
+ WithColor::error() << OutputFile << ": " << toString(BinOrErr.takeError());
return false;
}
return false;
}
-static std::string getOutputFileName(llvm::StringRef InputFile) {
+static Expected<std::string> getOutputFileName(llvm::StringRef InputFile) {
// When updating, do in place replacement.
if (OutputFileOpt.empty() && Update)
return InputFile;
llvm::SmallString<128> BundleDir(OutputFileOpt);
if (BundleDir.empty())
BundleDir = DwarfFile + ".dSYM";
- if (!createBundleDir(BundleDir) || !createPlistFile(DwarfFile, BundleDir))
- return "";
+ if (auto E = createBundleDir(BundleDir))
+ return std::move(E);
+ if (auto E = createPlistFile(DwarfFile, BundleDir))
+ return std::move(E);
llvm::sys::path::append(BundleDir, "Contents", "Resources", "DWARF",
llvm::sys::path::filename(DwarfFile));
// Using a std::shared_ptr rather than std::unique_ptr because move-only
// types don't work with std::bind in the ThreadPool implementation.
std::shared_ptr<raw_fd_ostream> OS;
- std::string OutputFile = getOutputFileName(InputFile);
+
+ Expected<std::string> OutputFileOrErr = getOutputFileName(InputFile);
+ if (!OutputFileOrErr) {
+ WithColor::error() << toString(OutputFileOrErr.takeError());
+ return 1;
+ }
+
+ std::string OutputFile = *OutputFileOrErr;
if (NeedsTempFiles) {
TempFiles.emplace_back(Map->getTriple().getArchName().str());
auto E = TempFiles.back().createTempFile();
if (E) {
- errs() << toString(std::move(E));
+ WithColor::error() << toString(std::move(E));
return 1;
}
OS = std::make_shared<raw_fd_ostream>(NoOutput ? "-" : OutputFile, EC,
sys::fs::F_None);
if (EC) {
- errs() << OutputFile << ": " << EC.message();
+ WithColor::error() << OutputFile << ": " << EC.message();
return 1;
}
}
if (!AllOK)
return 1;
- if (NeedsTempFiles &&
- !MachOUtils::generateUniversalBinary(
- TempFiles, getOutputFileName(InputFile), *OptionsOrErr, SDKPath))
- return 1;
+ if (NeedsTempFiles) {
+ Expected<std::string> OutputFileOrErr = getOutputFileName(InputFile);
+ if (!OutputFileOrErr) {
+ WithColor::error() << toString(OutputFileOrErr.takeError());
+ return 1;
+ }
+ if (!MachOUtils::generateUniversalBinary(TempFiles, *OutputFileOrErr,
+ *OptionsOrErr, SDKPath))
+ return 1;
+ }
}
return 0;