#!/usr/bin/perl -w

# Copyright (C) 2005, 2006, 2007 Apple Computer, Inc.  All rights reserved.
# Copyright (C) 2011 Carl Lobo.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1.  Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer. 
# 2.  Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution. 
# 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
#     its contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission. 
#
# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Updates a development environment to the new WebKitAuxiliaryLibrary

use strict;
use warnings;

use File::Find;
use File::Spec;
use File::Temp ();
use FindBin;
use HTTP::Date qw(str2time);
use POSIX;
use lib $FindBin::Bin;
use webkitdirs;

if ($#ARGV != 1) {
    die <<EOF;
Usage:
        update-webkit-dependancy <URL with the dependancy zip file> <*prefix dir inside zip without filename>

        * If filename is requirements.zip and the contents of the zipfile are "requirements/x" then prefix = "."
        * If filename is xyz.zip and the contents of the zipfile are xyz/abc/x" then prefix = "abc"
        * x is lib or include or bin.
EOF
}

sub lastModifiedToUnixTime($);
sub getLibraryName($);

# Time in seconds that the new zip file must be newer than the old for us to
# consider them to be different. If the difference in modification time is less
# than this threshold, we assume that the files are the same. We need this
# because the zip file is served from a set of mirrors with slightly different
# Last-Modified times.
my $newnessThreshold = 30;

my $libsURL = shift;
my $prefixInZip = shift;
my $sourceDir = sourceDir();
my $file = getLibraryName($libsURL);
my $zipFile = "$file.zip"; 
my $webkitLibrariesDir = toUnixPath($ENV{'WEBKITLIBRARIESDIR'}) || "$sourceDir/WebKitLibraries/win";
my $tmpRelativeDir = File::Temp::tempdir("webkitlibsXXXXXXX", TMPDIR => 1, CLEANUP => 1);
my $tmpAbsDir = File::Spec->rel2abs($tmpRelativeDir);

print "Checking Last-Modified date of $zipFile...\n";

my $result = system "curl -s -I $libsURL | grep Last-Modified > \"$tmpAbsDir/$file.headers\"";

if (WEXITSTATUS($result)) {
    print STDERR "Couldn't check Last-Modified date of new $zipFile.\n";
    print STDERR "Please ensure that $libsURL is reachable.\n";

    if (! -f "$webkitLibrariesDir/$file.headers") {
        print STDERR "Unable to check Last-Modified date and no version of $file to fall back to.\n";
        exit 1;
    }

    print STDERR "Falling back to existing version of $file.\n";
    exit 0;
}

if (open NEW, "$tmpAbsDir/$file.headers") {
    my $new = lastModifiedToUnixTime(<NEW>);
    close NEW;

    if (defined $new && open OLD, "$webkitLibrariesDir/$file.headers") {
        my $old = lastModifiedToUnixTime(<OLD>);
        close OLD;
        if (defined $old && abs($new - $old) < $newnessThreshold) {
            print "Current $file is up to date\n";
            exit 0;
        }
    }
}

print "Downloading $zipFile...\n\n";
$result = system "curl -o \"$tmpAbsDir/$zipFile\" $libsURL";
die "Couldn't download $zipFile!" if $result;

$result = system "unzip", "-q", "-d", $tmpAbsDir, "$tmpAbsDir/$zipFile";
die "Couldn't unzip $zipFile." if $result;

print "\nInstalling $file...\n";

sub wanted
{
    my $relativeName = File::Spec->abs2rel($File::Find::name, "$tmpAbsDir/$file/$prefixInZip");
    my $destination = "$webkitLibrariesDir/$relativeName";

    if (-d $_) {
        mkdir $destination;
        return;
    }

    system "cp", $_, $destination;
}

File::Find::find(\&wanted, "$tmpAbsDir/$file");

$result = system "mv", "$tmpAbsDir/$file.headers", $webkitLibrariesDir;
print STDERR "Couldn't move $file.headers to $webkitLibrariesDir" . ".\n" if $result;

print "The $file has been sucessfully installed in\n $webkitLibrariesDir\n";
exit;

sub toUnixPath
{
    my $path = shift;
    return unless $path;
    chomp($path = `cygpath -u '$path'`);
    return $path;
}

sub lastModifiedToUnixTime($)
{
    my ($str) = @_;

    $str =~ /^Last-Modified: (.*)$/ or return;
    return str2time($1);
}

sub getLibraryName($)
{
    my $url = shift;
    $url =~ m#/([^/]+)\.zip$#;
    return $1;
}

