Skip to content

Commit baebd25

Browse files
authored
[Mellanox] Remove external-changes patch if no downstream changes are found (#18795)
- Why I did it Bug Fix: when the external-changes.patch is empty, sonic-linux-kernel build fails when called with INCLUDE_EXTERNAL_PATCHES=y flag How I did it - How to verify it Verified by integrating a hw-mgmt version without downstream patches and building linux kernel with EXTERNAL_PATCHES flag Signed-off-by: Vivek Reddy <[email protected]>
1 parent 4a421c8 commit baebd25

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

platform/mellanox/integration-scripts.mk

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,8 @@ endif
163163
git add -- $(PLATFORM_PATH)/non-upstream-patches/
164164
git add -- $(PLATFORM_PATH)/hw-management.mk
165165

166-
echo -en '\n###-> Non Upstream external-changes.patch changes <-###\n' >> ${HWMGMT_USER_OUTFILE}
167-
git diff --no-color --staged -- $(PLATFORM_PATH)/non-upstream-patches/external-changes.patch >> ${HWMGMT_USER_OUTFILE}
168-
169-
echo -en '\n###-> Non Upstream kconfig-inclusions.patch changes <-###\n' >> ${HWMGMT_USER_OUTFILE}
170-
git diff --no-color --staged -- $(PLATFORM_PATH)/non-upstream-patches/kconfig-inclusions.patch >> ${HWMGMT_USER_OUTFILE}
166+
echo -en '\n###-> Non Upstream changes <-###\n' >> ${HWMGMT_USER_OUTFILE}
167+
git diff --no-color --staged -- $(PLATFORM_PATH)/non-upstream-patches/ >> ${HWMGMT_USER_OUTFILE}
171168

172169
echo -en '\n###-> Non Upstream patch list file <-###\n' >> ${HWMGMT_USER_OUTFILE}
173170
git diff --no-color --staged -- $($(MLNX_HW_MANAGEMENT)_SRC_PATH)/hwmgmt_nonup_patches >> ${HWMGMT_USER_OUTFILE}

platform/mellanox/integration-scripts/hwmgmt_kernel_patches.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
3+
# Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES.
44
# Apache-2.0
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
1818

1919
from hwmgmt_helper import *
2020

21-
COMMIT_TITLE = "Intgerate HW-MGMT {} Changes"
21+
COMMIT_TITLE = "Integrate HW-MGMT {} Changes"
2222

2323
PATCH_TABLE_LOC = "platform/mellanox/hw-management/hw-mgmt/recipes-kernel/linux/"
2424
PATCHWORK_LOC = "linux-{}/patchwork"
@@ -270,9 +270,15 @@ def rm_old_non_up_mlnx(self):
270270
sys.exit(1)
271271

272272
def mv_new_non_up_mlnx(self):
273+
dest_fpath = os.path.join(self.args.build_root, NON_UP_PATCH_LOC)
274+
if not Data.new_non_up and os.path.exists(dest_fpath):
275+
os.rmdir(dest_fpath)
276+
return
277+
273278
for patch in Data.new_non_up:
274279
src_path = os.path.join(self.args.non_up_patches, patch)
275-
shutil.copy(src_path, os.path.join(self.args.build_root, NON_UP_PATCH_LOC))
280+
os.makedirs(dest_fpath, exist_ok=True)
281+
shutil.copy(src_path, dest_fpath)
276282

277283
def construct_series_with_non_up(self):
278284
Data.agg_slk_series = copy.deepcopy(Data.up_slk_series)
@@ -309,7 +315,23 @@ def get_series_diff(self):
309315
return lines
310316

311317
def get_merged_diff(self, series_diff: list, kcfg_diff: list) -> list:
312-
return series_diff + ["\n"] + kcfg_diff
318+
if series_diff or kcfg_diff:
319+
return series_diff + ["\n"] + kcfg_diff
320+
else:
321+
return []
322+
323+
def write_non_up_diff(self, series_diff, kcfg_diff):
324+
final_diff = self.get_merged_diff(series_diff, kcfg_diff)
325+
non_up_diff_path = os.path.join(self.args.build_root, NON_UP_DIFF)
326+
if "".join(final_diff).strip():
327+
# don't write anything if the diff just contains whitespaces
328+
FileHandler.write_lines(non_up_diff_path, final_diff, True)
329+
else:
330+
# if nothing to write, delete the patch file
331+
try:
332+
os.remove(non_up_diff_path)
333+
except OSError as error:
334+
print("-> NOTICE File {} remove failed with error {}".format(non_up_diff_path, error))
313335

314336
def list_patches(self):
315337
old_up_patches = []
@@ -388,8 +410,7 @@ def perform(self):
388410
series_diff = self.get_series_diff()
389411
# handle kconfig and get any diff
390412
kcfg_diff = self.kcfg_handler.perform()
391-
final_diff = self.get_merged_diff(series_diff, kcfg_diff)
392-
FileHandler.write_lines(os.path.join(self.args.build_root, NON_UP_DIFF), final_diff, True)
413+
self.write_non_up_diff(series_diff, kcfg_diff)
393414

394415
path = os.path.join(self.args.build_root, PATCH_TABLE_LOC)
395416
patch_table = load_patch_table(path, Data.k_ver)

platform/mellanox/integration-scripts/tests/test_hwmgmtaction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
2+
# Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES.
33
# Apache-2.0
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -56,7 +56,7 @@
5656
"""
5757

5858
TEST_SLK_COMMIT = """\
59-
Intgerate HW-MGMT 7.0030.0937 Changes
59+
Integrate HW-MGMT 7.0030.0937 Changes
6060
## Patch List
6161
* 0002-i2c-mlxcpld-Decrease-polling-time-for-performance-im.patch : https://github.com/torvalds/linux/commit/cb9744178f33
6262
* 0003-i2c-mlxcpld-Add-support-for-I2C-bus-frequency-settin.patch : https://github.com/torvalds/linux/commit/66b0c2846ba8
@@ -71,7 +71,7 @@
7171
"""
7272

7373
TEST_SB_COMMIT = """\
74-
Intgerate HW-MGMT 7.0030.0937 Changes
74+
Integrate HW-MGMT 7.0030.0937 Changes
7575
7676
"""
7777

@@ -165,8 +165,8 @@ def test_write_final_diff(self, mock_write_lines):
165165
series_diff = self.action.get_series_diff()
166166
kcfg_diff = self._get_kcfg_incl_diff()
167167
final_diff = self.action.get_merged_diff(series_diff, kcfg_diff)
168+
self.action.write_non_up_diff(series_diff, kcfg_diff)
168169
print("".join(final_diff))
169-
FileHandler.write_lines(os.path.join(self.action.args.build_root, NON_UP_DIFF), final_diff, True)
170170
assert check_file_content(MOCK_INPUTS_DIR+"expected_data/external-changes.patch")
171171

172172
def test_commit_msg(self):

0 commit comments

Comments
 (0)