diff options
-rw-r--r-- | include/git.sh | 12 | ||||
-rw-r--r-- | include/lib.sh | 55 | ||||
-rw-r--r-- | include/vendor.sh | 30 | ||||
-rwxr-xr-x | mk | 25 |
4 files changed, 73 insertions, 49 deletions
diff --git a/include/git.sh b/include/git.sh index 4fa904ba..272a1af3 100644 --- a/include/git.sh +++ b/include/git.sh @@ -9,8 +9,6 @@ tmpgit="$xbmkpwd/tmp/gitclone" fetch_targets() { - [ -n "$tree_depend" ] && [ "$tree_depend" != "$tree" ] && \ - x_ ./mk -f "$project" "$tree_depend" e "src/$project/$tree" d && return 0 printf "Creating %s tree %s\n" "$project" "$tree" @@ -21,7 +19,7 @@ fetch_targets() fetch_project() { - eval "`setvars "" xtree tree_depend`" + eval "`setvars "" xtree`" eval "`setcfg "config/git/$project/pkg.cfg"`" chkvars url @@ -61,12 +59,6 @@ git_prep() done < "$mdir/module.list"; : fi - if [ "$project" = "coreboot" ] && [ -n "$xtree" ] && [ $# -gt 2 ] && \ - [ "$xtree" != "$tree" ]; then ( - x_ cd "$tmpgit/util" && x_ rm -Rf crossgcc - x_ ln -s "../../$xtree/util/crossgcc" crossgcc - ) || $err "$_loc: !xgcc link"; fi - [ "$_loc" != "$XBMK_CACHE/repo/$project" ] && \ [ "$XBMK_RELEASE" = "y" ] && rmgit "$tmpgit" @@ -90,7 +82,7 @@ fetch_submodule() [ -z "$st" ] && return 0 # subrepo/subfile not defined chkvars "sub${st}" "sub${st}_bkup" "subhash" - [ "$st" = "file" ] && download "$subfile" "$subfile_bkup" \ + [ "$st" = "file" ] && xbmkget "$subfile" "$subfile_bkup" \ "$tmpgit/$1" "$subhash" && return 0 rm -Rf "$tmpgit/$1" || $err "!rm '$mdir' '$1'" tmpclone "$subrepo" "$subrepo_bkup" "$tmpgit/$1" "$subhash" \ diff --git a/include/lib.sh b/include/lib.sh index cd3e14ae..f4e96c90 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -98,15 +98,52 @@ for fv in version versiondate; do eval "[ ! -f \".$fv\" ] || read -r $fv < \".$fv\" || :" done +# Use direct path, to prevent a hang if Python is using a virtual environment, +# not command -v, to prevent a hang when checking python's version +# See: https://docs.python.org/3/library/venv.html#how-venvs-work +pybin() +{ + py="import sys; quit(1) if sys.prefix == sys.base_prefix else quit(0)" + + venv=1 + command -v "$1" 1>/dev/null 2>/dev/null || venv=0 + [ $venv -lt 1 ] || "$1" -c "$py" 1>/dev/null 2>/dev/null || venv=0 + + # ideally, don't rely on PATH or hardcoded paths if python venv. + # use the *real*, direct executable linked to by the venv symlink + if [ $venv -gt 0 ] && [ -L "`command -v "$1" 2>/dev/null`" ]; then + # realpath isn't posix, but available mostly universally + pypath="$(realpath \ + "$(command -v "$1" 2>/dev/null)" 2>/dev/null || :)" + [ -e "$pypath" ] && [ ! -d "$pypath" ] && \ + [ -x "$pypath" ] && printf "%s\n" "$pypath" && return 0; : + fi + + # if python venv: fall back to common PATH directories for checking + [ $venv -gt 0 ] && for pypath in "/usr/local/bin" "/usr/bin"; do + [ -e "$pypath/$1" ] && [ ! -d "$pypath/$1" ] && \ + [ -x "$pypath/$1" ] && printf "%s/%s\n" "$pypath" "$1" && \ + return 0 + done + [ $venv -gt 0 ] && return 1 + + # Defer to normal command -v if not a venv + command -v "$1" 2>/dev/null || return 1 +} + python="python3" -command -v python3 1>/dev/null || python="python" +pybin python3 1>/dev/null || python="python" pyver="2" && [ "$python" = "python3" ] && pyver="3" -command -v $python 1>/dev/null || pyver="" -[ -z "$pyver" ] || $python -c 'import sys; print(sys.version_info[:])' \ - 1>/dev/null 2>/dev/null || $err "Cannot detect host Python version." -[ -n "$pyver" ] && \ - pyver="`$python -c 'import sys; print(sys.version_info[:])' | \ - awk '{print $1}'`" && pyver="${pyver#(}" && pyver="${pyver%,}" +pybin "$python" 1>/dev/null || pyver="" +[ -z "$pyver" ] || "`pybin "$python"`" -c \ + 'import sys; print(sys.version_info[:])' 1>/dev/null 2>/dev/null || \ + $err "Cannot detect host Python version." +if [ -n "$pyver" ]; then + pyver="$("$(pybin "$python")" -c \ + 'import sys; print(sys.version_info[:])' | awk '{print $1}')" + pyver="${pyver#(}" + pyver="${pyver%,}" +fi [ "${pyver%%.*}" = "3" ] || $err "Wrong python version (must be v 3.x)" # XBMK_CACHE is a directory, for caching downloads and git repositories @@ -133,7 +170,7 @@ if [ -z "${TMPDIR+x}" ]; then # set up python v3.x in PATH, in case it's not set up correctly. # see code above that detected the correct python3 command. cd "$XBMK_CACHE/xbmkpath" || $err "can't cd $XBMK_CACHE/xbmkpath" - x_ ln -s "`command -v "$python"`" python + x_ ln -s "`pybin "$python"`" python ) || $err "Can't set up python symlink in $XBMK_CACHE/xbmkpath" xbmk_rval=0 @@ -228,7 +265,7 @@ singletree() # can grab from the internet, or copy locally. # if copying locally, it can only copy a file. -download() +xbmkget() { _dlop="curl" && [ $# -gt 4 ] && _dlop="$5" cached="$XBMK_CACHE/file/$4" diff --git a/include/vendor.sh b/include/vendor.sh index c4e57069..4ee593ea 100644 --- a/include/vendor.sh +++ b/include/vendor.sh @@ -38,7 +38,7 @@ eval "`setvars "" has_hashes EC_hash DL_hash DL_url_bkup MRC_refcode_gbe vcfg \ TBFW_hash TBFW_size hashfile xromsize xchanged EC_url_bkup need_files \ vfile cbcfg $cv`" -vendor_download() +download() { [ $# -gt 0 ] || $err "No argument given" export PATH="$PATH:/sbin" @@ -118,7 +118,7 @@ fetch() fi dlop="curl" && [ $# -gt 5 ] && dlop="$6" - download "$dl" "$dl_bkup" "$_dl" "$dlsum" "$dlop" + xbmkget "$dl" "$dl_bkup" "$_dl" "$dlsum" "$dlop" rm -Rf "${_dl}_extracted" || $err "!rm ${_ul}_extracted. $dontflash" e "$_dest" f && return 0 @@ -318,7 +318,7 @@ fail_inject() err_ "$1" } -vendor_inject() +inject() { need_files="n" err="fail_inject" @@ -503,31 +503,31 @@ patch_rom() return 1 fi - [ -n "$CONFIG_HAVE_REFCODE_BLOB" ] && inject "fallback/refcode" \ + [ -n "$CONFIG_HAVE_REFCODE_BLOB" ] && insert "fallback/refcode" \ "$CONFIG_REFCODE_BLOB_FILE" "stage" - [ "$CONFIG_HAVE_MRC" = "y" ] && inject "mrc.bin" "$CONFIG_MRC_FILE" \ + [ "$CONFIG_HAVE_MRC" = "y" ] && insert "mrc.bin" "$CONFIG_MRC_FILE" \ "mrc" "0xfffa0000" - [ "$CONFIG_HAVE_ME_BIN" = "y" ] && inject IFD "$CONFIG_ME_BIN_PATH" me - [ "$CONFIG_KBC1126_FIRMWARE" = "y" ] && inject ecfw1.bin \ - "$CONFIG_KBC1126_FW1" raw "$CONFIG_KBC1126_FW1_OFFSET" && inject \ + [ "$CONFIG_HAVE_ME_BIN" = "y" ] && insert IFD "$CONFIG_ME_BIN_PATH" me + [ "$CONFIG_KBC1126_FIRMWARE" = "y" ] && insert ecfw1.bin \ + "$CONFIG_KBC1126_FW1" raw "$CONFIG_KBC1126_FW1_OFFSET" && insert \ ecfw2.bin "$CONFIG_KBC1126_FW2" raw "$CONFIG_KBC1126_FW2_OFFSET" [ -n "$CONFIG_VGA_BIOS_FILE" ] && [ -n "$CONFIG_VGA_BIOS_ID" ] && \ - inject "pci$CONFIG_VGA_BIOS_ID.rom" "$CONFIG_VGA_BIOS_FILE" optionrom + insert "pci$CONFIG_VGA_BIOS_ID.rom" "$CONFIG_VGA_BIOS_FILE" optionrom [ "$CONFIG_INCLUDE_SMSC_SCH5545_EC_FW" = "y" ] && \ [ -n "$CONFIG_SMSC_SCH5545_EC_FW_FILE" ] && \ - inject sch5545_ecfw.bin "$CONFIG_SMSC_SCH5545_EC_FW_FILE" raw + insert sch5545_ecfw.bin "$CONFIG_SMSC_SCH5545_EC_FW_FILE" raw [ -z "$CONFIG_FSP_USE_REPO" ] && [ -z "$CONFIG_FSP_FULL_FD" ] && \ [ -n "$CONFIG_FSP_M_FILE" ] && \ - inject "$CONFIG_FSP_M_CBFS" "$CONFIG_FSP_M_FILE" fsp --xip + insert "$CONFIG_FSP_M_CBFS" "$CONFIG_FSP_M_FILE" fsp --xip [ -z "$CONFIG_FSP_USE_REPO" ] && [ -z "$CONFIG_FSP_FULL_FD" ] && \ [ -n "$CONFIG_FSP_S_FILE" ] && \ - inject "$CONFIG_FSP_S_CBFS" "$CONFIG_FSP_S_FILE" fsp + insert "$CONFIG_FSP_S_CBFS" "$CONFIG_FSP_S_FILE" fsp printf "ROM image successfully patched: %s\n" "$rom" xchanged="y" } -inject() +insert() { [ "$2" = "/dev/null" ] && return 0 @@ -541,7 +541,7 @@ inject() [ $# -gt 3 ] && _offset="$4" else [ $# -gt 3 ] && _offset="-b $4" && [ -z "$4" ] && \ - $err "inject $*, $rom: offset given but empty (undefined)" + $err "insert $*, $rom: offset given but empty (undefined)" fi [ "$nukemode" = "nuke" ] || x_ e "$_dest" f @@ -549,7 +549,7 @@ inject() if [ "$cbfsname" = "IFD" ]; then [ "$nukemode" = "nuke" ] || "$ifdtool" $ifdprefix -i \ $_t:$_dest "$rom" -O "$rom" || \ - $err "failed: inject '$_t' '$_dest' on '$rom'" + $err "failed: insert '$_t' '$_dest' on '$rom'" [ "$nukemode" != "nuke" ] || "$ifdtool" $ifdprefix --nuke $_t \ "$rom" -O "$rom" || $err "$rom: !nuke IFD/$_t" elif [ "$nukemode" = "nuke" ]; then @@ -16,29 +16,24 @@ fi . "include/vendor.sh" . "include/mrc.sh" -eval "`setvars "" vdir src_dirname srcdir mode xp ser`" +eval "`setvars "" vdir src_dirname srcdir mode`" main() { - [ $# -lt 1 ] && $err "bad command" - rval=0 + cmd="" && [ $# -gt 0 ] && cmd="$1" && shift 1 for g in "command -v git" "git config --global user.name" \ "git config --global user.email" "git_init"; do eval "$g 1>/dev/null 2>/dev/null || $err \"Unconfigured: $g\"" done - case "$1" in + case "$cmd" in version) printf "%s\nWebsite: %s\n" "$relname" "$projectsite" ;; - release|download|inject) - cmd="vendor_$1" && [ "$1" = "release" ] && cmd="mkrelease" - shift 1 - $cmd "$@" ;; - -*) rval=1 ;; + release|download|inject) $cmd "$@" ;; + -*) return 1 ;; *) $err "bad command" ;; esac set -u -e # some commands disable them. turn them on! - return $rval } git_init() @@ -54,7 +49,7 @@ git_init() git tag -a "$version" -m "$projectname $version" || return 1 } -mkrelease() +release() { export XBMK_RELEASE="y" @@ -121,9 +116,9 @@ main "$@" && exit 0 eval "`setvars "" xarch srcdir premake gnatdir xlang mode makeargs elfdir cmd \ project target target_dir targets xtree _f release bootstrapargs mkhelper \ - autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \ + autoconfargs listfile autogenargs btype rev build_depend gccdir cmakedir \ defconfig postmake mkhelpercfg dry dest_dir mdir cleanargs gccver gccfull \ - gnatver gnatfull gccdir cmakedir do_make badhash`" + gnatver gnatfull do_make badhash tree`" trees() { @@ -246,8 +241,8 @@ handle_defconfig() configure_project() { eval "`setvars "" cleanargs build_depend autoconfargs xtree postmake \ - tree_depend makeargs btype mkhelper bootstrapargs premake release \ - xarch xlang badhash`" + makeargs btype mkhelper bootstrapargs premake release xlang xarch \ + badhash`" _tcfg="$1/target.cfg" [ -f "$_tcfg" ] || btype="auto" e "$datadir/mkhelper.cfg" f && eval "`setcfg "$datadir/mkhelper.cfg"`" |