SF.net SVN: gar:[25542] csw/mgar/gar/v2

cgrzemba at users.sourceforge.net cgrzemba at users.sourceforge.net
Thu Feb 4 12:01:43 CET 2016


Revision: 25542
          http://sourceforge.net/p/gar/code/25542
Author:   cgrzemba
Date:     2016-02-04 11:01:43 +0000 (Thu, 04 Feb 2016)
Log Message:
-----------
add IPS package build and some basic package checks

Modified Paths:
--------------
    csw/mgar/gar/v2/gar.mk
    csw/mgar/gar/v2/gar.pkg.mk
    csw/mgar/gar/v2/lib/python/makeStdLibDb.py
    csw/mgar/gar/v2/lib/python/rest.py

Added Paths:
-----------
    csw/mgar/gar/v2/bin/pathfilter.py
    csw/mgar/gar/v2/bin/pkg_resolve
    csw/mgar/gar/v2/lib/python/pkg_resolve.py
    csw/mgar/gar/v2/transforms/
    csw/mgar/gar/v2/transforms/README
    csw/mgar/gar/v2/transforms/defaults
    csw/mgar/gar/v2/transforms/unneeded-deps

Property Changed:
----------------
    csw/mgar/gar/v2/
    csw/mgar/gar/v2/lib/
    csw/mgar/gar/v2/lib/python/

Index: csw/mgar/gar/v2
===================================================================
--- csw/mgar/gar/v2	2016-02-03 05:40:38 UTC (rev 25541)
+++ csw/mgar/gar/v2	2016-02-04 11:01:43 UTC (rev 25542)

Property changes on: csw/mgar/gar/v2
___________________________________________________________________
Added: svn:ignore
## -0,0 +1 ##
+gar.pkg.mk.patch
Added: csw/mgar/gar/v2/bin/pathfilter.py
===================================================================
--- csw/mgar/gar/v2/bin/pathfilter.py	                        (rev 0)
+++ csw/mgar/gar/v2/bin/pathfilter.py	2016-02-04 11:01:43 UTC (rev 25542)
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+import logging
+import argparse
+import os
+import sys
+import re
+
+sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+from lib.python import common_constants
+from lib.python import configuration
+
+USAGE = '''%prog [-i path][-x path][-I path][-X path]
+
+ pathfilter will read a prototype(4) file from stdin, filter
+ it as specified by the include/exclude options and writes
+ the result to stdout.  If no include/exclude options are
+ given the input is copied verbatim to stdout.
+
+ Empty directories are implicitly excluded by default.
+'''
+
+
+def main():
+    parser = argparse.ArgumentParser(USAGE)
+    parser.add_argument("-x", dest="exclude_meta", nargs="*", action='append',
+                    help='''Excludes the path from the resulting prototype where
+    all meta characters are quoted.''')
+    parser.add_argument("-X", "--exclude", dest="exclude", nargs="*", action='append',
+                    help='''Excludes the path from the resulting prototype''')
+    parser.add_argument("-i", dest="include_meta", nargs="*", action='append',
+                    help='''Includes the path in the resulting prototype where 
+    all meta characters are quoted.  All pathes are
+    implicitly excluded by default if -i is used.''')
+    parser.add_argument("-I", "--include", dest="include", nargs="*", action='append',
+                    help='''Includes the path in the resulting prototype. All pathes are
+    implicitly excluded by default if -i is used.''')
+    parser.add_argument("-f", "--file", dest="infile", 
+      help='''prototype file''')
+    parser.add_argument("--debug", dest="debug", action="store_true")
+    options = parser.parse_args()
+    logging_level = logging.INFO
+    if options.debug:
+        logging_level = logging.DEBUG
+    fmt = '%(levelname)s %(asctime)s %(filename)s:%(lineno)d %(message)s'
+    logging.basicConfig(format=fmt, level=logging_level)
+    if not options.infile:
+        inf = sys.stdin
+    else: 
+        inf = open(options.infile)
+    # paths = {}
+    # paths = dict( re.match(".*path=([^\s]*).*",line).groups()[0],[line,False] for line in inf.readlines() )
+    for line in inf.readlines():
+        printed = False
+        line = line.strip()
+        path = re.match(".*path=([^\s]*).*",line).groups()[0]
+        # import pdb; pdb.set_trace()
+        if options.include:
+            for inc in options.include:
+                if re.match(inc[0].lstrip('/'), path):
+                    print line
+                    printed = True
+                    break
+        if not printed and options.include_meta:
+            for inc_pattern in options.include_meta:
+                if re.match("^"+inc_pattern[0].lstrip('/')+"$", path):
+                    print line
+                    printed = True
+                    break
+        if not printed:
+            notprint = False
+            for excl_pattern in options.exclude_meta:
+                if re.match("^"+excl_pattern[0].lstrip('/')+"$", path):
+                    notprint = True
+            if not notprint:
+                for excl_pattern in options.exclude:
+                    if re.match("^"+excl_pattern[0].lstrip('/')+"$", path):
+                        notprint = True
+            if not notprint:
+                print line
+    if not inf is sys.stdin:
+        inf.close()
+                  
+  # import pdb; pdb.set_trace()
+
+if __name__ == '__main__':
+  main()

