Skip to content

Commit 522ac75

Browse files
authored
[dsymutil] Bump .dSYM bundle directory mtime after a rewrite (llvm#199257)
When dsymutil rewrites an existing .dSYM bundle, only the inner DWARF file is replaced and the bundle directory's mtime stays frozen at the time of the original build. macOS Spotlight's bundle re-import path keys off the bundle directory's mtime to decide whether the importer should re-run. With the mtime frozen, Spotlight keeps the previous build's UUID indexed forever, DebugSymbols.framework's Spotlight lookup misses on the new UUID. Bump the bundle directory's mtime explicitly at the end of a successful run, reusing the .dSYM extraction already used by the codesign path. rdar://177725866
1 parent 1dd0811 commit 522ac75

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Verify dsymutil bumps the .dSYM bundle directory's mtime when rewriting an
2+
## existing bundle in place. macOS Spotlight keys off this mtime to decide
3+
## whether to reimport the bundle's UUID; without the bump, Spotlight serves
4+
## the previous build's UUID and DebugSymbols falls through to slow
5+
## dsymForUUID lookups.
6+
7+
RUN: rm -rf %t.dir
8+
RUN: mkdir -p %t.dir
9+
RUN: cat %p/../Inputs/basic.macho.x86_64 > %t.dir/basic
10+
RUN: dsymutil -oso-prepend-path=%p/.. %t.dir/basic
11+
12+
## Backdate the bundle dir to a known epoch so any update is visible.
13+
RUN: env TZ=GMT touch -t 197001020000 %t.dir/basic.dSYM
14+
## Marker with a newer-than-backdated timestamp; the second dsymutil run
15+
## must move the bundle dir's mtime past this marker.
16+
RUN: env TZ=GMT touch -t 200001010000 %t.dir/marker
17+
18+
RUN: dsymutil -oso-prepend-path=%p/.. %t.dir/basic
19+
20+
## `find -maxdepth 0 -newer` prints the bundle path iff its mtime is newer
21+
## than the marker. Without the mtime bump, the directory keeps its 1970
22+
## stamp and find prints nothing.
23+
RUN: find %t.dir/basic.dSYM -maxdepth 0 -newer %t.dir/marker | FileCheck %s
24+
CHECK: basic.dSYM

llvm/tools/dsymutil/dsymutil.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,33 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
10421042
}
10431043
}
10441044
}
1045+
1046+
// Bump the .dSYM bundle directory's mtime so macOS Spotlight reimports
1047+
// the (possibly new) UUID. Rewriting the inner DWARF file alone leaves
1048+
// the bundle directory mtime frozen, and Spotlight keeps serving the
1049+
// previous build's UUID, falling through to slow dsymForUUID lookups.
1050+
{
1051+
StringRef DWARFFile = OutputLocationOrErr->DWARFFile;
1052+
// Walk components from the right: the innermost match is the bundle
1053+
// itself, even when a parent directory is also named *.dSYM.
1054+
StringRef BundlePath;
1055+
for (auto I = sys::path::rbegin(DWARFFile),
1056+
E = sys::path::rend(DWARFFile);
1057+
I != E; ++I) {
1058+
StringRef Component = *I;
1059+
if (sys::path::extension(Component) == ".dSYM") {
1060+
BundlePath = DWARFFile.substr(0, Component.end() - DWARFFile.begin());
1061+
break;
1062+
}
1063+
}
1064+
if (!BundlePath.empty()) {
1065+
auto Now = std::chrono::system_clock::now();
1066+
if (auto EC =
1067+
sys::fs::setLastAccessAndModificationTime(BundlePath, Now))
1068+
WithColor::warning() << "could not update mtime of " << BundlePath
1069+
<< ": " << EC.message() << '\n';
1070+
}
1071+
}
10451072
}
10461073

10471074
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)