Skip to content

Commit 2bbc405

Browse files
dsymutil auto infer cas-path
1 parent 82f4013 commit 2bbc405

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

clang/test/ClangScanDeps/gmodules.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: split-file %s %t
55
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
66
// RUN: sed "s|DIR|%/t|g" %t/cdb_pch.json.template > %t/cdb_pch.json
7+
// RUN: sed "s|DIR|%/t|g" %t/cas-config.template > %t/.cas-config
78

89
/// Scan PCH
910
// RUN: clang-scan-deps -compilation-database %t/cdb_pch.json \
@@ -36,6 +37,7 @@
3637
/// Check debug info is correct.
3738
// RUN: %clang %t/tu.o -o %t/a.out
3839
// RUN: dsymutil -cas %t/cas %t/a.out -o %t/a.dSYM 2>&1 | FileCheck %s --check-prefix=WARN --allow-empty
40+
// RUN: dsymutil %t/a.out -o %t/a2.dSYM 2>&1 | FileCheck %s --check-prefix=WARN --allow-empty
3941
// WARN-NOT: warning:
4042

4143
// RUN: llvm-dwarfdump --debug-info %t/a.dSYM | FileCheck %s --check-prefix=DWARF
@@ -58,7 +60,11 @@
5860
// RUN: %deps-to-rsp %t/deps_2.json --module-name Right > %t/Right_2.rsp
5961
// RUN: %deps-to-rsp %t/deps_2.json --tu-index 0 > %t/tu_2.rsp
6062
// RUN: %clang @%t/Right_2.rsp
61-
// RUN: %clang @%t/tu_2.rsp
63+
// RUN: %clang @%t/tu_2.rsp -o %t/tu_2.o
64+
65+
/// Diff all outputs
66+
// RUN: diff %t/prefix.h.pch %t/prefix_2.pch
67+
// RUN: diff %t/tu.o %t/tu_2.o
6268

6369
// Check all the types are available
6470
// DWARF: DW_TAG_compile_unit
@@ -213,3 +219,8 @@ int main(void) {
213219
struct Top _top;
214220
struct Prefix _prefix;
215221
}
222+
223+
//--- cas-config.template
224+
{
225+
"CASPath": "DIR/cas"
226+
}

llvm/tools/dsymutil/BinaryHolder.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "BinaryHolder.h"
15+
#include "llvm/CAS/CASConfiguration.h"
1516
#include "llvm/Object/MachO.h"
1617
#include "llvm/Support/WithColor.h"
1718
#include "llvm/Support/raw_ostream.h"
@@ -263,6 +264,22 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
263264
return *(MemberCache[Key] = std::move(OE));
264265
}
265266

267+
static std::shared_ptr<cas::ObjectStore> searchAndCreateCAS(StringRef Path) {
268+
auto Config = cas::CASConfiguration::createFromSearchConfigFile(Path);
269+
if (!Config)
270+
return nullptr;
271+
272+
auto DB = Config->second.createDatabases();
273+
if (!DB) {
274+
consumeError(DB.takeError());
275+
return nullptr;
276+
}
277+
278+
WithColor::note() << "create CAS using configuration: " << Config->first
279+
<< "'\n";
280+
return DB->first;
281+
}
282+
266283
Expected<const BinaryHolder::ObjectEntry &>
267284
BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
268285
if (Opts.Verbose)
@@ -297,6 +314,9 @@ BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
297314
ObjectRefCounter[Filename]++;
298315
if (!ObjectCache.count(Filename)) {
299316
auto OE = std::make_unique<ObjectEntry>();
317+
if (!CAS)
318+
CAS = searchAndCreateCAS(Filename);
319+
300320
if (!(CAS && OE->load(*CAS, Filename, Opts))) {
301321
auto Err = OE->load(VFS, Filename, Timestamp, Opts);
302322
if (Err)

0 commit comments

Comments
 (0)