Added: csw/mgar/gar/v2/bin/pkg_resolve
===================================================================
--- csw/mgar/gar/v2/bin/pkg_resolve	                        (rev 0)
+++ csw/mgar/gar/v2/bin/pkg_resolve	2016-02-04 11:01:43 UTC (rev 25542)
@@ -0,0 +1,8 @@
+#!/opt/csw/bin/bash
+
+set -e
+set -u
+
+basedir=$(dirname $0)/..
+export PYTHONPATH=$basedir
+exec /opt/csw/bin/python2.6 "$basedir/lib/python/pkg_resolve.py" "$@"


Property changes on: csw/mgar/gar/v2/bin/pkg_resolve
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Modified: csw/mgar/gar/v2/gar.mk
===================================================================
--- csw/mgar/gar/v2/gar.mk	2016-02-03 05:40:38 UTC (rev 25541)
+++ csw/mgar/gar/v2/gar.mk	2016-02-04 11:01:43 UTC (rev 25542)
@@ -853,7 +853,8 @@
 # $(libdir) has the memorymodel-directory appended, whereas $(libdir_install)
 # has not, so we use this one for appending.
 
-
+# Make sure the configuration files always have a .CSW suffix and rename the
+# configuration files to this if necessary during merge.
 _PAX_ARGS = $(_INC_EXT_RULE) $(_EXTRA_PAX_ARGS) $(call modulationvalue,EXTRA_PAX_ARGS) $(EXTRA_PAX_ARGS)
 
 define killprocandparent

Modified: csw/mgar/gar/v2/gar.pkg.mk
===================================================================
--- csw/mgar/gar/v2/gar.pkg.mk	2016-02-03 05:40:38 UTC (rev 25541)
+++ csw/mgar/gar/v2/gar.pkg.mk	2016-02-04 11:01:43 UTC (rev 25542)
@@ -13,6 +13,11 @@
 #
 #
 
+# use opencsw pakckage db for resolve dependencies for IPS packages
+IPS_USE_PKG_DB =
+# prepend this to the package name
+IPS_PACKAGE_PREFIX ?= opencsw/
+
 ifeq ($(DEBUG_PACKAGING),)
 _DBG=@
 DEBUG_FLAG =
@@ -103,7 +108,9 @@
 _PKG_SPECS      = $(filter-out $(NOPACKAGE),$(SPKG_SPECS))
 $(if $(_PKG_SPECS),,$(error No packages for building defined))
 
-_PKG_SPECS_IPS = $(filter-out $(NOPACKAGE),$(or $(PACKAGES_IPS),$(NAME)))
+# dev and doc represented as facet in IPS
+NOPACKAGE_IPS = %-dev %-doc
+_PKG_SPECS_IPS = $(filter-out $(NOPACKAGE) $(NOPACKAGE_IPS),$(or $(PACKAGES_IPS),$(patsubst CSW%,%,$(SPKG_SPECS)),$(NAME)))
 
 # The is the name of the package containing the sourcefiles for all packages generated from this GAR recipe.
 # It defaults to the first defined package name or gspec. SRCPACKAGE_BASE is guaranteed
@@ -328,9 +335,17 @@
 _CSWCLASSES += cswtexhash
 _CSWCLASSES += cswdictconf
 
+PKGFORMAT-5.8 = svr4
+PKGFORMAT-5.9 = svr4
+PKGFORMAT-5.10 = svr4
+PKGFORMAT-5.11 = ips
+PKGFORMAT := $(PKGFORMAT-$(GAROSREL))
+
 # Make sure the configuration files always have a .CSW suffix and rename the
 # configuration files to this if necessary during merge.
+ifneq ($(GAROSREL),5.11)
 _EXTRA_PAX_ARGS += $(foreach FILE,$(SAMPLECONF:%\.CSW=%) $(PRESERVECONF:%\.CSW=%),-s ",^\.\($(FILE)\)$$,.\1\.CSW,p")
