#!/usr/bin/perl
# Copyright (c) 2014 B. Kevin Hardman
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
my ($uuid) = @ARGV;
my ($path) = qx(mdfind "com_apple_xcode_dsym_uuids == $uuid");
exit if $path !~ m/\.xcarchive$/;
chomp $path;
$path = "$path/dSYMs";
opendir(DIR, "$path") || die "Can't open directory $path: $!\n";
my @files = readdir(DIR);
closedir(DIR);
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
print "<plist version=\"1.0\">\n";
print "<dict>\n";
foreach my $file (@files) {
$file = "$path/$file";
my ($_) = qx(dwarfdump -u "$file");
next if $_ !~ /DWARF/;
my ($uuid, $arch, $executable) = m/^UUID: ([^ ]*) \(([^)]*)\) (.*)$/;
print "<key>$uuid</key>\n";
print "<dict>\n";
print "<key>DBGArchitecture</key>\n";
print "<string>$arch</string>\n";
print "<key>DBGDSYMPath</key>\n";
print "<string>$file</string>\n";
print "<key>DBGSymbolRichExecutable</key>\n";
print "<string>$executable</string>\n";
print "</dict>\n";
}
print "</dict>\n";
print "</plist>\n";