
    <i(                         d dl Z d dlZd dlZd dlZd dlZd dlZd Zd Zd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd ZddZd ZdS )    Nc                 v   t           j        j        }t           j        j        }|r%t           j                            | d|            dS |dk    r!t           j                            |            dS |dv r!t           j                            |            dS t           j                            | d|            dS )z=checkout a commit, either latest tag or master or 20YY branchzorigin/latest)masternightlyN)libargsfeed
git_branchgitcheckoutcheckout_latest_tagcheckout_default_branch)projectr	   branchs      X/home/osmocom-build/jenkins/workspace/gerrit-binpkgs@2/osmo-ci/scripts/obs/lib/srcpkg.pycheckout_for_feedr      s    8=DX F 4"4F"4"455555			##G,,,,,	&	&	&''00000"2D"2"233333    c                    t           j                            |           }| d}t          j                            |          rHt          j        |dg|          j                                        }|st          j	        |d           |S t           j        
                    |           }|                    ddd          }|                    ddd	          }t          j        d
dddd| dg|d          }|j        dk    rt          |  d           t          j        g d|          j        dd         }t          j        g d|          j                                        }	 t          |  d           t           j                            |           }| d| d| S #  t          |  d           d| d| cY S xY w|j        dk    rt          j	        |d           |j                                        }|                    ddd          }|                    ddd          }|                    d          r
|dd         }|S ) z@:returns: the string from git-version-gen, e.g. '1.7.0.10-76bdb'z/git-version-gen.cwdz!empty output from git-version-gen^    $r   describez
--abbrev=4z--tagsz--match=HEADFr   check   z: has no git tags)r   z	rev-parser   r      )r   zrev-listz--countr   z': getting version from debian/changelog-z: using 0.0.0 as versionz0.0.0.zcommand failed unexpectedlyz-gvN)r   r   get_repo_pathospathexistsrun_cmdoutputrstripexit_error_cmdget_latest_tag_patternreplace
returncodeprintdebianget_last_version_from_changelog
startswith)	r   	repo_pathscript_pathretpatternresultcommitcountversions	            r   get_git_versionr<      s   %%g..I 000K	w~~k"" k;,)<<<CJJLL 	Is$GHHH

 g,,W55Gooc2q))Gooc2r**G[ w  	
   F C+++,,,(((
 
 
 1 222
 
 
  		-WEEEFFFj@@IIG0000000	-W666777,E,,F,,,,,A6#@AAA
-


 
 C ++c3
"
"C
++dC
#
#C
~~c !""gJs   +:F& &Gc                    t           j        j        dk    r@t           j                            |           }|                    d          r
|dd          n|S t          |           }|dk    r>t           j                            |           }d|v r|	                    d          d         }t           j        j
        }|r| d| }|S )Nr   r$   r   UNKNOWN:r   )r   r   r	   r   get_latest_tagr3   r<   r1   r2   splitconflict_version)r   r6   rB   s      r   get_version_for_feedrC   \   s    
x}   g$$W--..--6s122ww36
'
"
"C ij88AA#::))C..#C x0 *))'))Jr   c                     t           j                            |           }d|v r|                    d          d         S dS )a4  The osmo-gbproxy used to have the same package version as osmo-sgsn
    until 2021 where it was split into its own git repository. From then on,
    osmo-gbproxy has a 0.*.* package version, which is smaller than the
    previous 1.*.* from osmo-sgsn. We had to set the epoch to 1 for
    osmo-gbproxy so package managers know these 0.*.* versions are higher than
    the previous 1.*.* ones that are still found in e.g. debian 11. The epoch
    is set in debian/changelog, retrieve it from there.
    :returns: the epoch number if set, e.g. "1" or an empty stringr?   r   r   )r   r1   r2   rA   )r   version_epochs     r   	get_epochrF   v   sB     J>>wGGM
m""3''**2r   c                  p    t          j        g dt           j                            d                     dS )zeDownload the subproject sources here, so the package can be built in
    OBS without Internet access.)mesonsubprojectsdownloadopen5gsr   N)r   r)   r   r%    r   r   prepare_project_open5gsrM      sC     K,,,G!!),,     r   c                      t           j                            d          } t          j                            t           j        d          }t          j        dd|g|            d S )Npyhsszdata/pyhss_download_deps.shshz-er   )r   r   r%   r&   r'   join
ci_obs_dirr)   )r4   scripts     r   prepare_project_pyhssrT      sQ    %%g..IW\\#.*GHHFKtV$)444444r   c                  t    t           j                            d          } t          j        g d|            dS )a  The format of the license field in pyproject.toml was changed from a
    "table" to a a string with an SPDX license expression. The sources have
    been adjusted to use the new format to appease a warning ("By 2026-Feb-18,
    you need to update your project and remove deprecated calls or your builds
    will no longer be supported."). However now the build fails with setuptools
    from Debian 12. Remove the license line from pyproject.toml, the debian
    packaging has its own license information in debian/copyright.	pyosmocom)sed-iz/^license = /dzpyproject.tomlr   N)r   r   r%   r)   )r4   s    r   prepare_project_pyosmocomrY      s;     %%k22IKAAAyQQQQQQr   c                     t           j                            |           }d}t          j                            | d|           r,t          |  d|            t          j        ||           dS dS )zRun contrib/generate_build_dep.sh if it exists in the given project, to
    to download sources for dependencies (see e.g. osmo_dia2gsup.git).zcontrib/generate_build_dep.sh/
