Skip to content

Commit

Permalink
src: build: Add --from-sha <SHA> option
Browse files Browse the repository at this point in the history
Add --from-sha <SHA> option that builds every commit from <SHA> to actual commit
Closes kworkflow#666

Signed-off-by: Marcelo Mendes Spessoto Junior <[email protected]>
  • Loading branch information
MarceloSpessoto committed May 18, 2024
1 parent c2a2388 commit 1183dd7
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 35 deletions.
10 changes: 5 additions & 5 deletions database/migrate_legacy_data_20220101.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function migrate_statistics()
cmd_manager 'SILENT' "mv ${datadir}/statistics ${datadir}/legacy_statistics"
if [[ "$?" != 0 ]]; then
complain "Couldn't rename ${datadir}/statistics ${datadir}/legacy_statistics"
return 1 #EPERM
return 1 # EPERM
fi
}

Expand Down Expand Up @@ -161,7 +161,7 @@ function migrate_pomodoro()
cmd_manager 'SILENT' "mv ${datadir}/pomodoro ${datadir}/legacy_pomodoro"
if [[ "$?" != 0 ]]; then
complain "Couldn't rename ${datadir}/pomodoro ${datadir}/legacy_pomodoro"
return 1 #EPERM
return 1 # EPERM
fi
}

Expand Down Expand Up @@ -216,20 +216,20 @@ function migrate_kernel_configs()
cmd_manager 'SILENT' "cp -r ${configs_dir}/. ${datadir}/configs"
if [[ "$?" != 0 ]]; then
complain "Couldn't copy kernel config files from ${configs_dir} to ${datadir}/configs"
return 1 #EPERM
return 1 # EPERM
fi

# mark migrated directories to avoid duplicated data
cmd_manager 'SILENT' "mv ${datadir}/configs/configs ${datadir}/configs/legacy_configs"
if [[ "$?" != 0 ]]; then
complain "Couldn't rename ${datadir}/configs/configs to ${datadir}/configs/legacy_configs"
return 1 #EPERM
return 1 # EPERM
fi

cmd_manager 'SILENT' "mv ${datadir}/configs/metadata ${datadir}/configs/legacy_metadata"
if [[ "$?" != 0 ]]; then
complain "Couldn't rename ${datadir}/configs/metadata to ${datadir}/configs/legacy_metadata"
return 1 #EPERM
return 1 # EPERM
fi
}

Expand Down
9 changes: 9 additions & 0 deletions documentation/man/features/kw-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SYNOPSIS
| *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*) [\--cflags]
| *kw* (*b* | *build*) [\--from-sha <SHA>]
| *kw* (*b* | *build*) [\--verbose]
DESCRIPTION
Expand Down Expand Up @@ -102,6 +103,10 @@ OPTIONS
| **sv** or **vs** enables both.
| **n** (or any other option) disables notifications (this is the default).
\--from-sha:
Build every commit from <SHA> to branch head. Useful for testing if all patches in
patchset compiles.

