Skip to content

Commit

Permalink
kw: remove kw vars
Browse files Browse the repository at this point in the history
Completely remove kw vars functionality as this feature has been
deprecated by the kw config --show functionality.

This commit does the following:
* change documentation to recommend kw config --show instead of kw vars
* remove kw vars documentation and base code
* remove show_variables_main function used internally by kw vars and its
  tests

Closes: kworkflow#1026

Reviewed-by: David Tadokoro <[email protected]>
Signed-off-by: Marcelo Mendes Spessoto Junior <[email protected]>
Signed-off-by: David Tadokoro <[email protected]>
  • Loading branch information
MarceloSpessoto authored and davidbtadokoro committed Feb 22, 2024
1 parent d1556d2 commit 9e40555
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 249 deletions.
1 change: 0 additions & 1 deletion documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
('man/features/kw-pomodoro', 'kw-pomodoro', 'pomodoro style time management', [author], 1),
('man/features/kw-report', 'kw-report', 'user data report support', [author], 1),
('man/features/kw-ssh', 'kw-ssh', 'ssh access', [author], 1),
('man/features/kw-vars', 'kw-vars', 'view kw config values', [author], 1),
('man/features/kw-vm', 'kw-vm', 'commands to work with QEMU VMs', [author], 1),
('man/features/kw-self-update', 'kw-self-update', 'kw self-update mechanism', ['David Tadokoro, Everaldo Junior'], 1),
('man/features/kw-patch-hub', 'kw-patch-hub', 'UI with lore.kernel.org archives', ['David Tadokoro, Rodrigo Siqueira'], 1),
Expand Down
14 changes: 0 additions & 14 deletions documentation/man/features/kw-vars.rst

This file was deleted.

1 change: 0 additions & 1 deletion documentation/man/kw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ the previous sections.
| :ref:`kw-device<device-doc>`
| :ref:`kw-ssh<ssh-doc>`
| :ref:`kw-kernel-config-manager<kernel-config-manager-doc>`
| :ref:`kw-vars<vars-doc>`
| :ref:`kw-diff<diff-doc>`
| :ref:`kw-report<report-doc>`
| :ref:`kw-pomodoro<pomodoro-doc>`
Expand Down
4 changes: 2 additions & 2 deletions documentation/tutorials/kw-env.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Let's say that you want to switch from one config to another, you can just use::

If you want to check if everything looks correct, you can use::

kw vars
kw config --show

How to customize your bash terminal to display the current environment
----------------------------------------------------------------------
Expand All @@ -90,4 +90,4 @@ Once enabled, you need to add the following line to the .bashrc file::
.. note::
If you have modified the PS1 variable in the .bashrc file, you will need to adapt
it to work correctly. You can simply call the ``kw_get_current_env_name`` function
on PS1 to display the current environment being used in kworkflow.
on PS1 to display the current environment being used in kworkflow.
2 changes: 1 addition & 1 deletion documentation/tutorials/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ When configuring kw, you might want to start looking at theses options:

After making some changes, check that kw is incorporating them with::

kw vars
kw config --show

which simply shows all the defined configuration options.

Expand Down
7 changes: 0 additions & 7 deletions kw
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ function kw()
kw_ssh_main "$@"
)
;;
vars)
(
include "${KW_LIB_DIR}/lib/kw_config_loader.sh"

show_variables_main "$@"
)
;;
codestyle | c)
(
include "${KW_LIB_DIR}/codestyle.sh"
Expand Down
8 changes: 1 addition & 7 deletions src/_kw
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ _kw()
'self-update:kw self-update mechanism'
'ssh:SSH support'
'patch-hub: Open UI with lore.kernel.org archives'
'vars:Show variables'
'version:Show kw version'
)

Expand Down Expand Up @@ -406,7 +405,7 @@ _kw_man()
_values 'kw commands' \
'backup' 'build' 'codestyle' 'config' 'debug' 'deploy' 'device' 'diff' 'drm' 'env' \
'explore' 'init' 'mail' 'maintainers' 'pomodoro' 'remote' 'report' 'self-update' 'ssh' \
'patch-hub' 'vars'
'patch-hub'
}

_kw_p() { _kw_pomodoro }
Expand Down Expand Up @@ -506,11 +505,6 @@ _kw_patch-hub()
_nothing
}

_kw_vars()
{
_nothing
}

