Skip to content

Commit

Permalink
src: build: Adding verbose mode.
Browse files Browse the repository at this point in the history
This commit adds support for the verbose parameter within `kw build`.
The verbose parameter gives details of the commands that are executed behind the scenes.

Note: This is part of the issue: kworkflow#179

Signed-off-by: Aquila Macedo <aquilamacedo@riseup.net>
  • Loading branch information
aquilamacedo committed Apr 27, 2023
1 parent cca88c2 commit 87af917
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions documentation/man/features/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SYNOPSIS
| *kw* (*b* | *build*) [\--llvm] [\--alert=(s | v | (sv | vs) | n)]
| *kw* (*b* | *build*) [(-c | \--clean)] [\--alert=(s | v | (sv | vs) | n)]
| *kw* (*b* | *build*) [(-f | \--full-cleanup)] [\--alert=(s | v | (sv | vs) | n)]
| *kw* (*b* | *build*) [\--verbose]
DESCRIPTION
===========
Expand Down Expand Up @@ -83,6 +84,11 @@ OPTIONS
build process, including configuration files and script output. This option also
considers whether or not the user is using kw env.

\--verbose:
Verbose mode is an option that causes the kw program to display debug messages to track
its progress. This functionality is very useful during the debugging process, allowing
you to identify possible errors more easily.

\--alert=(s | v | (sv | vs) | n):
Defines the alert behaviour upon the command completion.
| **s** enables sound notification.
Expand Down
1 change: 1 addition & 0 deletions src/_kw
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ _kw_b() { _kw_build }
_kw_build()
{
_arguments : \
'(--verbose)--verbose[enable verbose mode]' \
'(-i --info -c --clean -n --menu -d --doc --ccache -w --warnings -S --cpu-scaling -s --save-log-to --llvm)'{-i,--info}'[display kernel release name, version and number of modules to compile]' \
'(-c --clean -i --info -n --menu -d --doc --ccache -w --warnings -S --cpu-scaling -s --save-log-to --llvm)'{-c,--clean}'[remove files generated by the kernel build system]' \
'(-n --menu -i --info -c --clean -d --doc)'{-n,--menu}'[invoke kernel menuconfig]' \
Expand Down
2 changes: 1 addition & 1 deletion src/bash_autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function _kw_autocomplete()
kw_options['backup']='--restore --force --help'

kw_options['build']='--menu --info --doc --cpu-scaling --ccache --warnings
--save-log-to --llvm --help --full-cleanup'
--save-log-to --llvm --help --full-cleanup --verbose'
kw_options['b']="${kw_options['build']}"

kw_options['kernel-config-manager']='--fetch --get --list --remove --save --force
Expand Down
22 changes: 20 additions & 2 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ function build_kernel_main()
clean=${options_values['CLEAN']}
full_cleanup=${options_values['FULL_CLEANUP']}

[[ -n "${options_values['VERBOSE']}" ]] && flag='VERBOSE'
flag=${flag:-'SILENT'}

if [[ -n "${options_values['INFO']}" ]]; then
build_info ''
exit
Expand Down Expand Up @@ -178,6 +181,8 @@ function build_menu_config()
local llvm="$5"
local cmd

flag=${flag:-'SILENT'}

cmd="make -j ${llvm}ARCH=${platform_ops} ${menu_config}${env_path}"
cmd_manager "$flag" "$cmd"
}
Expand All @@ -192,6 +197,8 @@ function build_doc()
local output_path="$5"
local cmd

flag=${flag:-'SILENT'}

cmd="make ${optimizations} ${doc_type}${output_path}${env_path}"
cmd_manager "$flag" "$cmd"
}
Expand All @@ -212,6 +219,8 @@ function build_clean()
local env_path="$2"
local cmd

flag=${flag:-'SILENT'}

cmd="make clean${env_path}"
cmd_manager "$flag" "$cmd"
}
Expand All @@ -225,6 +234,8 @@ function full_cleanup()
local env_path="$2"
local cmd

flag=${flag:-'SILENT'}

cmd="make distclean${env_path}"
cmd_manager "$flag" "$cmd"
}
Expand Down Expand Up @@ -275,7 +286,7 @@ function load_build_config()

function parse_build_options()
{
local long_options='help,info,menu,doc,ccache,cpu-scaling:,warnings::,save-log-to:,llvm,clean,full-cleanup'
local long_options='help,info,menu,doc,ccache,cpu-scaling:,warnings::,save-log-to:,llvm,clean,full-cleanup,verbose'
local short_options='h,i,n,d,S:,w::,s:,c,f'
local doc_type
local file_name_size
Expand Down Expand Up @@ -303,6 +314,7 @@ function parse_build_options()
options_values['USE_LLVM_TOOLCHAIN']="${build_config[use_llvm]:-${configurations[use_llvm]}}"
options_values['CLEAN']=''
options_values['FULL_CLEANUP']=''
options_values['VERBOSE']=''

# Check llvm option
if [[ ${options_values['USE_LLVM_TOOLCHAIN']} =~ 'yes' ]]; then
Expand Down Expand Up @@ -353,6 +365,10 @@ function parse_build_options()
options_values['FULL_CLEANUP']=1
shift
;;
--verbose)
options_values['VERBOSE']=1
shift
;;
--doc | -d)
doc_type_fallback="${configurations[doc_type]:-htmldocs}"
options_values['DOC_TYPE']="${build_config[doc_type]:-$doc_type_fallback}"
Expand Down Expand Up @@ -408,7 +424,9 @@ function build_help()
' build (-s | --save-log-to) <path> - Save compilation log to path' \
' build (--llvm) - Enable use of the LLVM toolchain' \
' build (-c | --clean) - Clean option integrated into env' \
' build (-f | --full-cleanup) - Reset the kernel tree to its default option integrated into env'
' build (-f | --full-cleanup) - Reset the kernel tree to its default option integrated into env' \
' build (--verbose) - Show a detailed output'

}

# Every time build.sh is loaded its proper configuration has to be loaded as well
Expand Down
9 changes: 9 additions & 0 deletions tests/build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ function test_parse_build_options_check_options_values()

assert_equals_helper 'Default CLEAN did not match expectation' \
"($LINENO)" '' "${options_values['CLEAN']}"

assert_equals_helper 'Default VERBOSE did not match expectation' \
"($LINENO)" '' "${options_values['VERBOSE']}"
}

function test_parse_build_options()
Expand Down Expand Up @@ -506,6 +509,12 @@ function test_parse_build_options()
assert_equals_helper 'Could not set build option FULL_CLEANUP' \
"($LINENO)" 1 "${options_values['FULL_CLEANUP']}"

# VERBOSE
options_values=()
parse_build_options --verbose
assert_equals_helper 'Could not set build option VERBOSE' \
"($LINENO)" 1 "${options_values['VERBOSE']}"

# Unsopported option
output="$(parse_build_options --mispelled 2>&1)"
assertEquals "($LINENO)" 22 "$?"
Expand Down

0 comments on commit 87af917

Please sign in to comment.