From d339b68befe7c4a3e8122e3e5b620f9487483bcc Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 8 Apr 2009 09:55:33 +0000 Subject: [PATCH] * Added UnzipArchive rule which unzips a zip file into a target directory. * Added DownloadOptionalPackage which is mainly a wrapper around DownloadFile preventing the package from being downloaded twice, even if invoked more than once. * InstallOptionalHaikuImagePackage uses DownloadOptionalPackage now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30020 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/FileRules | 78 ++++++++++++++++++++++++++++++++++++++++++++ build/jam/ImageRules | 4 +-- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/build/jam/FileRules b/build/jam/FileRules index c78e5d839d..e73123be3b 100644 --- a/build/jam/FileRules +++ b/build/jam/FileRules @@ -189,6 +189,66 @@ actions UnarchiveObjects } +rule UnzipArchive directory : entries : zipFile : grist +{ + # UnzipArchive : : [ : ] + # + # Unzips the zip file target to directory . The rule + # can be called multiple times for different for the same + # and combo. + # + # - The directory into which to unzip the zip file. The + # directory is created is by this rule and it is the target + # that the unzip action is associated with. + # - The entries of the zip file one is interested in. The rule + # always unzips the complete zip file, from the given entries + # the rule creates targets (using ) representing the + # unzipped entries. Those targets are returned by the rule. + # - The zip file target to unzip. + # - The grist used to create targets from . Defaults to + # "unzipped". + + grist ?= unzipped ; + + # Turn the entries into targets to build. + local targets ; + local entry ; + for entry in $(entries) { + local target = $(entry:G=$(grist)) ; + targets += $(target) ; + } + + LOCATE on $(targets) = $(directory) ; + Depends $(targets) : $(directory) ; + NoUpdate $(targets) ; + + # one-time initialization for the main target (the directory) + if ! [ on $(directory) return $(INITIALIZED) ] { + NoUpdate $(directory) ; + MakeLocate $(directory) : $(directory:P) ; + Depends $(directory) : $(zipFile) ; + UnzipArchive1 $(directory) : $(zipFile) ; + INITIALIZED on $(directory) = 1 ; + } + + # Use a dummy rule so that it looks to jam like the targets are actually + # built from the directory target. + UnzipArchiveDummy $(targets) : $(directory) ; + + return $(targets) ; +} + +actions UnzipArchive1 +{ + mkdir -p $(1[1]) + unzip -q -u -o -d $(1[1]) $(2) +} + +actions UnzipArchiveDummy +{ +} + + rule ObjectReference { # ObjectReference : @@ -299,3 +359,21 @@ actions DownloadFile1 { wget -O $(1) $(URL) } + +rule DownloadOptionalPackage package : url +{ + # download zip file + local zipFile = $(package:G=download).zip ; + + # Request the download only once. + if [ on $(zipFile) return $(HAIKU_OPTIONAL_PACKAGE_DOWNLOAD) ] { + return $(zipFile) ; + } + + HAIKU_OPTIONAL_PACKAGE_DOWNLOAD on $(zipFile) = 1 ; + + MakeLocate $(zipFile) : $(HAIKU_DOWNLOAD_DIR) ; + DownloadFile $(zipFile) : $(url) ; + + return $(zipFile) ; +} diff --git a/build/jam/ImageRules b/build/jam/ImageRules index e819093cfa..361149510a 100644 --- a/build/jam/ImageRules +++ b/build/jam/ImageRules @@ -731,9 +731,7 @@ rule OptionalPackageDependencies package : dependencies rule InstallOptionalHaikuImagePackage package : url : dirTokens { # download zip file - local zipFile = $(package:G=download).zip ; - MakeLocate $(zipFile) : $(HAIKU_DOWNLOAD_DIR) ; - DownloadFile $(zipFile) : $(url) ; + local zipFile = [ DownloadOptionalPackage $(package) : $(url) ] ; # unzip onto image UnzipArchiveToHaikuImage $(dirTokens) : $(zipFile) ;