Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Some release preparation enhancements and made SAL execution path con…
Browse files Browse the repository at this point in the history
…figurable via settings.yaml
  • Loading branch information
kamalkrbh committed Feb 25, 2021
1 parent 5c8bf0f commit f00592b
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 185 deletions.
31 changes: 7 additions & 24 deletions bf_sde.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
set_env_var, validate_path_existence, \
append_to_env_var, \
dname, get_switch_model, execute_cmd, get_ref_bsp_abs_path, \
get_aps_bsp_pkg_abs_path, release_dir, \
execute_cmd_n_get_output_2, delete_files, get_path_relative_to_user_home, \
get_from_advance_setting_dict
get_aps_bsp_pkg_abs_path, execute_cmd_n_get_output_2, get_path_relative_to_user_home, \
get_from_advance_setting_dict, create_release
from constants import stratum_profile
from drivers import load_and_verify_kernel_modules

Expand Down Expand Up @@ -175,26 +174,8 @@ def prepare_bsp_pkg():
'> {3}'.
format(bsp_dev_abs, earliest_commit_hash, latest_commit_hash,
bsp_dev_abs + '/' + get_diff_file_name()))

latest_commit_hash_short = execute_cmd_n_get_output_2(
'git --git-dir {0}/.git rev-parse --short HEAD'.format(bsp_dev_abs))
bsp_name = '/' + os.path.basename(bsp_dev_abs) \
+ '_' + latest_commit_hash_short
bsp_rel_dir = release_dir + bsp_name

try:
os.mkdir(bsp_rel_dir)
print('SAL release directory {} created.'.format(bsp_rel_dir))
except FileExistsError:
print('BSP Release directory {} already exists, recreated.'.format(
bsp_rel_dir))
delete_files(bsp_rel_dir)
os.mkdir(bsp_rel_dir)

shutil.move(bsp_dev_abs + '/' + get_diff_file_name(), bsp_rel_dir + '/' +
get_diff_file_name())
shutil.copytree(bsp_dev_abs + '/platforms/apsn/', bsp_rel_dir + '/apsn')
shutil.make_archive(bsp_rel_dir, 'zip', bsp_rel_dir)
create_release(bsp_dev_abs, get_diff_file_name(),
'/platforms/apsn/')


def ask_user_for_building_bsp():
Expand Down Expand Up @@ -273,16 +254,18 @@ def set_sde_env_n_load_drivers():
load_drivers()
return True


def install_bsp_deps():
os.system('sudo apt -y install libusb-1.0-0-dev libcurl4-openssl-dev')


def install_switch_bsp():
set_sde_env_n_load_drivers()
aps_bsp_installation_file = get_aps_bsp_pkg_abs_path()
print("Installing {}".format(aps_bsp_installation_file))
aps_zip = zipfile.ZipFile(aps_bsp_installation_file)
aps_zip.extractall(Path(aps_bsp_installation_file).parent)
aps_bsp_dir = aps_zip.namelist()[0]
aps_bsp_dir = aps_zip.namelist()[0]+'/apsn/'
aps_bsp_dir_absolute = str(
Path(aps_bsp_installation_file).parent) + '/' + aps_bsp_dir
aps_zip.close()
Expand Down
130 changes: 127 additions & 3 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,126 @@ def delete_files(file):
os.system('rm {}'.format(file))


release_dir = dname + '/release'
if not os.path.exists(release_dir):
os.mkdir(release_dir)
aot_release_dir = dname + '/release'
if not os.path.exists(aot_release_dir):
os.mkdir(aot_release_dir)


def get_latest_git_tag(local_git_repo):
return execute_cmd_n_get_output_2(
'git --git-dir {0}/.git describe --abbrev=0 --tags'.
format(local_git_repo)).strip()


def get_git_tag_hash(local_git_repo, git_tag):
return execute_cmd_n_get_output_2(
'git --git-dir {0}/.git rev-list -n 1 {1}'.
format(local_git_repo, git_tag))


def get_latest_git_hash(local_git_repo):
return execute_cmd_n_get_output_2(
'git --git-dir {0}/.git rev-parse HEAD'.
format(local_git_repo))


