2020from ciq_helpers import get_git_user , last_git_tag , parse_kernel_tag , replace_spec_changelog
2121
2222
23- def calculate_lt_rebase_versions (kernel_version , distlocalversion , dist ):
23+ def calculate_lt_rebase_versions (kernel_version , buildid ):
2424 """Calculate version strings for LT rebase.
2525
2626 Arguments:
2727 kernel_version: Kernel version string (e.g., '6.12.74')
28- distlocalversion: DISTLOCALVERSION string (e.g., '.1.0.0')
29- dist: DIST string (e.g., '.el9_clk')
28+ buildid: Build ID string (e.g., '.1')
3029
3130 Returns:
32- Tuple of (full_kernel_version, tag_version, spectarfile_release, new_tag, major_version)
31+ Tuple of (full_kernel_version, tag_version, kernel_major_minor, kernel_patch,
32+ buildid, new_tag, major_version)
3333 """
34+ # Parse kernel version into components
35+ version_parts = kernel_version .split ("." )
36+ if len (version_parts ) != 3 :
37+ raise ValueError (f"Invalid kernel version format: { kernel_version } " )
38+
39+ kernel_major_minor = f"{ version_parts [0 ]} .{ version_parts [1 ]} "
40+ kernel_patch = version_parts [2 ]
41+ major_version = version_parts [0 ]
42+
3443 tag_version = f"{ kernel_version } -1"
35- spectarfile_release = f"{ tag_version } { distlocalversion } { dist } "
3644 new_tag = f"ciq_kernel-{ tag_version } "
37- major_version = kernel_version .split ("." )[0 ]
3845
39- return kernel_version , tag_version , spectarfile_release , new_tag , major_version
46+ return kernel_version , tag_version , kernel_major_minor , kernel_patch , buildid , new_tag , major_version
4047
4148
4249def update_spec_file (
4350 spec_path ,
4451 full_kernel_version ,
45- spectarfile_release ,
52+ kernel_major_minor ,
53+ kernel_patch ,
54+ buildid ,
4655 lt_tag_version ,
4756 lt_new_tag ,
4857 lt_major_version ,
4958 upstream_tag ,
5059 srcgit ,
51- distlocalversion ,
52- dist ,
5360):
5461 """Update the spec file with new version information and changelog.
5562
5663 Arguments:
5764 spec_path: Path to kernel.spec file
5865 full_kernel_version: Full kernel version (e.g., '6.12.77')
59- spectarfile_release: Value for tarfile_release variable
66+ kernel_major_minor: Major.minor version (e.g., '6.12')
67+ kernel_patch: Patch version (e.g., '77')
68+ buildid: Build ID (e.g., '.1')
6069 lt_tag_version: Tag version (e.g., '6.12.77-1')
6170 lt_new_tag: New tag name (e.g., 'ciq_kernel-6.12.77-1')
6271 lt_major_version: Major version number (e.g., '6')
6372 upstream_tag: Git tag name (e.g., 'v6.12.77')
6473 srcgit: Git repository object
65- distlocalversion: DISTLOCALVERSION string
66- dist: DIST string
6774 """
75+ import re
76+
6877 # Read the spec file
6978 try :
7079 with open (spec_path , "r" ) as f :
@@ -73,6 +82,22 @@ def update_spec_file(
7382 print (f"ERROR: Failed to read spec file { spec_path } : { e } " )
7483 sys .exit (1 )
7584
85+ # Extract el_version from spec file
86+ el_version = None
87+ for line in spec :
88+ if line .startswith ("%define el_version" ):
89+ match = re .search (r'%define el_version\s+(\d+)' , line )
90+ if match :
91+ el_version = match .group (1 )
92+ break
93+
94+ if not el_version :
95+ print ("ERROR: Could not find %define el_version in spec file" )
96+ sys .exit (1 )
97+
98+ # Construct dist string from el_version for changelog
99+ dist = f".el{ el_version } "
100+
76101 # Get git user info, checking both repo-level and global config
77102 try :
78103 name , email = get_git_user (srcgit )
@@ -83,21 +108,21 @@ def update_spec_file(
83108 print (f" Error details: { e } " )
84109 sys .exit (1 )
85110
86- # Update version variables
111+ # Update version variables - updating base variables, not el_version
87112 updated_spec = []
88113 for line in spec :
89- if line .startswith ("%define specrpmversion " ):
90- line = f"%define specrpmversion { full_kernel_version } "
91- elif line .startswith ("%define specversion " ):
92- line = f"%define specversion { full_kernel_version } "
93- elif line .startswith ("%define tarfile_release " ):
94- line = f"%define tarfile_release { spectarfile_release } "
114+ if line .startswith ("%define kernel_major_minor " ):
115+ line = f"%define kernel_major_minor { kernel_major_minor } "
116+ elif line .startswith ("%define kernel_patch " ):
117+ line = f"%define kernel_patch { kernel_patch } "
118+ elif line .startswith ("%define buildid " ):
119+ line = f"%define buildid { buildid } "
95120 updated_spec .append (line )
96121
97122 # Build changelog entry lines
98123 changelog_date = time .strftime ("%a %b %d %Y" )
99124 changelog_lines = [
100- f"* { changelog_date } { name } <{ email } > - { lt_tag_version } { distlocalversion } { dist } " ,
125+ f"* { changelog_date } { name } <{ email } > - { lt_tag_version } { buildid } { dist } " ,
101126 f"-- Rebased changes for Linux { full_kernel_version } (https://github.com/ctrliq/kernel-src-tree/releases/tag/{ lt_new_tag } )" ,
102127 ]
103128
@@ -133,9 +158,8 @@ def update_spec_file(
133158 parser .add_argument ("--srcgit" , required = True , help = "Location of srcgit repository" )
134159 parser .add_argument ("--spec-file" , required = True , help = "Path to kernel.spec file" )
135160 parser .add_argument (
136- "--distlocalversion " , default = ".1.0.0 " , help = "DISTLOCALVERSION for tarfile_release (default: .1.0.0 )"
161+ "--buildid " , default = ".1" , help = "Build ID (default: .1)"
137162 )
138- parser .add_argument ("--dist" , default = ".el9_clk" , help = "DIST for tarfile_release (default: .el9_clk)" )
139163 parser .add_argument ("--commit" , action = "store_true" , help = "Commit the spec file changes to git" )
140164 args = parser .parse_args ()
141165
@@ -167,14 +191,16 @@ def update_spec_file(
167191 sys .exit (1 )
168192
169193 # Calculate version strings
170- full_kernel_version , tag_version , spectarfile_release , new_tag , major_version = calculate_lt_rebase_versions (
171- kernel_version , args .distlocalversion , args . dist
194+ full_kernel_version , tag_version , kernel_major_minor , kernel_patch , buildid , new_tag , major_version = calculate_lt_rebase_versions (
195+ kernel_version , args .buildid
172196 )
173197
174198 print ("\n LT Rebase Version Information:" )
175199 print (f" Full Kernel Version: { full_kernel_version } " )
200+ print (f" Kernel Major.Minor: { kernel_major_minor } " )
201+ print (f" Kernel Patch: { kernel_patch } " )
202+ print (f" Build ID: { buildid } " )
176203 print (f" Tag Version: { tag_version } " )
177- print (f" Spec tarfile_release: { spectarfile_release } " )
178204 print (f" New Tag: { new_tag } " )
179205 print (f" Major Version: { major_version } \n " )
180206
@@ -189,14 +215,14 @@ def update_spec_file(
189215 update_spec_file (
190216 spec_path ,
191217 full_kernel_version ,
192- spectarfile_release ,
218+ kernel_major_minor ,
219+ kernel_patch ,
220+ buildid ,
193221 tag_version ,
194222 new_tag ,
195223 major_version ,
196224 upstream_tag ,
197225 srcgit ,
198- args .distlocalversion ,
199- args .dist ,
200226 )
201227
202228 print ("Spec file updated successfully" )
0 commit comments