a tf*_@sddlmmZddlmZddlZddlmZddl Z ddl Z ddl Z ddl ZddlZddlZGdddejZGdddejZdS)N)lint_fmri_successorcseZdZdZdZfddZddZddd Zd d Zd d Z ddZ ddZ dddZ e de _d ddZe de_d!ddZe de_ZS)"UserlandActionCheckerz3An opensolaris.org-specific class to check actions.zuserland.actioncstd|_td}|dkr(||_nd|_gd|_gd|_t dt dt dg|_ t dt d t d t d t d g|_ t d |_ i|_ i|_tt||dS)Nz2checks Userland packages for common content errorsZ PROTO_PATH)Zi86Zsparcv7Z32zi86pc-solaris-64intzsun4-solaris-64int)amd64Zsparcv964zi86pc-solaris-thread-multi-64zsun4-solaris-thread-multi-64z ^/lib(/.*)?$z^/usr/z ^\$ORIGIN/z ^.*/64(/.*)?$z^.*/amd64(/.*)?$z^.*/sparcv9(/.*)?$z(^.*/i86pc-solaris-thread-multi-64(/.*)?$z'^.*/sun4-solaris-thread-multi-64(/.*)?$z^etc/(rc.|init)\.d)_ descriptionosgetenvsplit proto_path pathlist32 pathlist64recompile runpath_re runpath_64_re initscript_re lint_paths ref_pathssuperr__init__)selfconfigpath __class__D/jenkins/jobs/oi-userland/workspace/tools/python/pkglint/userland.pyr-s.     zUserlandActionChecker.__init__csDddd}i}|j|j|j|jdD]}||jg|jq$|jD]}||jg|jqJ|j t d|j|j |jdD]6t fdd |jgDs|d |jq|j t d |j|j|j|jdD]|d |jq|j t d |jD]|d |jq|j|j|j|jd dS)zInitialize the checker with a dictionary of paths, so that we can do link resolution. This is copied from the core pkglint code, but should eventually be made common. NFc Ss|}|r"dd||D}ndd|D}|D]`}|rL|j|krLq8||jvrXq8|}|||j||j|} || g |j |fq8dS)zUpdates a dictionary of { attr: [(fmri, action), ..]} where attr is the value of that attribute from actions of a given type atype, in the given manifest.css|] }|VqdSNr.0arrr kzCUserlandActionChecker.startup..seed_dict..css|] }|VqdSrrrrrrr"mr#N) get_all_variantsgen_actions_by_type gen_actionsnameattrsget_variant_template merge_unknownupdate setdefaultappendfmri) mfattrdicatypeverbosepkg_varsZmfgactionvariantsprrr seed_dictbs    z0UserlandActionChecker.startup..seed_dict)releasepatternz+Seeding reference action path dictionaries.)r9c3s|]}t|jVqdSr)rr.)r r.manifestrrr"sz0UserlandActionChecker.startup..rz&Seeding lint action path dictionaries.z'Seeding local action path dictionaries. ignore_pubs)NF) gen_manifests lint_api_instr9r:r,r.get_namer-lint_manifestsloggerdebugr ref_api_instanygetrr"_UserlandActionChecker__merge_dictr>)renginer8 lint_fmrismrr;rstartupZsB        zUserlandActionChecker.startupTcCs|D]}||vr||||<qdd}|||}|||}|D]:}|D],} |} | } t|| |drN|| qNqB||g} |D] } || D]}| | |fqq| ||<qdS)aPMerges the given src dictionary into the target dictionary, giving us the target content as it would appear, were the packages in src to get published to the repositories that made up target. We need to only merge packages at the same or successive version from the src dictionary into the target dictionary. If the src dictionary contains a package with no version information, it is assumed to be more recent than the same package with no version in the target.cSs8i}|D]*\}}||vr(|||q|g||<q|S)z*Builds a dictionary of fmri:action entries)r-)arrr1pfmrir5rrr build_dics   z5UserlandActionChecker.__merge_dict..build_dicr=N)copyrArpopr+r-)rsrctargetr>r7rOsrc_dictarg_dic src_pfmri targ_pfmrisnametnamelrNr5rrrZ __merge_dicts,       z"UserlandActionChecker.__merge_dictcCsPtj|}|tjD]2}|dkr2tj|}q|dkrd}q>d} |jD]}||vrZd} qZ|dkr|dkr| dkr|dkr|S|dkr|rt d }n|dkr|st d }|S) Nrura/FTrb@rxz!32-bit object '%s' in 64-bit pathz!64-bit object '%s' in 32-bit path) rirjrGrrr\r r r r) rrr_rsruraZelemsZpath64r7Zpath32rrrZ__elf_wrong_location_check7s(         z0UserlandActionChecker.__elf_wrong_location_checkrfc Cs|jdvrdS|j}|dks$|dkr.|jd}d|jvr|jd}t|dd@dkrd |jvr|jtd ||d d |j|fd nd |jvrd|jvr|jd}t|dd@dkr|jtd||d d|j|fd n&|jtd||d d|j|fd |jdur|jD]&}|d|}tj |rq@qtj |sp|j td|d|j|fd nnt |r| |} | dkr|j| |d|j|fd |||} | dkr|j| |d|j|fd dS)z'Checks for existence in the proto area.)fileNNOHASHrmoderpreservezA%(path)s is writable (%(mode)s), but missing a preserve attribute)rr%s%s.0rgz>%(path)s has a preserve action, but is not writable (%(mode)s)z%s%s.4z+%(path)s has a preserve action, but no moderyrz3%s missing from proto area, skipping content checks%s%s.1%s%s.2)r'hashr(intrprr rrexistsinfori is_elf_object0_UserlandActionChecker__elf_wrong_location_check)_UserlandActionChecker__elf_runpath_check) rr5r<rI pkglint_idrr directoryfullpathr_rrr file_actionTsb                        z!UserlandActionChecker.file_actionz%Paths should exist in the proto area.002c Cs|jdvrdS|jd}|jd}|||}|j|dr@dS|d7}|jD]}||rNdSqN|jtd|j||fd|j|fddS) zChecks for link resolution.)linkhardlinkNrrSrz"%s %s has unresolvable target '%s'rrg)r'r( _UserlandActionChecker__realpathrrG startswithrpr) rr5r<rIrrrSZ realtargetkeyrrr link_resolvess          z#UserlandActionChecker.link_resolveszlinks should resolve.003cCsH|jdvrdS|jd}|j|rD|jtd|d|j|fddS)z Checks for SVR4 startup scripts.)rr~rrNrz.SVR4 startup '%s', deliver SMF service insteadrrg)r'r(rr{rrr)rr5r<rIrrrrr init_scripts    z!UserlandActionChecker.init_scriptz-SVR4 startup scripts should not be delivered.)T)rf)r)r)__name__ __module__ __qualname____doc__r'rrLrHrZ&_UserlandActionChecker__elf_aslr_checkrrrr pkglint_descrr __classcell__rrrrr(s" -L /!2 9  !  rcs`eZdZdZdZfddZdddZede_dd d Z ed e _dddZ ede _Z S)UserlandManifestCheckerz5An opensolaris.org-specific class to check manifests.zuserland.manifestcstt||dSr)rrr)rrrrrrsz UserlandManifestChecker.__init__1001c Cs$tjds |dD]}|dD]}tj|j}tj j j j tj j j j ttj j j jgB}tj j}tj j dtj j j|dddd} | |gd|} | tj j jjr(|d|jd d d g} | tj j jjD]:} | j| vr|jtd |j|| jd d|j|fdqq(qdS)NZ ENCUMBEREDdependr.rcSsdS)NFr)xrrrr#z=UserlandManifestChecker.forbidden_publisher..T%s.allowed_pubs zopenindiana.orgz on-nightlyzWpackage %(pkg)s depends on %(name)s, which comes from forbidden publisher %(publisher)s)pkgr' publisherrrg)renvironrGr%attrlistrr.PkgFmripkg_nameclientapi PackageInfo ALL_OPTIONSACTION_OPTIONS frozensetLICENSESprogressNullProgressTrackerImageInterfaceCURRENT_API_VERSIONr INFO_FOUND get_paramr'r rrpr) rr<rIrr5fr info_neededZ progtracker interfaceret allowed_pubsirrrforbidden_publishers*   "   z+UserlandManifestChecker.forbidden_publisherz1Dependencies should come from standard publishersrfcCsg}d}d}|dD] }d}q$q|dkr0dS|dD]4}|jdsf|jtdd|j|fdq:d}qpq:|dkr|jtdd|j|fddS) NFrTlicensezNmissing vaue for action license attribute 'license' like 'CDDL','MIT','GPL'...rrgzmissing license action)r%r(rprr')rr<rIrZmanifest_pathsfilesrr5rrrcomponent_checks&     z'UserlandManifestChecker.component_checkzFlicense actions and ARC information are required if you deliver files.rcCsR|d|jd}|j}|jrN|j|vrN|jtd|jd|j|fddS)Nrrzpackage %s has a publisher set!rrg)rr'r r.rrpr)rr<rIrrr.rrrpublisher_in_fmris  z)UserlandManifestChecker.publisher_in_fmrizextra publisher set)r)rf)r) rrrrr'rrrrrrrrrrrrs    r) pkg.lint.baselintbasepkg.lint.enginerpkg.fmrirpkg.elfrirZos.pathrrkpkg.client.apipkg.client.api_errorspkg.client.progress ActionCheckerrManifestCheckerrrrrrs