+endif
 
 PKGGET_DESTDIR ?=
 
@@ -397,6 +412,7 @@
 # Use PKGFILES_CSWlibfoo1 = $(call pkgfiles_lib,libfoo.so.1)
 pkgfiles_lib += $(call baseisadirs,$(libdir),$(subst .,\.,$(subst +,\+,$(1)))(\.\d+)*)
 
+IPS_PKGFILES_DEVEL := $(PKGFILES_DEVEL)
 # PKGFILES_DEVEL selects files belonging to a developer package
 PKGFILES_DEVEL_CONFIG ?= $(call baseisadirs,$(bindir),[^/]*-config)
 PKGFILES_DEVEL += $(PKGFILES_DEVEL_CONFIG)
@@ -984,16 +1000,31 @@
 			done)),)
 _buildpackage: pre-package $(PACKAGE_TARGETS) post-package $(if $(filter-out 0,$(ENABLE_CHECK)),pkgcheck)
 
-_buildpackage-ips: pre-package $(PACKAGE_TARGETS_IPS) post-package
+# _buildpackage-ips: pre-package $(PACKAGE_TARGETS_IPS) post-package $(if $(filter-out 0,$(ENABLE_CHECK)),pkgcheck)
+_buildpackage-ips: pre-package $(PACKAGE_TARGETS_IPS) post-package package-publish 
 
+# generates p5m from proto and publishs
+package-publish:
+	$(if $(IPS_USE_PKG_DB), \
+		$(foreach SPEC,$(_PKG_SPECS_IPS),\
+			$(GARBIN)/pkg_resolve $(DEBUG_FLAG) \
+			--arch "$(GARCH)" \
+			--os-release "$(SPKG_OSNAME)" \
+			--catalog-release "$(CATALOG_RELEASE)" \
+			--pkg-root "$(PKGROOT)" $(SPEC).proto > $(SPEC).p5p,  \
+			cp $@.proto $@.p5p))
+	$(if $(IPS_RM_SAME_VERS),\
+		$(foreach SPEC,$(_PKG_SPECS_IPS),\
+			pkgrepo remove -s  $(SPKG_EXPORT_IPS)  $(IPS_PACKAGE_PREFIX)$(SPEC)@$(IPS_VERSION) || true;))
+	$(_DBG)cd $(WORKDIR) && pkgdepend resolve -m $(foreach SPEC,$(_PKG_SPECS_IPS),$(SPEC).p5p )
+	$(foreach SPEC,$(_PKG_SPECS_IPS),\
+		( cd $(WORKDIR) && cp $(SPEC).p5p.res $(SPEC).p5m && \
+			pkglint -c /var/tmp/build_$(LOGNAME)/lint-cache -r $(SPKG_EXPORT_IPS) $(SPEC).p5m ); \
+		pkgsend publish -s $(SPKG_EXPORT_IPS) -d $(SPKG_PKGROOT) $(WORKDIR)/$(SPEC).p5m; )
+
 _package: validateplatform extract-global merge $(SPKG_DESTDIRS) _buildpackage
 	@$(MAKECOOKIE)
 
-PKGFORMAT-5.8 = svr4 
-PKGFORMAT-5.9 = svr4 
-PKGFORMAT-5.10 = svr4 
-PKGFORMAT-5.11 = ips 
-
 package: package-$(PKGFORMAT-$(GAROSREL)) 
 
 package-svr4: _package 
@@ -1053,28 +1084,83 @@
 # -- IPS Packaging --
 
 .PRECIOUS: $(WORKDIR)/%.proto
+$(WORKDIR)/%.proto: _PKGFILES_EXCLUDE=$(call _pkgfiles_exclude,CSW$*)
+$(WORKDIR)/%.proto: _PKGFILES_INCLUDE=$(call _pkgfiles_include,CSW$*)
 $(WORKDIR)/%.proto: $(WORKDIR)
