
    $i(                         S SK r S SKrS SKrS SKrS SKrS SKrS rS rS r	S r
S rS rS rS	 rS
 rS rS rSS jrS rg)    Nc                    [         R                  R                  n[         R                  R                  nU(       a$  [         R                  R                  U SU 35        gUS:X  a   [         R                  R                  U 5        gUS;   a   [         R                  R                  U 5        g[         R                  R                  U SU 35        g)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      /obs/lib/srcpkg.pycheckout_for_feedr      s    88==DXX  FGF8"45		##G,	&	&''0GD6"23    c                    [         R                  R                  U 5      nU S3n[        R                  R                  U5      (       aO  [         R                  " US/US9R                  R                  5       nU(       d  [         R                  " US5        U$ [         R                  R                  U 5      nUR                  SSS5      nUR                  SSS	5      n[         R                  " S
SSSSU 3S/USS9nUR                  S:X  a  [        U  S35        [         R                  " / SQUS9R                  SS n[         R                  " / SQUS9R                  R                  5       n [        U  S35        [         R                  R                  U 5      nU SU SU 3$ UR                  S:w  a  [         R                  " US5        UR                  R                  5       nUR                  SSS5      nUR                  SSS5      nUR!                  S5      (       a  USS nU$ !   [        U  S35        SU SU 3s $ = f) 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 K/0K	ww~~k""kk;,)<CCJJLs$GH

 gg,,W5Gooc2q)Gooc2r*G[[wi 	
 F C	*+,(
 &1 2
 & 		-WIDEFjj@@IGYawax00
 A6#@A
--


 C ++c3
"C
++dC
#C
~~c!"gJ%	-WI567E7!F8,,s   .6H) )Ic                    [         R                  R                  S:X  a<  [         R                  R	                  U 5      nUR                  S5      (       a  USS  $ U$ [        U 5      nUS:X  a9  [         R                  R                  U 5      nSU;   a  UR                  S5      S   n[         R                  R                  nU(       a  U SU 3nU$ )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    
xx}}  gg$$W-..--s12w636
'
"C ijj88A#:))C.#C xx00Q'()Jr   c                 v    [         R                  R                  U 5      nSU;   a  UR                  S5      S   $ g)a  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   s9     JJ>>wGM
m""3'**r   c                  l    [         R                  " / SQ[         R                  R                  S5      S9  g)zaDownload 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      s%     KK,GG!!),r   c                      [         R                  R                  S5      n [        R                  R                  [         R                  S5      n[         R                  " SSU/U S9  g )Npyhsszdata/pyhss_download_deps.shshz-er   )r   r   r%   r&   r'   join
ci_obs_dirr)   )r4   scripts     r   prepare_project_pyhssrT      sD    %%g.IWW\\#..*GHFKKtV$)4r   c                  p    [         R                  R                  S5      n [         R                  " / SQU S9  g)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2IKKAyQr   c                     [         R                  R                  U 5      nSn[        R                  R                  U SU 35      (       a%  [        U  SU 35        [         R                  " X!S9  gg)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	ww~~1[M233	K=12K/ 4r   c                     [         R                  R                  U 5      n[        U S3S5       nUR	                  U S35        S S S 5        g ! , (       d  f       g = f)Nz/.tarball-versionw
)r   r   r%   openwrite)r   r;   r4   fs       r   write_tarball_versionrd      sH    %%g.I	,-s	3q	7)2 
4	3	3s   A
Ac                     [         R                  " U 5      n[         R                  R                  U 5      n[	        U  SU S35        [
        R                  " U SU S35      R                  5         g)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WWg&F	WI%fXT
23LLK=56<<>r   c                 8   [         R                  R                  U 5      n[         R                  " / SQUSS9nUR                  R                  5       R                  S5      nU H4  nUS:X  a  M  [        U  SU 35        [         R                  " SSS	U/US
9  M6     g )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KK[M
 "((//177=M%2	OP\~^_r	 	
	 &r   c                    [         R                  R                  n[         R                  R                  n[         R                  R                  n[         R
                  R                  U 5        [         R
                  R                  U 5        US:  a   [         R
                  R                  X5        O[        U 5        [        U 5      nU(       a  XT-  n[        U 5      nU(       a  U SU 3OUn[         R                  R                  U 5      S Ln[        U  SU 35        [        X5        U [         R                   R"                  ;   a  [         R                  R$                  (       ds  U S:w  am  [         R                  R&                  =(       d    SU 3n	[         R(                  R+                  X	U5        U(       a   [         R                  R-                  X	U5        [         R(                  R/                  X5        [0        R2                  " [         R4                  " U 5      5        [         R6                  " 5         S[0        R8                  R;                  U 5       3n
U
[=        5       ;   a"  [        U  SU
 35        [=        5       U
   " 5         U [         R                   R"                  ;   a  [?        U 5        [         R                  R@                  (       a8  [         R(                  RA                  U [         R                  R@                  5        [         R                  RB                  (       a   [         R(                  RC                  U 5        OUS:X  a  [E        U 5        [         R(                  RG                  U 5        [         R(                  RI                  U 5        U(       a?  [         R                  RK                  XU5        [         R                  RM                  U 5        US	:X  a  [O        U 5        [         R6                  " 5         U$ )
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      s   xx0088==DXX,,NGGMM'GGMM'1}$$W8'""7+G!gE,1ugQwi(wM<<009EL	WI/
?@'1#**---chh6F6F7VgKg((++@$/@

%%g8HILL##G6FGJJ,,WDKK##G,-  ".rww/?/?/H.IJ	)	$9#:;<	'(*#**---w'
xx  

##GSXX-F-FG
xx

""7+		27;JJ##G,JJ##G,g6##G,x!  "r   c                 `   [         R                   " [        R                  " U 5       S35      n[        U5      S:X  d
   SU  35       e[	        US   S5       nUR                  5        H+  nUR                  S5      (       d  M  SU;   d  M#    SSS5        g	   SSS5        g
! , (       d  f       g
= f)zcCheck 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     yyC//89@AHx=AF!<WIFF	hqk3	6$$&D/005Kt5S 
 	& 
 
  
 	
 s   (BB
BB
B-)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?D4"5	R0 	?
0=@r   