EXAMPLES
========
For these examples, we suppose the fields in your **kworkflow.config** file are
Expand Down Expand Up @@ -158,3 +163,7 @@ If you want to reset the kernel tree to its default, `all config and script outp
If you want to use cflags::

kw b --cflags "-O3 -pipe -march=native"

If you want to build every commit from HEAD~2 to HEAD::

kw b --from-sha HEAD~2
9 changes: 9 additions & 0 deletions documentation/tutorials/buildlinux.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ Well, that's it. kw will automatically infer the number of job slots for
compiling based on the number of cores of your machine (i.e. when running make
``-j<number>``, *<number>* is an integer that specifies the number of processes
that will run at the same time), and compilation will begin!

Compiling patchsets
-------------------
You may want to try compiling every patch in your patchset to test if everything is alright.
You can do this by using the "from-sha" flag::

kw build --from-sha SHA

This will compile every path from the commit with given SHA to the branch HEAD.
2 changes: 1 addition & 1 deletion kw
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function kw()

complain 'Invalid option'
kworkflow_help
return 1
return 1 # EPERM
)
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function report_results()
done
fi

return 1
return 1 # EPERM
fi
}

Expand Down
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ function setup_global_config_file()
fi
else
warning "setup could not find $config_file_template"
return 2
return 2 # ENOENT
fi
}

Expand Down
4 changes: 2 additions & 2 deletions src/_kw
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ _kw_build()
'(-S --cpu-scaling -i --info -c --clean -f --full-cleanup --cflags)'{-S,--cpu-scaling}'[set CPU usage]:scaling percentage: ' \
'(-s --save-log-to -i --info -c --clean -f --full-cleanup --cflags)'{-s,--save-log-to}'[save full compilation log with the enabled warnings to the specified path]:log path:_files' \
'(-i --info -c --clean -f --full-cleanup --cflags)--llvm[enable the usage of the LLVM toolchain]' \
'(-i --info -c --clean -f --full-cleanup -n --menu -d --doc --ccache -w --warnings -S --cpu-scaling -s --save-log-to --llvm --cflags)--cflags[customize kernel compilation with specific flags]'

'(-i --info -c --clean -f --full-cleanup -n --menu -d --doc --ccache -w --warnings -S --cpu-scaling -s --save-log-to --llvm --cflags)--cflags[customize kernel compilation with specific flags]' \
'(-i --info -c --clean -f --full-cleanup -n --menu -d --doc --ccache -w --warnings -S --cpu-scaling -s --save-log-to --llvm --cflags --from-sha)--from-sha[Compile all commits from given sha value to branch head]: :'
}

_kw_clear-cache()
Expand Down
2 changes: 1 addition & 1 deletion src/bash_autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function _kw_autocomplete()
kw_options['init']='--arch --remote --target --force --template --verbose'

kw_options['build']='--help --info --menu --cpu-scaling --ccache --llvm --clean
--full-cleanup --verbose --doc --warnings --save-log-to --cflags'
--full-cleanup --verbose --doc --warnings --save-log-to --cflags --from-sha'

kw_options['b']="${kw_options['build']}"

Expand Down
73 changes: 71 additions & 2 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function build_kernel_main()
local clean
local output_kbuild_flag=''
local cflags
local from_sha_arg
local sha_base
local merge_base

parse_build_options "$@"

Expand All @@ -59,6 +62,7 @@ function build_kernel_main()
clean=${options_values['CLEAN']}
full_cleanup=${options_values['FULL_CLEANUP']}
cflags=${options_values['CFLAGS']}
from_sha_arg=${options_values['FROM_SHA_ARG']}

[[ -n "${options_values['VERBOSE']}" ]] && flag='VERBOSE'
flag=${flag:-'SILENT'}
Expand Down Expand Up @@ -124,6 +128,41 @@ function build_kernel_main()
return "$?"
fi

if [[ -n "$from_sha_arg" ]]; then
# Check if there is a rebase in process.
if [[ -d .git/rebase-merge ]]; then
printf '%s\n' 'ERROR: Abort the repository rebase before continuing with build from sha (use "git rebase --abort")!'
return 22 #EINVAL
elif [[ -f .git/MERGE_HEAD ]]; then
printf '%s\n' 'ERROR: Abort the repository merge before continuing with build from sha (use "git rebase --abort")!'
return 22 #EINVAL
elif [[ -f .git/BISECT_LOG ]]; then
printf '%s\n' 'ERROR: Stop the repository bisect before continuing with build from sha (use "git bisect reset")!'
return 22 #EINVAL
elif [[ -d .git/rebase-apply ]]; then
printf '%s\n' 'ERROR: Abort the repository patch apply before continuing with build from sha (use "git am --abort")!'
return 22 #EINVAL
fi

# Check if given SHA represents real commit
cmd_manager "SILENT" "git cat-file -e ${from_sha_arg}^{commit} 2> /dev/null"
if [[ "$?" != 0 ]]; then
printf '%s\n' 'ERROR: The given SHA does not represent a valid commit sha.'
return 22 #EINVAL
fi

# Check if given SHA is in working tree.
sha_base=$(git rev-parse --verify "$from_sha_arg")
merge_base=$(git merge-base "$from_sha_arg" HEAD)
if [[ "$sha_base" != "$merge_base" ]]; then
printf '%s\n' 'ERROR: Given SHA is invalid. Check if it is an ancestor of the branch head.'
return 22 #EINVAL
fi

build_from_sha "$flag" "$from_sha_arg"
return "$?"
fi

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

if [[ -n "$cflags" ]]; then
Expand Down Expand Up @@ -247,9 +286,33 @@ function full_cleanup()
cmd_manager "$flag" "$cmd"
}

# This functions uses iteractive 'git rebase' with '--exec' flag under the hood
# to apply a 'kw build' over each commit from SHA to branch head.
#
# @flag How to display a command, see `src/lib/kwlib.sh` function `cmd_manager`.
# @sha The SHA from the first commit to be compiled until the branch head.
#
# Return:
# 0 if successfully compiled patchset, 1 otherwise.
function build_from_sha()
{
local flag="$1"
local sha="$2"
local cmd

flag=${flag:-'SILENT'}
cmd="git rebase ${sha} --exec 'kw build'"
cmd_manager "$flag" "$cmd"

if [[ "$?" != 0 ]]; then
printf '%s\n' 'kw build failed during the compilation of a patch! Check the rebase in progress for more information.'
return 1
fi
}

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

# Check llvm option
if [[ ${options_values['USE_LLVM_TOOLCHAIN']} =~ 'yes' ]]; then
Expand Down Expand Up @@ -362,6 +426,10 @@ function parse_build_options()
options_values['LOG_PATH']="$2"
shift 2
;;
--from-sha)
options_values['FROM_SHA_ARG']="$2"
shift 2
;;
--)
shift
;;
Expand Down Expand Up @@ -394,7 +462,8 @@ function build_help()
' build (-c | --clean) - Clean option integrated into env' \
' build (-f | --full-cleanup) - Reset the kernel tree to its default option integrated into env' \
' build (--cflags) - Customize kernel compilation with specific flags' \
' build (--verbose) - Show a detailed output'
' build (--verbose) - Show a detailed output' \
' build (--from-sha <SHA>) - Build all commits from <SHA> to actual commit'
}

# Every time build.sh is loaded its proper configuration has to be loaded as well
Expand Down
6 changes: 3 additions & 3 deletions src/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function debug_main()
if [[ "$?" -gt 0 ]]; then
complain "Invalid option: ${options_values['ERROR']}"
debug_help
return 22
return 22 # EINVAL
fi

test_mode="${options_values['TEST_MODE']}"
Expand Down Expand Up @@ -961,7 +961,7 @@ function parser_debug_options()
populate_remote_info "$2"
if [[ "$?" == 22 ]]; then
options_values['ERROR']="$option"
return 22
return 22 # EINVAL
fi
options_values['TARGET']="$REMOTE_TARGET"
shift 2
Expand Down Expand Up @@ -1029,7 +1029,7 @@ function parser_debug_options()
;;
*)
options_values['ERROR']="$1"
return 22
return 22 # EINVAL
;;
esac
done
Expand Down
2 changes: 1 addition & 1 deletion src/kernel_config_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function get_config_from_proc()
case "$target" in
1) # VM
# We do not support this option with VM
return 95
return 95 # ENOTSUP
;;
2) # LOCAL
# Try to find /proc/config, if we cannot find, attempt to load the module
Expand Down
2 changes: 1 addition & 1 deletion src/kw_remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ function parse_remote_options()
return 22 # EINVAL
elif [[ "${options_values['DEFAULT_REMOTE']}" == 1 ]]; then
options_values['ERROR']='Expected a string values after --set-default='
return 22
return 22 # EINVAL
elif [[ -z "${options_values['ADD']}" && -z "${options_values['REMOVE']}" &&
-z "${options_values['RENAME']}" && -z "${options_values['LIST']}" &&
-z "${options_values['DEFAULT_REMOTE']}" ]]; then
Expand Down
4 changes: 2 additions & 2 deletions src/kw_ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function parser_ssh_options()
populate_remote_info "$2"
if [[ "$?" == 22 ]]; then
options_values['ERROR']="$option"
return 22
return 22 # EINVAL
fi
shift 2
;;
Expand Down Expand Up @@ -357,7 +357,7 @@ function parser_ssh_options()
;;
*)
options_values['ERROR']="$1"
return 22
return 22 # EINVAL
;;
esac
done
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dialog_ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ function prettify_string()
local variable_to_concatenate="$2"

if [[ -z "$fixed_text" || -z "$variable_to_concatenate" ]]; then
return 22
return 22 # EINVAL
fi

printf '\Zb\Z6%s\Zn%s\\n' "$fixed_text" "$variable_to_concatenate"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/kw_string.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function str_is_a_number()

value=$(str_strip "$value")
[[ "$value" =~ ^[-]?[0-9]+$ ]] && return 0
return 1
return 1 # EPERM
}

# Calculate the length of a string
Expand Down Expand Up @@ -206,7 +206,7 @@ function str_has_special_characters()
local str="$*"

[[ "$str" == *['!'@#\$%^\&*\(\)+]* ]] && return 0
return 1
return 1 # EPERM
}

# Get value under double-quotes. This function only returns the first match if
Expand Down
6 changes: 3 additions & 3 deletions src/lib/kwlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function is_kernel_root()
-d "${DIR}/scripts" ]]; then
return 0
fi
return 1
return 1 # EPERM
}

# Finds the root of the linux kernel repo containing the given file
Expand Down Expand Up @@ -268,7 +268,7 @@ function is_a_patch()
local file_content

if [[ ! -f "$FILE_PATH" ]]; then
return 1
return 1 # EPERM
fi

file_content=$(< "$FILE_PATH")
Expand All @@ -284,7 +284,7 @@ function is_a_patch()

for expected_str in "${PATCH_EXPECTED_STRINGS[@]}"; do
if [[ ! "$file_content" =~ $expected_str ]]; then
return 1
return 1 # EPERM
fi
done

Expand Down
2 changes: 1 addition & 1 deletion src/lib/remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function is_ssh_connection_configured()
ret="$?"

# User canceled the manual update
[[ "$ret" == 125 ]] && return 125
[[ "$ret" == 125 ]] && return 125 # ECANCELED
# Some other unknown error occurred
[[ "$ret" != 0 ]] && return 101 # ENETUNREACH

Expand Down
2 changes: 1 addition & 1 deletion src/lib/web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function is_html_file()

grep --silent '\(<head>\|<body>\)' "$file_path"
[[ "$?" == 0 ]] && return 0
return 1
return 1 # EPERM
}

# This function recieves a string and converts it to contain only characters that
Expand Down
2 changes: 1 addition & 1 deletion src/mail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ function mail_verify()
if [[ "${#missing_conf}" -gt 0 ]]; then
complain 'Missing configurations required for send-email:'
printf ' %s\n' "${missing_conf[@]}"
return 22
return 22 # EINVAL
fi

success 'It looks like you are ready to send patches as:'
Expand Down
Loading

0 comments on commit 1183dd7

Please sign in to comment.