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 Mar 8, 2023
1 parent 2f95ec9 commit cc994a8
Showing 1 changed file with 64 additions and 9 deletions.
73 changes: 64 additions & 9 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function kernel_build()
local llvm
local env_name
local clean
local flag
local output_kbuild_flag=''

parse_build_options "$@"
Expand All @@ -73,6 +74,7 @@ function kernel_build()
output_kbuild_flag=" O=${options_values['ENV_PATH_KBUILD_OUTPUT_FLAG']}"
fi

flag="${options_values['TEST_MODE']}"
cross_compile="${options_values['CROSS_COMPILE']}"
menu_config=${options_values['MENU_CONFIG']}
parallel_cores=${options_values['PARALLEL_CORES']}
Expand All @@ -84,6 +86,8 @@ function kernel_build()
clean=${options_values['CLEAN']}
full_cleanup=${options_values['FULL_CLEANUP']}

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

if [[ -n "${options_values['INFO']}" ]]; then
build_info ''
exit
Expand All @@ -102,7 +106,7 @@ function kernel_build()
fi

if [[ -n "$clean" ]]; then
build_clean "$flag"
build_clean "$flag" "$output_kbuild_flag"
return "$?"
fi

Expand All @@ -118,8 +122,7 @@ function kernel_build()
fi

if [[ -n "$menu_config" ]]; then
command="make -j ${llvm}ARCH=${platform_ops} ${menu_config}${output_kbuild_flag}"
cmd_manager "$flag" "$command"
build_menu_config "$flag" "$output_kbuild_flag" "$menu_config" "$platform_ops" "$llvm"
exit
fi

Expand All @@ -142,11 +145,12 @@ function kernel_build()
fi

if [[ -n "$doc_type" ]]; then
command="make ${optimizations} ${doc_type}${output_path}${output_kbuild_flag}"
cmd_manager "$flag" "$command"
return
build_doc "$flag" "$output_kbuild_flag" "$optimizations" "$doc_type" "$output_path"
return "$?"
fi

flag=${flag:-'SILENT'}

command="make ${optimizations} ${llvm}ARCH=${platform_ops}${warnings}${output_path}${output_kbuild_flag}"

# Let's avoid menu question by default
Expand All @@ -168,6 +172,41 @@ function kernel_build()
return "$ret"
}

# This function runs the make command under the hood, which in this
# context is used to build and configure the linux kernel using the
# "menuconfig" interface.
function build_menu_config()
{
local flag="$1"
local env_path="$2"
local menu_config="$3"
local platform_ops="$4"
local llvm="$5"
local cmd

flag=${flag:-'SILENT'}

cmd="make -j ${llvm}ARCH=${platform_ops} ${menu_config}${env_path}"
say "$cmd"
cmd_manager "$flag" "$cmd"
}

# This function builds kernel-doc, by default it will create htmldocs.
function build_doc()
{
local flag="$1"
local env_path="$2"
local optimizations="$3"
local doc_type="$4"
local output_path="$5"
local cmd
say "$doc_type"
flag=${flag:-'SILENT'}

cmd="make ${optimizations} ${doc_type}${output_path}${env_path}"
cmd_manager "$flag" "$cmd"
}

# This function runs the 'make clean' command under the hood, with
# the advantage of checking if the user is using an env or not.
# In other words, it integrates env with the clean option.
Expand All @@ -181,9 +220,12 @@ function kernel_build()
function build_clean()
{
local flag="$1"
local env_path="$2"
local cmd

cmd="make clean${output_kbuild_flag}"
flag=${flag:-'SILENT'}

cmd="make clean${env_path}"
cmd_manager "$flag" "$cmd"
}

Expand All @@ -196,6 +238,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 @@ -246,8 +290,8 @@ 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 short_options='h,i,n,d,S:,w::,s:,c,f'
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,v'
local doc_type
local file_name_size

Expand All @@ -274,6 +318,8 @@ 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['TEST_MODE']='SILENT'
options_values['VERBOSE']=''

# Check llvm option
if [[ ${options_values['USE_LLVM_TOOLCHAIN']} =~ 'yes' ]]; then
Expand Down Expand Up @@ -324,6 +370,10 @@ function parse_build_options()
options_values['FULL_CLEANUP']=1
shift
;;
--verbose | -v)
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 @@ -352,6 +402,10 @@ function parse_build_options()
--)
shift
;;
TEST_MODE)
options_values['TEST_MODE']='TEST_MODE'
shift
;;
*)
options_values['ERROR']="$1"
return 22 # EINVAL
Expand All @@ -376,6 +430,7 @@ function build_help()
' build (-S | --cpu-scaling) <percentage> - Scale CPU usage by factor' \
' build (--ccache) - Enable use of ccache' \
' build (-w | --warnings) [warning_levels] - Enable warnings' \
' build (-v | --verbose) - Show a detailed output' \
' 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' \
Expand Down

0 comments on commit cc994a8

Please sign in to comment.