generate-export-file [plain text]
use strict;
use warnings;
use File::Basename;
use File::Find;
use File::Temp qw(tempfile);
use Getopt::Long;
sub preprocessorFlags();
sub preprocessorMacros($\@);
sub process($$$);
my $showHelp = 0;
my $verbose = 1;
my $result = GetOptions(
"help" => \$showHelp,
"verbose" => \$verbose,
);
if (!$result || $showHelp || scalar(@ARGV) != 2) {
print STDERR basename($0) . " [-h|--help] [-v|--verbose] infile outfile\n";
exit 1;
}
my $inFile = shift @ARGV;
my $outFile = shift @ARGV;
my $arch;
if ($outFile =~ /\.([^.]+)\.exp$/) {
$arch = $1;
}
die "Unknown arch!" if !defined($arch) || !$arch;
print "Processing $inFile for $arch...\n" if $verbose;
process($inFile, $outFile, $arch);
exit 0;
sub preprocessorFlags()
{
my @features = split(/\s+/, $ENV{GCC_PREPROCESSOR_DEFINITIONS});
return @features;
}
sub preprocessorMacros($\@)
{
my ($cc, $cc_args) = @_;
my @args = @$cc_args;
push(@args, map { "-D" . $_ } preprocessorFlags());
push(@args, qw(-include wtf/Platform.h -include wtf/Assertions.h));
push(@args, "-F" . $ENV{BUILT_PRODUCTS_DIR}) if $ENV{BUILT_PRODUCTS_DIR};
push(@args, "-I" . $ENV{BUILT_PRODUCTS_DIR} . "/usr/local/include") if $ENV{BUILT_PRODUCTS_DIR};
push(@args, "-I" . $ENV{BUILT_PRODUCTS_DIR} . $ENV{SDKROOT} . "/usr/local/include") if $ENV{BUILT_PRODUCTS_DIR};
if (exists $ENV{SYSTEM_LIBRARY_DIR} && $ENV{SYSTEM_LIBRARY_DIR}) {
my $frameworkSearchPath = $ENV{SDKROOT} . $ENV{SYSTEM_LIBRARY_DIR};
if ($ENV{PLATFORM_NAME} eq "iphoneos" || $ENV{PLATFORM_NAME} eq "iphonesimulator") {
$frameworkSearchPath .= "/PrivateFrameworks";
} else {
$frameworkSearchPath .= "/Frameworks";
}
push(@args, "-F" . $frameworkSearchPath);
}
push(@args, "-I" . $ENV{BUILT_PRODUCTS_DIR} . $ENV{SDKROOT} . "/usr/local/include") if $ENV{BUILT_PRODUCTS_DIR};
push(@args, "-I" . $ENV{SDKROOT} . "/usr/local/include");
push(@args, qw(-dM /dev/null));
print join(" ", $cc, @args), "\n" if $verbose;
local $/ = undef;
open(CC, "-|", $cc, @args) or die "$!";
my $macros = <CC>;
close(CC);
return $macros;
}
sub process($$$)
{
my ($inFile, $outFile, $arch) = @_;
if (!exists $ENV{SDKROOT} or !$ENV{SDKROOT}) {
die "SDKROOT environment variable not found";
}
chomp (my $cc = `xcrun -find cc`);
my @args = qw(-E -P);
push(@args, qw(-x c++));
push(@args, "-isysroot", $ENV{SDKROOT});
push(@args, "-arch", $arch);
my $macros = preprocessorMacros($cc, @args);
push(@args, "-o", $outFile);
push(@args, "-");
print join(" ", $cc, @args), "\n" if $verbose;
open(CC, "|-", $cc, @args) or die "$!";
open(IN, "<", $inFile) or die "$!";
print CC $macros;
while (my $line = <IN>) {
next if ($line =~ /^ print CC $line;
}
close(IN);
close(CC);
my $fileCount = chmod 0644, $outFile;
if ($fileCount != 1) {
die "Could not chmod 0644 $outFile: $!";
}
}