From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Narebski Subject: [PATCH 02/24] gitweb: Prepare for splitting gitweb Date: Tue, 7 Dec 2010 00:10:47 +0100 Message-ID: <1291677069-6559-3-git-send-email-jnareb@gmail.com> References: <1291677069-6559-1-git-send-email-jnareb@gmail.com> Cc: John 'Warthog9' Hawley , John 'Warthog9' Hawley , Junio C Hamano , demerphq , Aevar Arnfjord Bjarmason , Thomas Adam , Jakub Narebski To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Dec 07 00:17:13 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PPkIy-0002Cx-GO for gcvg-git-2@lo.gmane.org; Tue, 07 Dec 2010 00:17:13 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752930Ab0LFXRG (ORCPT ); Mon, 6 Dec 2010 18:17:06 -0500 Received: from mail-ey0-f171.google.com ([209.85.215.171]:37279 "EHLO mail-ey0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752625Ab0LFXRF (ORCPT ); Mon, 6 Dec 2010 18:17:05 -0500 X-Greylist: delayed 323 seconds by postgrey-1.27 at vger.kernel.org; Mon, 06 Dec 2010 18:17:05 EST Received: by eyg5 with SMTP id 5so8018462eyg.2 for ; Mon, 06 Dec 2010 15:17:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=+Gg2MCYnLLIMXiOWD0DQrlGUilDLYCp804LTLE1nIBY=; b=eG6g/FerEppV+jwYFnGupKZ2K6v6DkCT4FsvWnsk2rea2pDsWEY8Xv2Yqp0apPA2Qd zSg4dHj5s6JTPTavR3Saz4uquSY3lthwWjjeAFNKxdWqnu4gjn7i/eKm1K/++qwcmYYJ 8adclPvFGlPS6OCCUDPHxh+J6oSeLtIg0MCYA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=WJYnvvbtwcPCnK0da+WXa7j8AdVOp3/BVmnVfyQQk5SDBOZ2Uka5f11HfYQ2UM1/oF 4sS1HDtNs2JgRTwaJMYjwqJstojam0TSAAtesaOAoBaPo+KVtss13UOfSmkYipSPxMHS JrM5q29Bp+0MM4nhmsLezjrKyXSC7I3qh4X1Q= Received: by 10.213.35.209 with SMTP id q17mr6599408ebd.56.1291677104174; Mon, 06 Dec 2010 15:11:44 -0800 (PST) Received: from localhost.localdomain (abwg200.neoplus.adsl.tpnet.pl [83.8.230.200]) by mx.google.com with ESMTPS id y5sm5190626eeh.22.2010.12.06.15.11.41 (version=SSLv3 cipher=RC4-MD5); Mon, 06 Dec 2010 15:11:42 -0800 (PST) X-Mailer: git-send-email 1.7.3 In-Reply-To: <1291677069-6559-1-git-send-email-jnareb@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Prepare gitweb for having been split into modules that are to be installed alongside gitweb in 'lib/' subdirectory, by adding use lib __DIR__.'/lib'; to gitweb.perl (to main gitweb script), and preparing for putting modules (relative path) in $(GITWEB_MODULES) in gitweb/Makefile. This preparatory work allows to add new module to gitweb by simply adding GITWEB_MODULES += to gitweb/Makefile (assuming that the module is in 'gitweb/lib/' directory). While at it pass GITWEBLIBDIR in addition to GITWEB_TEST_INSTALLED to allow testing installed version of gitweb and installed version of modules (for future tests which would check individual (sub)modules). Using __DIR__ from Dir::Self module (not in core, that's why currently gitweb includes excerpt of code from Dir::Self defining __DIR__) was chosen over using FindBin-based solution (in core since perl 5.00307, while gitweb itself requires at least perl 5.8.0) because FindBin uses BEGIN block, which is a problem under mod_perl and other persistent Perl environments (thought there are workarounds). At Pavan Kumar Sankara suggestion gitweb/Makefile uses install [OPTION]... SOURCE... DIRECTORY format (2nd format) with single SOURCE rather than install [OPTION]... SOURCE DEST format (1st format) because of security reasons (race conditions). Modern GNU install has `-T' / `--no-target-directory' option, but we cannot rely that the $(INSTALL) we are using supports this option. The install-modules target in gitweb/Makefile uses shell 'for' loop, instead of make's $(foreach) function, to avoid possible problem with generating a command line that exceeded the maximum argument list length. Signed-off-by: Jakub Narebski --- In previous version there was a BUG: shell variables should not be in single quotes. This is fixed version, the same as in [PATCHv7.4 0/4] Gitweb caching v7.4 Message-ID: <1291404335-25541-1-git-send-email-jnareb@gmail.com> http://thread.gmane.org/gmane.comp.version-control.git/162830 series, which are a bit fixed up and a tiny bit cleaned up version of "Gitweb caching v7" series from John 'Warthog9' Hawley: http://thread.gmane.org/gmane.comp.version-control.git/160147 Sidenote: this patch can serve as a way to introduce infrastructure required for splitting gitweb into modules for better maintability. This issue was to be first part (first milestone) for "Integrated web client for git" GSoC2010 project by Pavan Kumar Sankara (with Christian Couder as mentor, and Petr 'Pasky' Baudis as co-mentor)... which unfortunately failed middterm evaluations. As you can see later in series it makes it very easy to add new gitweb modules which are to be installed. Just add GITWEB_MODULES += Module/Foo.pm to gitweb/Makefile for Module::Foo (present in gitweb/lib/Module/Foo.pm) and 'install-gitweb' target would automatically install it along with gitweb. gitweb/Makefile | 17 +++++++++++++++-- gitweb/gitweb.perl | 8 ++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gitweb/Makefile b/gitweb/Makefile index 0a6ac00..e6029e1 100644 --- a/gitweb/Makefile +++ b/gitweb/Makefile @@ -57,6 +57,7 @@ PERL_PATH ?= /usr/bin/perl bindir_SQ = $(subst ','\'',$(bindir))#' gitwebdir_SQ = $(subst ','\'',$(gitwebdir))#' gitwebstaticdir_SQ = $(subst ','\'',$(gitwebdir)/static)#' +gitweblibdir_SQ = $(subst ','\'',$(gitwebdir)/lib)#' SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))#' PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))#' DESTDIR_SQ = $(subst ','\'',$(DESTDIR))#' @@ -153,20 +154,32 @@ test: test-installed: GITWEB_TEST_INSTALLED='$(DESTDIR_SQ)$(gitwebdir_SQ)' \ + GITWEBLIBDIR='$(DESTDIR_SQ)$(gitweblibdir_SQ)' \ $(MAKE) -C ../t gitweb-test ### Installation rules -install: all +install: all install-modules $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebdir_SQ)' $(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)' $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)' $(INSTALL) -m 644 $(GITWEB_FILES) '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)' +install-modules: + install_dirs="$(sort $(dir $(GITWEB_MODULES)))" && \ + for dir in $$install_dirs; do \ + test -d '$(DESTDIR_SQ)$(gitweblibdir_SQ)'/"$$dir" || \ + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitweblibdir_SQ)'/"$$dir"; \ + done + gitweb_modules="$(GITWEB_MODULES)" && \ + for mod in $$gitweb_modules; do \ + $(INSTALL) -m 644 "lib/$$mod" '$(DESTDIR_SQ)$(gitweblibdir_SQ)'/"$$(dirname $$mod)"; \ + done + ### Cleaning rules clean: $(RM) gitweb.cgi static/gitweb.min.js static/gitweb.min.css GITWEB-BUILD-OPTIONS -.PHONY: all clean install test test-installed .FORCE-GIT-VERSION-FILE FORCE +.PHONY: all clean install install-modules test test-installed .FORCE-GIT-VERSION-FILE FORCE diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 679f2da..cfa511c 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -10,6 +10,14 @@ use 5.008; use strict; use warnings; + +use File::Spec; +# __DIR__ is taken from Dir::Self __DIR__ fragment +sub __DIR__ () { + File::Spec->rel2abs(join '', (File::Spec->splitpath(__FILE__))[0, 1]); +} +use lib __DIR__ . '/lib'; + use CGI qw(:standard :escapeHTML -nosticky); use CGI::Util qw(unescape); use CGI::Carp qw(fatalsToBrowser set_message); -- 1.7.3