-	$(_DBG)(cd $(PKGROOT) && pkgsend generate .) >$@
+	$(_DBG) @echo "PKG: $(IPS_PACKAGE_PREFIX)$*"
+	$(_DBG) pkgsend generate $(PKGROOT) >$@.gen
+	$(_DBG)if [ -n "$(PKGFILES_CSW$*_SHARED)" -o \
+	      -n "$(PKGFILES_CSW$*)" -o \
+	      -n "$(_PKGFILES_EXCLUDE)" -o \
+	      -n "$(ISAEXEC_FILES_CSW$*)" -o \
+	      -n "$(ISAEXEC_FILES)" ]; then \
+	  ($(GARBIN)/pathfilter.py $(if $(or $(_PKGFILES_EXCLUDE),$(_PKGFILES_INCLUDE)),\
+				-I $(call licensedir,CSW$*)/license \
+				-I /etc/opt/csw/pkg/CSW$*/cswmigrateconf \
+		      		-I /opt/csw/share/alternatives/$(call catalogname,CSW$*) \
+		      )\
+		      $(foreach S,$(filter-out CSW$*,$(SPKG_SPECS)),\
+				-X $(call licensedir,$S)/license \
+				-X /etc/opt/csw/pkg/$S/cswmigrateconf \
+				-X /opt/csw/share/alternatives/$(call catalogname,$S) \
+		      ) \
+		      $(foreach I,$(EXTRA_PKGFILES_INCLUDED) $(EXTRA_PKGFILES_INCLUDED_CSW$*),-i '$I') \
+		      $(foreach X,$(EXTRA_PKGFILES_EXCLUDED) $(EXTRA_PKGFILES_EXCLUDED_CSW$*),-x '$X') \
+		      $(foreach FILE,$(_PKGFILES_INCLUDE),-i '$(FILE)') \
+		      $(if $(_PKGFILES_INCLUDE),-x '.*',$(foreach FILE,$(_PKGFILES_EXCLUDE),-x '$(FILE)')) \
+	              $(foreach IE,$(abspath $(ISAEXEC_FILES_CSW$*) $(ISAEXEC_FILES)), \
+	                  -e '$(IE)=$(dir $(IE))$(ISA_DEFAULT)/$(notdir $(IE))' \
+	               ) \
+	          -f $@.gen; \
+	   if [ -n "$(EXTRA_PKGFILES_$*)" ]; then echo "$(EXTRA_PKGFILES_$*)"; fi \
+	  ) >$@.filtered; \
+	else \
+	  cp $@.gen $@.filtered; \
+	fi
+	$(if $(and $(INITSMF),$(filter $(shell cat $(WORKDIR)/$@.filtered),$(patsubst /%,%,$(INITSMF)))), \
+	    ginstall -d $(PKGROOT)/var/svc/manifest/site; \
+	    svcbundle -o $(PKGROOT)/var/svc/manifest/$(notdir $(INITSMF)).xml -s service-name=$(notdir $(INITSMF)) -s model=daemon -s start-method="$(INITSMF) start" -s stop-method="$(INITSMF) stop"; \
+	    echo "<transform pkg -> emit file owner=root group=sys mode=755 path=var/svc/manifest/site/$(notdir $(INITSMF)).xml>" >> $@.filtered; )
+	$(_DBG)$(foreach DFILE,$(IPS_PKGFILES_DEVEL), echo "<transform file path=$(patsubst /%,%,$(DFILE)) -> default facet.devel true>" >> $@.filtered; )
+	$(foreach BIT,$(IPS_BYPASS_GENERATE_DEP), echo "<transform file path=$(patsubst /%,%,$(BIT)) -> default pkg.depend.bypass-generate .*>" >> $@.filtered; )
+	$(foreach BIT,$(PKGFILES_CSW$*_SHARED), \
+		echo "<transform file path=$(patsubst /%,%,$(BIT)) -> default overlay allow>" >> $@.filtered; \
+		echo "<transform file path=$(patsubst /%,%,$(BIT)) -> default preserve legacy>" >> $@.filtered )
+	$(foreach PKG,$(filter-out $(_PKG_SPECS),$(RUNTIME_DEP_PKGS_CSW$*)), echo "<transform pkg -> emit depend fmri=pkg:/$(patsubst CSW%,%,$(PKG)) type=require>" >> $@.filtered; )
+	$(foreach CONF,$(PRESERVECONF), echo "<transform file path=$(patsubst /%,%,$(CONF)) -> default preserve renamenew>" >> $@.filtered; )
+	mv $@.filtered $@
 
+	 
+	
 IPS_META_CLASSIFICATION ?= Applications/Accessories
-IPS_META_SUMMARY ?= $(DESCRIPTION)
+IPS_META_SUMMARY ?= $(if $(SPKG_DESC_CSW$*),$(SPKG_DESC_CSW$*),$(DESCRIPTION))
 IPS_META_DESCRIPTION ?= $(DESCRIPTION)
+IPS_VERSION ?= $(VERSION)
 
 .PRECIOUS: $(WORKDIR)/%.meta