_kw_version()
{
_nothing
Expand Down
2 changes: 1 addition & 1 deletion src/bash_autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function _kw_autocomplete()
current_command="${COMP_WORDS[$COMP_CWORD]}"
previous_command="${COMP_WORDS[$comp_curr - 1]}"

kw_options['kw']='init build deploy bd diff ssh vars codestyle self-update
kw_options['kw']='init build deploy bd diff ssh codestyle self-update
maintainers kernel-config-manager config remote explore
pomodoro report device backup debug mail env patch-hub
clear-cache drm vm version man help'
Expand Down
1 change: 0 additions & 1 deletion src/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function kworkflow_help()
' bd - Build and install kernel image/modules' \
' diff,df - Diff files' \
' ssh,s - SSH support' \
' vars - Show kw variables' \
' codestyle,c - Apply checkpatch on directory or file' \
' self-update,u - kw self-update mechanism' \
' maintainers,m - Get maintainers and mailing list' \
Expand Down
108 changes: 0 additions & 108 deletions src/lib/kw_config_loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,103 +56,6 @@ declare -gA lore_config_local
# Default target option from kworkflow.config
declare -gA deploy_target_opt=(['local']=2 ['remote']=3)

# This function is used to show the current set up used by kworkflow.
function show_variables_main()
{
local test_mode=0
local has_local_config='No'

load_all_config

if [[ "$1" =~ ^-h|^--help ]]; then
vars_help "$@"
exit 0
fi

# TODO: Drop [[ -f "$PWD/$CONFIG_FILENAME" ]] in the future
if [[ -f "${PWD}/${KW_DIR}/${CONFIG_FILENAME}" || -f "${PWD}/${CONFIG_FILENAME}" ]]; then
has_local_config='Yes'
fi

if [[ "$1" == 'TEST_MODE' ]]; then
test_mode=1
fi

local -Ar ssh=(
[ssh_user]='SSH user'
[ssh_ip]='SSH address'
[ssh_port]='SSH port'
[ssh_configfile]='SSH configuration file'
[hostname]='Hostname of the target in the SSH configuration file'
)

local -Ar misc=(
[disable_statistics_data_track]='Disable tracking of statistical data'
[gui_on]='Command to activate GUI'
[gui_off]='Command to deactivate GUI'
[checkpatch_opts]='Options to be used in the checkpatch script'
[get_maintainer_opts]='Options to be used in the get_maintainer script'
)

local -Ar group_descriptions=(
[build]='Kernel build options'
[deploy]='Kernel deploy options'
[mail]='Send-email options'
[ssh]='SSH options'
[vm]='VM options'
[notification]='Notification options'
[misc]='Miscellaneous options'
[lore]='Upstream patches from Lore options'
)

groups=(
'deploy'
'mail'
'ssh'
'vm'
'notification'
'misc'
'build'
'lore'
)

say 'kw configuration variables:'
printf '%s\n' " Local config file: $has_local_config"

for group in "${groups[@]}"; do
local -n descriptions="$group"
case "$group" in
'build')
show_build_variables "$@"
continue
;;
'deploy')
show_deploy_variables "$@"
continue
;;
'mail')
show_mail_variables "$@"
continue
;;
'notification')
show_notification_variables "$@"
continue
;;
'vm')
show_vm_variables "$@"
continue
;;
'lore')
show_lore_variables "$@"
continue
;;
esac

printf '%s\n' " ${group_descriptions["$group"]}:"
print_array configurations descriptions "$test_mode"
done
}

# This is a helper function that prints the option description followed by the
# option value.
#
Expand Down Expand Up @@ -505,14 +408,3 @@ load_all_config()
load_lore_config
load_vm_config
}

function vars_help()
{
if [[ "$1" == --help ]]; then
include "$KW_LIB_DIR/help.sh"
kworkflow_man 'vars'
return
fi
printf '%s\n' 'kw vars:' \
' vars - Show current variable values being used by kw.'
}
106 changes: 0 additions & 106 deletions tests/unit/lib/kw_config_loader_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,112 +253,6 @@ function get_all_assigned_options_to_string_helper()
printf '%s' "$output"
}