: running r   N)r   r   r%   r&   r'   r(   r0   r)   )r   r4   r5   s      r   run_generate_build_depr]      s     %%g..I1K	w~~22[2233 011K11222KY//////0 0r   c                     t           j                            |           }t          | dd          5 }|                    | d           d d d            d S # 1 swxY w Y   d S )Nz/.tarball-versionw
)r   r   r%   openwrite)r   r;   r4   fs       r   write_tarball_versionrd      s    %%g..I	---s	3	3  q	7                                   s   AA Ac                     t          j        |           }t           j                            |           }t	          |  d| d           t          j        | d| d                                           dS )zWrite the current git commit to commit_$commit.txt file, so it gets
    uploaded to OBS along with the rest of the source package. This allows
    figuring out if the source package is still up-to-date or not for the
    master feed.z: adding commit_z.txtz/commit_N)r   get_output_pathr   get_headr0   pathlibPathtouch)r   output_pathr9   s      r   write_commit_txtrl      s{    
 %g..KWg&&F	W
2
2f
2
2
2333LK5555566<<>>>>>r   c                 B   t           j                            |           }t          j        g d|d          }|j                                                            d          }|D ]7}|dk    r	t          |  d|            t          j        ddd	|g|
           8d S )N)grepz-rz-lz;include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.asciidoc.incFr   r`   r   z6: setting asciidoc style to remove draft watermark in rW   rX   zZ/\/build\/Makefile\.asciidoc\.inc/s/^/  ASCIIDOCSTYLE = $(BUILDDIR)\/custom-dblatex.sty\n/r   )r   r   r%   r)   r*   r+   rA   r0   )r   r4   doc_makefilesdoc_makefiles       r   *set_asciidoc_style_without_draft_watermarkrq      s    %%g..IK[[[  M
 "(//1177==M% 
 
2^^P\^^___r	 	
 	
 	
 	
 	
	
 
r   c                 \   t           j        j        }t           j        j        }t           j        j        }t           j                            |            t           j                            |            |dk    r!t           j                            | |           nt          |            t          |           }|r||z  }t          |           }|r| d| n|}t           j                            |           d u}t          |  d|            t          | |           | t           j        j        v rqt           j        j        s`| dk    rZt           j        j        pd| }	t           j                            | |	|           |r!t           j                            | |	|           t           j                            | |           t1          j        t          j        |                      t          j                     dt0          j                            |            }
|
t=                      v r0t          |  d|
             t=                      |
                      | t           j        j        v rt?          |            t           j        j         r/t           j                             | t           j        j                    t           j        j!        r t           j        !                    |            n|dk    rtE          |            t           j        #                    |            t           j        $                    |            |r@t           j        %                    | ||           t           j        &                    |            |d	k    rtO          |            t          j                     |S )
Nr   r?   z: building source package zosmocom-keyringzosmocom-prepare_project_r\   r   r   )(r   r   rB   r	   version_appendr   clonecleancheckout_from_reviewr   rC   rF   rpm_specget_spec_in_pathr0   rd   configprojects_osmocomno_metaconflict_pkgnamer1   control_add_depend
add_dependchangelog_add_entry_if_neededr&   makedirsrf   remove_cache_extra_filesr'   basenameglobalsr]   configure_appenddisable_manualsrq   build_source_packagemove_files_to_outputgeneratecopy_to_outputrl   )r   	gerrit_idrB   r	   rt   r;   epochrE   has_rpm_specmetapkgproject_specific_funcs              r   buildr      sC   x08=DX,NGMM'GMM'1}}$$Wi8888'""""7++G ">!gE,1>u((w(((wM<0099EL	W
?
?
?
?@@@'=111#*---ch6F-7VgKgKg(+@/@$/@/@
%%gw8HIII 	HL##GW6FGGGJ,,WmDDDK#G,,--- """Jrw/?/?/H/HJJ		));;$9;;<<<(		'(***#*---w'''
x  H
##GSX-FGGG
x <
""7++++			27;;;J##G,,,J##G,,, -gw666##G,,,x!!! """r   c                 r   t          j         t          j        |            d          }t          |          dk    sJ d|              t	          |d         d          5 }|                                D ])}|                    d          rd|v r ddd           d	S *	 ddd           n# 1 swxY w Y   d
S )zgCheck if an already built source package has osmo-gsm-manuals-dev in
    Build-Depends of the .dsc filez/*.dscr   zfailed to get dsc path for r   rzBuild-Depends:zosmo-gsm-manuals-devNTF)globr   rf   lenra   	readlinesr3   )r   path_dschandlelines       r   requires_osmo_gsm_manuals_devr     s(    yC/88@@@AAHx==AFWFF	hqk3		 6$$&& 	 	D/00 5Kt5S5S       	              
 5s    1B,B,,B03B0)r   )r   r&   rh   
lib.configr   
lib.debianlib.rpm_specr   r<   rC   rF   rM   rT   rY   r]   rd   rl   rq   r   r   rL   r   r   <module>r      s    				             4 4 4? ? ?D  4  "  5 5 5	R 	R 	R0 0 0     	? 	? 	?
 
 
0= = = =@    r   