+$(WORKDIR)/%.meta: cswpkgname = CSW$(subst _,-,$*)
 $(WORKDIR)/%.meta: $(WORKDIR)
-	$(_DBG)(echo "set name=pkg.fmri value=$*@$(VERSION)"; \
+	$(if $(filter %/,$(IPS_PACKAGE_PREFIX)),,$(error IPS_PACKAGE_PREFIX must ending in a / wheres this did not: $(IPS_PACKAGE_PREFIX)))
+	$(_DBG)(echo "set name=pkg.fmri value=$(IPS_PACKAGE_PREFIX)$*@$(IPS_VERSION)"; \
 	echo "set name=pkg.summary value=\"$(IPS_META_SUMMARY)\""; \
 	echo "set name=pkg.description value=\"$(IPS_META_DESCRIPTION)\""; \
-	echo "set name=variant.arch value=$(GARCH)"; \
 	echo "set name=info.classification value=org.opensolaris.category.2008:$(IPS_META_CLASSIFICATION)"; \
-	$(_CATEGORY_IPS_META) \
+	echo "<transform pkg -> emit legacy arch=$(GARCH) category=\"$(if $(CATEGORY),$(CATEGORY),application)\" desc=\"$(SPKG_DESC_$(cswpkgname))\" name=\"$(cswpkgname)\" pkg=$(cswpkgname) variant.arch=$(GARCH) vendor=\"$(call pkgvar,SPKG_VENDOR,$(cswpkgname))\" version=$(call pkgvar,SPKG_VERSION,$(cswpkgname)),$(call pkgvar,SPKG_REVSTAMP,$(cswpkgname)) hotline=\"http://www.opencsw.org/bugtrack/\">"; \
+	echo "<transform pkg -> emit license $(call licensedir,CSW$(subst _,-,$*))/license license=\"see license file\">"; \
+	$(_CATEGORY_IPS_META) ; \
 	) >$@
-
+	$(if $(or $(ARCHALL_$(cswpkgname)),$(ARCHALL)), echo "set name=variant.arch value=sparc value=i386", echo "set name=variant.arch value=$(GARCH)")  >> $@; 
+	$(if $(findstring $(cswpkgname)/,$(USERGROUP)), (cat $(WORKDIR)/cswusergroup | while read line; do \
+	      echo $$line | awk -F':' '{ print "group groupname="$$2; }'; \
+	      echo $$line | awk -F':' '{ print "user username="$$1" group="$$2" gecos-filed=\""$$3"\" home-dir="$$4" login-shell="$$5; }'; \
+	    done ) >> $@ )
+	
+  
 packageips-%: $(WORKDIR)/%.proto $(WORKDIR)/%.meta $(SPKG_EXPORT_IPS)
-	cd $(WORKDIR) && pkgmogrify $*.proto $*.meta > $*.p5m
-	cd $(WORKDIR) && pkglint $*.p5m
-	pkgsend publish -s $(SPKG_EXPORT_IPS) -d $(SPKG_PKGROOT) $(WORKDIR)/$*.p5m
-
+	cd $(WORKDIR) && cat $*.meta $*.proto  > $*.premog
+	pkgmogrify  -I $(GARDIR)transforms -I $(WORKDIR) $*.premog defaults | pkgfmt > $(WORKDIR)/$*.mogrified
+	pkgdepend generate $(foreach I,$(shell isainfo),-D ISALIST=$I) -md $(PKGROOT) $(WORKDIR)/$*.mogrified > $(WORKDIR)/$*.depend
+	pkgmogrify  -I $(GARDIR)transforms -I $(WORKDIR) $*.depend unneeded-deps | pkgfmt > $(WORKDIR)/$*.p5p
 # ---
 
 # pkgcheck - check if the package is compliant
@@ -1106,6 +1192,7 @@
 	$(_DBG)rm -rf $(foreach T,extract checksum package package-ips pkgcheck,$(COOKIEDIR)/*$(T)-$**)
 	$(_DBG)rm -rf $(COOKIEDIR)/pre-package $(COOKIEDIR)/post-package
 	$(_DBG)rm -rf $(addprefix $(WORKDIR)/,$(filter-out $(DISTFILES),$(patsubst $(WORKDIR)/%,%,$(wildcard $(WORKDIR)/$*.*)) prototype copyright $*.copyright))
+	$(_DBG)rm -rf $(WORKDIR)/$(patsubst CSW%,%,$*).*
 
 repackage: pkgreset package
 

Index: csw/mgar/gar/v2/lib
===================================================================
--- csw/mgar/gar/v2/lib	2016-02-03 05:40:38 UTC (rev 25541)
+++ csw/mgar/gar/v2/lib	2016-02-04 11:01:43 UTC (rev 25542)

Property changes on: csw/mgar/gar/v2/lib
___________________________________________________________________
Added: svn:ignore
## -0,0 +1 ##
+map.solaris10-0
Index: csw/mgar/gar/v2/lib/python
===================================================================
--- csw/mgar/gar/v2/lib/python	2016-02-03 05:40:38 UTC (rev 25541)
+++ csw/mgar/gar/v2/lib/python	2016-02-04 11:01:43 UTC (rev 25542)

Property changes on: csw/mgar/gar/v2/lib/python
___________________________________________________________________
Modified: svn:ignore
## -1 +1 ##
-stdlib.json
+stdlibs.json
Modified: csw/mgar/gar/v2/lib/python/makeStdLibDb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/makeStdLibDb.py	2016-02-03 05:40:38 UTC (rev 25541)
+++ csw/mgar/gar/v2/lib/python/makeStdLibDb.py	2016-02-04 11:01:43 UTC (rev 25542)
@@ -10,24 +10,25 @@
 import cjson
 
 fnLiblst = "stdlibs.json"
+# list of OS libs for which we do not take into account the dependencies
+liblst = ['libjawt.so']
 
 def buildStdlibList():
-  liblst = ['libjawt.so']
-  cwd_save = os.getcwd()
-  std_locations = (
+    cwd_save = os.getcwd()
+    std_locations = (
       '/usr/lib',
       '/usr/dt/lib',
       '/usr/openwin/lib',
       '/usr/X11/lib',
       '/usr/ucblib',
       '/usr/sfw/lib',
-  )
-  for libdir in std_locations:
-    os.chdir(libdir)
-    for lib in os.listdir('.'):
-      if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
-        liblst.append(lib)
-  os.chdir(cwd_save)
-  with open(fnLiblst, 'w') as fd:
-    fd.write(cjson.encode(liblst))
-    fd.close()
+    )
+    for libdir in std_locations:
+        if os.path.isdir(libdir):
+            os.chdir(libdir)
+            for lib in os.listdir('.'):
+                if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
+                    liblst.append(lib)
+    os.chdir(cwd_save)
+    with open(fnLiblst, 'w') as fd:
+        fd.write(cjson.encode(liblst))

Added: csw/mgar/gar/v2/lib/python/pkg_resolve.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkg_resolve.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/pkg_resolve.py	2016-02-04 11:01:43 UTC (rev 25542)
@@ -0,0 +1,174 @@
+#!/usr/bin/env python2.6 -t
+
+"""
+gets all depended catalog names
+usage: get_dependencies <md5_sum>
+
+search rest: r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/catalognames/([^/]+)/', 'Srv4ByCatAndCatalogname',
+pkgdepend genertate creates entries like:
+depend fmri=__TBD 
+ pkg.debug.depend.file=libpcre.so.1 
+ pkg.debug.depend.path=lib 
+ pkg.debug.depend.path=opt/csw/lib 
+ pkg.debug.depend.path=opt/csw/lib 
+ pkg.debug.depend.path=opt/csw/lib/amd64 
+ pkg.debug.depend.path=opt/csw/lib/i386 
+ pkg.debug.depend.path=usr/lib 
+ pkg.debug.depend.reason=opt/csw/bin/swig 
+ pkg.debug.depend.type=elf 
+ type=require
+"""
+
+from __future__ import print_function
+
+import optparse
+import rest
+import common_constants
+import pprint
+import gdbm
+import logging
+import sys
+import os
+import cjson
+from lib.python.shell import ShellCommand
+import makeStdLibDb
+import platform
+import re
+from lib.python import configuration
+from lib.python import representations
+
+from Cheetah.Template import Template
+
+fn_stdlibs = 'work/stdlibs.json'
+fn_pkgstats = 'work/pkgstats'
+LDD_CMD = '/usr/bin/ldd'
+
+FileRE = '.*pkg.debug.depend.file=([^\s]*)\s.*'
+PathRE = 'pkg.debug.depend.path=([^\s]*)'
+ReasonRE = '.*pkg.debug.depend.reason=([^\s]*)\s.*'
+
+# strict
+# depend_tmpl = 'depend fmri=pkg://opencsw/$catalogname@$version,$rel-$revision type=require'
+# lazzy
+depend_tmpl = 'depend fmri=pkg:/opencsw/$catalogname@$version type=require'
+manifest_tmpl = '''
+set name=pkg.fmri value=pkg:/opencsw/$category/$catalogname@$version,$osrel-$revision:$pstamp
+set name=pkg.summary value="$summary"
+set name=pkg.human-version value=$version
+set name=publisher value=$email
+'''
+
+catrel = 'unstable'
+arch = platform.processor()
+osrel = platform.system()+platform.release()
+pkgroot = '../pkgroot'
+
+def char2dotvers(version):
+     newversion = ''
+     converted = False
+     for c in version:
+        try: 
+	    n = int(c)
+            if converted: newversion +='.'; converted = False
+            newversion += c
+	except ValueError:
+            if c == '.':
+                newversion += c
+            else:
+                newversion += ".%d" % (ord(c.upper())-0x40)
+                converted = True
+     return newversion
+
+class GetPackage(object):
+    def __init__(self):
+        self.cached_catalogs_bins = {}
+        self.cached_catalogs_links = {}
+        self.cached_catalogs_needed_bins = {}
+        config = configuration.GetConfig()
+        username, password = rest.GetUsernameAndPassword()
+        self.rest_client = rest.RestClient(
+          pkgdb_url=config.get('rest', 'pkgdb'),
+          releases_url=config.get('rest', 'releases'),
+          username=username,
+          password=password)
+        self.cp = rest.CachedPkgstats(fn_pkgstats, self.rest_client)
+        
+
+    def resolveDeps(self, p5m):
+        def getResolvedPath(bin, lib):
+            ret_code, cstdout, cstderr = ShellCommand([LDD_CMD,os.path.join(pkgroot,bin)])
+            for line in cstdout.split('\n'):
+                if lib in line:
+                    return os.path.dirname(line.split('=>')[1]).strip()
+        with open( p5m ) as pf:
+            for line in pf.readlines():
+                line = line.strip()
+                if line.startswith('depend fmri=__TBD') and'pkg.debug.depend.type=elf' in line:
+                    basename = re.match(FileRE, line).group(1)
+                    reason = re.match(ReasonRE, line).group(1)
+                    # these path are useless because its sorted alphabetically
+                    paths = re.findall(PathRE, line)
+                    # thats why we get the used path
+                    deppath = getResolvedPath(reason, basename)
+                    logging.debug("getPathsAndCatnames:  %s %s %s %s" % (catrel,arch,osrel,basename))
+                    pkg = self.rest_client.GetPathsAndCatnamesByBasename(catrel, arch, osrel, basename)
+                    if deppath:
+                    	if not deppath in pkg.keys():
+                    		if os.path.islink(deppath):
+                    			deppath = os.path.realpath(deppath)
+                        catalogname = pkg[deppath][0][0]
+                        # import pdb; pdb.set_trace()
+                        version = pkg[deppath][0][1].split(',')[0]
+                        if not version.startswith('fakeversion'):
+                            version = char2dotvers(version)
+                            print (Template(depend_tmpl,searchList=[
+                                        {'catalogname': catalogname,'version': version }]))
+                    else:
+                        print (line)
+                else:
+                    print (line)
+                        
+def main():
+    global pkgroot, catrel, arch, osrel
+
+    parser = optparse.OptionParser()
+    parser.add_option("--debug", dest="debug", action="store_true")
+    parser.add_option("-r", "--os-release", dest="osrel",
+                    default='system',
+                    help="E.g. SunOS5.10")
+    parser.add_option("-a", "--arch", dest="arch", default='system',
+                    help="'i386' or 'sparc'")
+    parser.add_option("-c", "--catalog-release", dest="catrel",
+                    default="unstable",
+                    help="E.g. unstable, dublin")    
+    parser.add_option("-R", "--pkg-root", dest="pkgroot",
+                    default="../pkgroot",
+                    help="E.g. unstable, dublin")    
+    options, args = parser.parse_args()
+    if not args:
+        logging.error("need argument: package_prototype after pkgdepend generate")
+        sys.exit(1)
+    if options.debug:
+        logging.basicConfig(level=logging.DEBUG)
+    if options.osrel:
+        osrel = options.osrel
+    if options.arch:
+        arch = options.arch
+    if options.catrel:
+        catrel = options.catrel
+    if options.pkgroot:
+        pkgroot = options.pkgroot
+    logging.debug("use options: %s %s %s %s" % (catrel, arch, osrel, pkgroot))
+    logging.debug("use arg:  %s" % args)
+    if not os.path.exists(fn_stdlibs):
+        print ("needed file %s not found, will create this" % fn_stdlibs, file=sys.stderr)
+        makeStdLibDb.buildStdlibList()
+    
+    Pkg = GetPackage()
+    for p5m in args:
+        Pkg.resolveDeps(p5m)
+    print ("")
+
+
+if __name__ == '__main__':
+  main()

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2016-02-03 05:40:38 UTC (rev 25541)
+++ csw/mgar/gar/v2/lib/python/rest.py	2016-02-04 11:01:43 UTC (rev 25542)
@@ -422,6 +422,14 @@
     data = urllib2.urlopen(url).read()
     return cjson.decode(data)
 
+  def GetPathsAndCatnamesByBasename(self, catrel, arch, osrel, basename):
+    url = (
+        self.pkgdb_url
+        + "/catalogs/%s/%s/%s/catnames-and-paths-by-basename?%s"
+           % (catrel, arch, osrel, urllib.urlencode({'basename': basename})))
+    data = urllib2.urlopen(url).read()
+    return cjson.decode(data)
+
   def GetCatalogTimingInformation(self, catrel, arch, osrel):
     url = (
       self.pkgdb_url

Added: csw/mgar/gar/v2/transforms/README
===================================================================
--- csw/mgar/gar/v2/transforms/README	                        (rev 0)
+++ csw/mgar/gar/v2/transforms/README	2016-02-04 11:01:43 UTC (rev 25542)
@@ -0,0 +1 @@
+see also at /usr/share/pkg/transform

Added: csw/mgar/gar/v2/transforms/defaults
===================================================================
--- csw/mgar/gar/v2/transforms/defaults	                        (rev 0)
+++ csw/mgar/gar/v2/transforms/defaults	2016-02-04 11:01:43 UTC (rev 25542)
@@ -0,0 +1,26 @@
+<transform dir file link hardlink path=opt/.+/man(/.+)? -> default facet.doc.man true>
+<transform dir file link hardlink path=opt/.+/doc(/.+)? -> default facet.doc true>
+<transform file path=opt/.+/man(/.+)? -> add restart_fmri svc:/application/man-index:default>
+<transform dir path=etc(/opt(/csw(/init.d)?)?)?$ -> drop>
+<transform dir path=var(/opt(/csw(/(log|run|lib))?)?)?$ -> drop>
+<transform dir path=var/svc(/manifest)?$ -> drop>
+<transform dir path=opt(/csw)?$ -> drop>
+<transform dir path=opt/csw(/(bin|sbin|lib|libexec|share|include))?$ -> drop>
+<transform dir path=opt/csw/share/(doc|man(/man[0-9a-z]([a-z])?)?)$ -> drop>
+<transform dir path=opt/csw/lib(/.*)/pkgconfig$ -> drop>
+<transform dir path=opt/csw/lib/python([0-9.]+)?$ -> drop>
+<transform dir path=opt/csw/lib/python([0-9.]+)?/site-packages$ -> drop>
+<transform file path=opt/csw/lib/python.* -> add restart_fmri \
+    svc:/application/pycompile>
+<transform file path=opt/csw/lib/python.* -> emit depend fmri=pkg:/opencsw/cswpycomile type=require>
+<transform file path=var/svc/manifest/.*\.xml$ -> default restart_fmri svc:/system/manifest-import:default>
+<transform file path=.*lib/.+\.a$ -> default facet.devel all>
+<transform file path=.*lib/.+\.la$ -> default facet.devel all>
+<transform file path=.*lib/.+\.so$ -> default facet.devel all>
+<transform file path=.*lib(/(amd64|sparv9))?/pkgconfig(/.*)? -> default facet.devel all>
+<transform file path=.*include/.* -> default facet.devel all>
+<transform file path=.*aclocal/.* -> default facet.devel all>
+<transform file path=.*man3/.+ -> default facet.devel all>
+<transform file path=.*man1/.+-config$ -> default facet.devel all>
+<transform file path=.*bin/.+-config$ -> default facet.devel all>
+

Added: csw/mgar/gar/v2/transforms/unneeded-deps
===================================================================
--- csw/mgar/gar/v2/transforms/unneeded-deps	                        (rev 0)
+++ csw/mgar/gar/v2/transforms/unneeded-deps	2016-02-04 11:01:43 UTC (rev 25542)
@@ -0,0 +1,3 @@
+<transform depend fmri=.*shell/ksh93.* -> drop >
+<transform depend pkg.debug.depend.file=sh -> drop >
+

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list