function test_show_variables_main_completeness()
{
local -A shown_options
local -A possible_options
local output
local output_vm
local output_mail
local output_build
local output_deploy
local output_notification

configurations=()

# get all assigned options, including commented ones
# remove #'s and ='s to get option names
output=$(get_all_assigned_options_to_string_helper "$KW_CONFIG_TEMPLATE")
output_build="$(get_all_assigned_options_to_string_helper "$KW_BUILD_CONFIG_SAMPLE")"
output_deploy="$(get_all_assigned_options_to_string_helper "$KW_DEPLOY_CONFIG_SAMPLE")"
output_vm="$(get_all_assigned_options_to_string_helper "$KW_VM_CONFIG_SAMPLE")"
output_mail="$(get_all_assigned_options_to_string_helper "$KW_MAIL_CONFIG_SAMPLE")"
output_notification="$(get_all_assigned_options_to_string_helper "$KW_NOTIFICATION_CONFIG_SAMPLE")"

output+=" $output_build $output_deploy $output_vm $output_mail $output_notification"
for option in $output; do
possible_options["$option"]=1
done

cp "$KW_CONFIG_SAMPLE" "$TMPDIR_KW_FOLDER"
cp "$KW_BUILD_CONFIG_SAMPLE" "$TMPDIR_KW_FOLDER"
cp "$KW_VM_CONFIG_SAMPLE" "$TMPDIR_KW_FOLDER"
cp "$KW_MAIL_CONFIG_SAMPLE" "$TMPDIR_KW_FOLDER"
cp "$KW_NOTIFICATION_CONFIG_SAMPLE" "$TMPDIR_KW_FOLDER"
cp "${SAMPLES_DIR}/deploy_all_options.config" "${TMPDIR_KW_FOLDER}/deploy.config"

load_all_config

output="$(show_variables_main 'TEST_MODE' | grep -E '^ ')"
output="$(printf '%s\n' "$output" | sed 's/.*(\(\S*\)).*/\1/')"

for option in $output; do
shown_options["$option"]=1
done

assert_configurations_helper possible_options shown_options "$LINENO"
}

function test_show_variables_main_correctness()
{
local output
local option
local value
local message

# show_variables_main will load the config file, and for this test we want to
# avoid this behaviour. For this reason, we are deleting the .kw folder
rm -rf .kw

declare -gA configurations=(
[ssh_ip]=1
[ssh_port]=2
[mount_point]='/home/lala'
[menu_config]=4
[virtualizer]='libvirt'
[qemu_hw_options]=6
[qemu_net_options]=7
[qemu_path_image]='/home/xpto/p/virty.qcow2'
[alert]='n'
[sound_alert_command]='paplay SOUNDPATH/bell.wav'
[visual_alert_command]='notify-send lala'
[default_deploy_target]=vm
[reboot_after_deploy]='no'
[deploy_temporary_files_path]='/tmp/kw'
[dtb_copy_pattern]='broadcom/*.dtb'
[strip_modules_debug_option]='yes'
[deploy_default_compression]='lzop'
[kw_files_remote_path]='/opt/kw'
[send_opts]='--annotate --cover-letter --no-chain-reply-to --thread'
[blocked_emails]='[email protected]'
[disable_statistics_data_track]=14
[gui_on]=15
[gui_off]=16
)

output="$(show_variables_main | grep -E '^\s{3,}')"

# The `read` command will read all the characters untill it finds a newline
# character and then write those characters onto the given variable (in this
# case, the `line` variable). If it does not find a newline `\n` character, it
# will exit with status code 1. This evaluates to false, which means the
# shellscript exits the loop. Therefore, if the last line is not empty but
# misses the newline character, the loop won't be run and the last config
# option won't be read. We handle this edge case by checking if line is not
# empty and proceeding to run the loop once more if necessary.
#
# shellcheck disable=SC2162
while read -r line || [[ -n "$line" ]]; do
option="$(printf '%s\n' "$line" | sed -E 's/.*\((\S*)\).*/\1/')"
value=$(printf '%s\n' "$line" | sed -E 's/.*: (.*)/\1/')
if [[ "${configurations[$option]}" != "$value" ]]; then
message="Value of option $option should be "
message+="${configurations["$option"]} but is $value"
fail "($LINENO): $message"
fi
done <<< "$output"
}

function test_load_configuration()
{
local msg='We will stop supporting kworkflow.config in the kernel root directory in favor of using a .kw/ directory.'
Expand Down

0 comments on commit 9e40555

Please sign in to comment.