1#!/usr/bin/perl -w 2 3# Copyright (C) 2014 Apple Inc. All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 3. Neither the name of Apple puter, Inc. ("Apple") nor the names of 15# its contributors may be used to endorse or promote products derived 16# from this software without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29use strict; 30use Cwd; 31use File::Path qw(make_path); 32use File::Spec; 33 34my $PWD = Cwd::cwd(); 35my $XSRCROOT = Cwd::realpath(File::Spec->updir); 36$ENV{'XSRCROOT'} = $XSRCROOT; 37$ENV{'SRCROOT'} = $XSRCROOT; 38 39# Make sure we don't have any leading or trailing quotes 40$ARGV[0] =~ s/^\"//; 41$ARGV[0] =~ s/\"$//; 42 43my $XDSTROOT = Cwd::realpath($ARGV[0]); 44$ENV{'XDSTROOT'} = $XDSTROOT; 45 46my $TARGET_BUILD_DIR = File::Spec->catdir($XDSTROOT, "bin$ARGV[3]", 'WebKit.resources'); 47$ENV{'TARGET_BUILD_DIR'} = $TARGET_BUILD_DIR; 48my ($JAVASCRIPTCORE_PRIVATE_HEADERS_DIR, $WEBCORE_PRIVATE_HEADERS_DIR); 49if ($ARGV[4] eq '1') { 50 $ARGV[1] =~ s/^\"//; 51 $ARGV[1] =~ s/\"$//; 52 my $Internal = Cwd::realpath($ARGV[1]);; 53 $JAVASCRIPTCORE_PRIVATE_HEADERS_DIR = File::Spec->catdir($Internal, 'include', 'private', 'JavaScriptCore'); 54 $WEBCORE_PRIVATE_HEADERS_DIR = File::Spec->catdir($Internal, 'include', 'private', 'WebCore'); 55} else { 56 $JAVASCRIPTCORE_PRIVATE_HEADERS_DIR = File::Spec->catdir($XDSTROOT, "obj$ARGV[3]", 'JavaScriptCore', 'DerivedSources'); 57 $WEBCORE_PRIVATE_HEADERS_DIR = File::Spec->catdir($XDSTROOT, "obj$ARGV[3]", 'WebCore', 'DerivedSources'); 58} 59 60$ENV{'JAVASCRIPTCORE_PRIVATE_HEADERS_DIR'} = $JAVASCRIPTCORE_PRIVATE_HEADERS_DIR; 61$ENV{'WEBCORE_PRIVATE_HEADERS_DIR'} = $WEBCORE_PRIVATE_HEADERS_DIR; 62 63my $DERIVED_SOURCES_DIR = File::Spec->catdir($XDSTROOT, "obj$ARGV[3]", 'WebInspectorUI', 'DerivedSources'); 64$ENV{'DERIVED_SOURCES_DIR'} = $DERIVED_SOURCES_DIR; 65 66$ENV{'UNLOCALIZED_RESOURCES_FOLDER_PATH'} = 'WebInspectorUI'; 67 68if (($TARGET_BUILD_DIR =~ /Release/) || ($TARGET_BUILD_DIR =~ /Production/)) { 69 $ENV{'COMBINE_INSPECTOR_RESOURCES'} = 'YES'; 70} 71 72my $targetResourcePath = File::Spec->catdir($ENV{'TARGET_BUILD_DIR'}, $ENV{'UNLOCALIZED_RESOURCES_FOLDER_PATH'}); 73my $protocolDir = File::Spec->catdir($targetResourcePath, 'Protocol'); 74 75# Copy over dynamically loaded files from other frameworks, even if we aren't combining resources. 76my $jsFrom = File::Spec->catfile($ENV{'JAVASCRIPTCORE_PRIVATE_HEADERS_DIR'}, 'InspectorJSBackendCommands.js'); 77my $jsTo = File::Spec->catfile($protocolDir, 'InspectorJSBackendCommands.js'); 78print "Copying JavaScript bindings from $jsFrom to $jsTo\n"; 79 80my $wcFrom = File::Spec->catfile($ENV{'WEBCORE_PRIVATE_HEADERS_DIR'}, 'InspectorWebBackendCommands.js'); 81my $wcTo = File::Spec->catfile($protocolDir, 'InspectorWebBackendCommands.js'); 82print "Copying WebCore bindings from $wcFrom to $wcTo\n"; 83 84my $copyResourcesCommand = File::Spec->catfile($XSRCROOT, 'Scripts', 'copy-user-interface-resources.pl'); 85do $copyResourcesCommand; 86