def get_2nd_latest_git_tag(local_git_repo):
# If only one tag exists then second last release tag refers to previous
# commit hash to latest release tag.
print(local_git_repo)
return execute_cmd_n_get_output_2(
'git --git-dir {0}/.git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1` --always'.
format(local_git_repo)).strip()


def create_nested_dir(destination_location, dir_path):
"""
Creates nested path given in @dir_path string inside @destination_location,
the outermost directory is ignored and that can be copied by calling function when
all parent directory structure is present.
Args:
destination_location:
dir_path:
Returns:
"""
nested_path_list = dir_path.split('/')
#clear up empty strings in the path
nested_path_list = list(filter(None, nested_path_list))
#Slice the last dir
nested_path_list = nested_path_list[:-1]
for d in nested_path_list:
destination_location += '/'+d+'/'
if not os.path.exists(destination_location):
os.mkdir(destination_location)


def create_release(local_git_repo, *files_to_release):
"""
Args:
local_git_repo: Absolute path to local git repository
*files_to_release: File paths relative to local_git_repo to be part of release.
Returns:
"""
rel_tag_latest = get_latest_git_tag(local_git_repo)
release_tag_2ndlast = get_2nd_latest_git_tag(local_git_repo)
hash_rel_tag_latest = get_git_tag_hash(local_git_repo, rel_tag_latest)
hash_latest = get_latest_git_hash(local_git_repo)

arch_name = None
start_hash_for_RN = None
end_hash_for_RN = None

if hash_latest == hash_rel_tag_latest:
print('Preparing main release {}'.format(rel_tag_latest))
print('Preparing release notes since release tag {}'.format(
release_tag_2ndlast))
start_hash_for_RN = release_tag_2ndlast
end_hash_for_RN = rel_tag_latest
arch_name = aot_release_dir + '/{0}_{1}'. \
format(os.path.basename(local_git_repo), rel_tag_latest)
else:
print('Preparing development release.')
start_hash_for_RN = rel_tag_latest
end_hash_for_RN = hash_latest
suffix = execute_cmd_n_get_output_2(
'git --git-dir {0}/.git describe --tags'.
format(local_git_repo)).strip()
arch_name = aot_release_dir + '/{0}_{1}'. \
format(os.path.basename(local_git_repo), suffix)

try:
os.mkdir(arch_name)
print('Release directory {} created.'.format(arch_name))
except FileExistsError:
print('Release directory {} already exists, recreated.'.format(
arch_name))
delete_files(arch_name)
os.mkdir(arch_name)

rel_notes_file = 'RelNotes_{}.txt'.format(os.path.basename(os.path.normpath(arch_name)))
make_rel_notes(local_git_repo, rel_notes_file, start_hash_for_RN, end_hash_for_RN)

for file in files_to_release:
abs_file_path = local_git_repo +'/'+file
create_nested_dir(arch_name, file)
if os.path.isdir(abs_file_path):
shutil.copytree(abs_file_path, arch_name + '/' + file)
else:
shutil.copyfile(abs_file_path, arch_name + '/' + file)
shutil.copyfile(rel_notes_file, arch_name + '/' + rel_notes_file)
shutil.make_archive(arch_name, 'zip', arch_name)
print('Release is available at {}'.format(aot_release_dir))


def make_rel_notes(local_git_repo, rel_notes_file, start_hash_for_rn, end_hash_for_rn):
cmd = 'git --git-dir {0}/.git log --pretty=format:%s {2}..{3} > {0}/{1}'.\
format(local_git_repo, rel_notes_file,
start_hash_for_rn, end_hash_for_rn)

print('Executing command : {}'.format(cmd))
os.system(cmd)


def check_path(some_path, path_for):
Expand Down Expand Up @@ -274,6 +391,13 @@ def get_sde_home_absolute():
return dname + '/' + get_sde_dir_name_in_tar()


def get_sal_rel_absolute():
sal_rel_in_config = get_from_setting_dict('SAL', 'sal_rel')
if sal_rel_in_config:
# return absolute path as configured in yaml
return get_path_relative_to_user_home(sal_rel_in_config)


def get_sde_install_dir_absolute():
return get_sde_home_absolute() + '/install'

Expand Down
Loading

0 comments on commit f00592b

Please sign in to comment.