Misc library edits and cleanup
Makefile
--------
o Simplify initial bootstrap path construction logic used to load
the top level library makefile repo:onf-lib/makefiles/include.mk.
o Remove direct includes (consts.mk) that are loaded by include.mk.
bin/setup.sh
------------
o Update repo:onf-lib installer script.
o Re-arrange inlined logic into functions.
o Added a banner message to display installation progress.
o Added install_config_mk(), relocate sandbox/config.mk into sandbox/makefiles/onf-lib/config.mk.
o Added detection logic to handle patching python to v3.10+.
makefiles/etc/include.mk
------------------------
o Remove dup logic, include.mk mirrored features.mk, changed to simply include features.mk.
makefiles/include.mk
--------------------
o Relocate display of include/display of help target trailer message
from top level Makefile into the library makefile hierarchy.
makefiles_include_mk.ex
-----------------------
o Added git-submodule maintenance helper targets & dependencies that
consuming repository makefiles can use to automate submodule checkout
from a clean state.
Change-Id: Id8df17cef09a17325137934d04e58d87ea370621
diff --git a/Makefile b/Makefile
index 96b8f26..3249936 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,13 @@
.PHONY: help clean help test
.DEFAULT_GOAL := help
+##---------------------##
+##---] BOOTSTRAP [---##
+##---------------------##
+onf-mk-abs ?= $(abspath $(lastword $(MAKEFILE_LIST)))
+onf-mk-top := $(dir $(onf-mk-abs))
+onf-mk-top := $(patsubst %/,%,$(onf-mk-top))
+
##-------------------##
##---] GLOBALS [---##
##-------------------##
@@ -26,11 +33,7 @@
##--------------------##
##---] INCLUDES [---##
##--------------------##
-include $(TOP)/config.mk
-include $(TOP)/makefiles/include.mk
-
-## Display make help text late
-include $(ONF_MAKEDIR)/help/trailer.mk
+include $(onf-mk-top)/makefiles/include.mk
## -----------------------------------------------------------------------
## Intent: Helper target for interactive README.md viewing
diff --git a/bin/setup.sh b/bin/setup.sh
index 0d3f577..0175083 100755
--- a/bin/setup.sh
+++ b/bin/setup.sh
@@ -27,6 +27,7 @@
##---] GLOBALS [---##
##-------------------##
set -euo pipefail
+# declare -g -i debug=1
## -----------------------------------------------------------------------
## Intent: Display a message with formatting
@@ -51,20 +52,71 @@
exit 1
}
-##----------------##
-##---] MAIN [---##
-##----------------##
+## -----------------------------------------------------------------------
+## Intent: Archive current directory before we begin
+## -----------------------------------------------------------------------
+function archive_sandbox()
+{
+ local abs="$(realpath --canonicalize-existing '.')"
+ local dir="${abs##*/}"
+ local ts="$(date '+%Y%m%d%H%M%S')"
+ local prefix="../${dir}-all/backups"
-## Avoid trashing a work-in-progress
-path='makefiles/local/include.mk'
-[[ -e "$path" ]] && { error "Detected upgrade path: $path"; }
+ banner "Archive current directory ($dir)"
-banner "Archive current directory"
-tar czvf ../backup-setup.tgz .
+# make sterile >/dev/null # nuke lingering .venv/ installs
+# make clean-all >/dev/null # nuke lingering .venv/ installs
-## Migration patches should be simple and plentiful.
-if [[ ! -d makefiles-orig ]]; then
- cat <<EOM
+ declare -a targs=()
+ targs+=('--create')
+
+ ## Set archive compression level
+ local compress='bzip2'
+ local ext
+ case "$compress" in
+ bzip2) targs+=('--bzip2'); ext='bz2' ;;
+ gzip) targs+=('--gzip'); ext='tgz' ;;
+ zstd) targs+=('--zstd'); ext='zst' ;;
+ *) error "Detected invalid compression [$compress]" ;;
+ esac
+
+ local out="${prefix}/${ts}.${ext}"
+
+ targs+=('--file' "$out")
+
+ mkdir -p "$prefix"
+ tar "${targs[@]}" '.'
+ /bin/ls -l "$out"
+ return
+}
+
+## -----------------------------------------------------------------------
+## Intent: Install feature enabling makefile.
+## -----------------------------------------------------------------------
+function install_config_mk
+{
+ local dst='makefiles/config.mk'
+ if [[ -f "$dst" ]]; then
+ :
+ elif [[ -f 'config.mk' ]]; then
+ git mv config.mk "$dst"
+ else
+ rsync -v --checksum makefiles/onf-lib/config.mk "$dst"
+ fi
+
+ return
+}
+
+## -----------------------------------------------------------------------
+## Intent: Re-home existing local makefiles/ into makefiles/local
+## -----------------------------------------------------------------------
+function patch_detection()
+{
+ [[ ! -d makefiles ]] && return
+
+ ## Migration patches should be simple and plentiful.
+ if [[ ! -d makefiles-orig ]]; then
+ cat <<EOM
* -----------------------------------------------------------------------
* Replacing a repository makefile directory is deployed
@@ -82,8 +134,28 @@
3) Update Makefile to include makefiles/include.mk
EOM
- exit 1
-fi
+ exit 1
+ fi
+ return
+}
+
+##----------------##
+##---] MAIN [---##
+##----------------##
+while [[ $# -gt 0 ]]; do
+ arg=$1; shift
+ case "$arg" in
+ debug) declare -g -i debug=1 ;;
+ *) error "Detected invalid switch [$arg]" ;;
+ esac
+done
+
+## Avoid trashing a work-in-progress
+path='makefiles/local/include.mk'
+[[ -e "$path" ]] && { error "Detected upgrade path: $path"; }
+
+archive_sandbox
+patch_detection
mkdir -p makefiles
pushd makefiles || { error 'pushd makefiles failed'; }
@@ -103,7 +175,8 @@
banner 'Prep work for pending checkin'
git add makefiles/include.mk
git add makefiles/local/include.mk
-git mv config.mk makefiles/config.mk
+install_config_mk
git add makefiles
+git status
# [EOF]
diff --git a/makefiles/etc/include.mk b/makefiles/etc/include.mk
index a48b42c..cc17c2e 100644
--- a/makefiles/etc/include.mk
+++ b/makefiles/etc/include.mk
@@ -17,31 +17,10 @@
# SPDX-FileCopyrightText: 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
-# Usage:
-#
-# mytarget:
-# $(call banner-enter,target $@)
-# @echo "Hello World"
-# $(call banner-leave,target $@)
-# -----------------------------------------------------------------------
$(if $(DEBUG),$(warning ENTER))
-target-banner = ** ---------------------------------------------------------------------------
-
-## -----------------------------------------------------------------------
-## Intent: Return a command line able to display a banner hilighting
-## make target processing within a logfile.
-## -----------------------------------------------------------------------
-banner-enter=\
- @echo -e \
- "\n"\
- "$(target-banner)\n"\
- "** $(MAKE) ENTER: $(1)\n"\
- "$(target-banner)"\
-
-banner-leave=\
- @echo -e "** $(MAKE) LEAVE: $(1)"
+include $(ONF_MAKEDIR)/etc/features.mk
$(if $(DEBUG),$(warning LEAVE))
diff --git a/makefiles/git/detect-local-edits.mk b/makefiles/git/detect-local-edits.mk
new file mode 100644
index 0000000..d0afc84
--- /dev/null
+++ b/makefiles/git/detect-local-edits.mk
@@ -0,0 +1,23 @@
+# -*- makefile -*-
+## -----------------------------------------------------------------------
+## Intent: Targets in this makefile will determine if locally modified
+## files exist in the sandbox. VOLTHA currently uses this logic to
+## detect when go {tidy, update} have indirectly modified vendor go.mod
+## files during a build or test.
+## -----------------------------------------------------------------------
+
+$(error DISABLED -- not yet deployed/in use)
+
+# $(MAKE) --no-print-directory detect-local-edits
+
+## ---------------------------------------------------------------------
+## Intent: Determine if sandbox contains locally modified files
+## ---------------------------------------------------------------------
+clean-tree := git status --porcelain
+detect-local-edits:
+ $(HIDE)[[ `$(clean-tree)` == "" ]] || {\
+ echo "ERROR: Untracked files detected, commit or remove to continue" \
+ && echo "`git status`" \
+ && exit 1; }
+
+# [EOF]
diff --git a/makefiles/include.mk b/makefiles/include.mk
index 48de1e9..418e59e 100644
--- a/makefiles/include.mk
+++ b/makefiles/include.mk
@@ -20,7 +20,7 @@
# https://gerrit.opencord.org/plugins/gitiles/onf-make
# ONF.makefiles.include.version = 1.1
# -----------------------------------------------------------------------
-
+#
ifndef mk-include--onf-make # single-include guard macro
$(if $(DEBUG),$(warning ENTER))
@@ -31,18 +31,18 @@
## -----------------------------------------------------------------------
## Define vars based on relative import (normalize symlinks)
-## Usage: include makefiles/onf/include.mk
+## Usage: include makefiles/onf-lib/include.mk
## Overide-by: makefiles/onf-lib/makefiles/include.mk
## when repo:onf-make is used as a git-submodule
## -----------------------------------------------------------------------
-onf-mk-abs ?= $(abspath $(lastword $(MAKEFILE_LIST)))
+onf-mk-abs := $(abspath $(lastword $(MAKEFILE_LIST)))
onf-mk-top := $(subst /include.mk,$(null),$(onf-mk-abs))
onf-mk-tmp := $(onf-mk-top)/tmp
ONF_MAKEDIR := $(onf-mk-top)
TOP ?= $(patsubst %/makefiles/include.mk,%,$(onf-mk-abs))
-##--------------------##
+#--------------------##
##---] INCLUDES [---##
##--------------------##
include $(ONF_MAKEDIR)/lint/make/warn-undef-vars.mk # target lint-make helper
@@ -78,6 +78,9 @@
##-------------------##
include $(ONF_MAKEDIR)/targets/include.mk # clean, sterile
+## Display make help text late
+include $(ONF_MAKEDIR)/help/trailer.mk
+
$(if $(DEBUG),$(warning LEAVE))
mk-include--onf-make := true
diff --git a/makefiles_include_mk.ex b/makefiles_include_mk.ex
index 1bad7af..3e79d0a 100644
--- a/makefiles_include_mk.ex
+++ b/makefiles_include_mk.ex
@@ -35,7 +35,7 @@
## Define vars based on relative import (normalize symlinks)
## Usage: include makefiles/onf/include.mk
## -----------------------------------------------------------------------
-onf-mk-abs ?= $(abspath $(lastword $(MAKEFILE_LIST)))
+onf-mk-abs := $(abspath $(lastword $(MAKEFILE_LIST)))
onf-mk-top := $(subst /include.mk,$(null),$(onf-mk-abs))
onf-mk-lib := $(onf-mk-top)/onf-lib/makefiles
onf-mk-loc := $(onf-mk-top)/local
@@ -56,6 +56,10 @@
include $(onf-mk-lib)/include.mk
include $(onf-mk-loc)/include.mk
+## -----------------------------------------------------------------------
+## Intent: Helper targets for maintaining git-submodules (repo:onf-make)
+## -----------------------------------------------------------------------
+
## -----------------------------------------
## Submodue init target for new repositories
## -----------------------------------------
@@ -65,9 +69,29 @@
cd $(dir $@) \
&& git submodule https://github.com/opencord/onf-make.git onf-lib
+## -----------------------------------------------------------------------
+## Intent: This target will update dependent git-submodule to the latest
+## version available from the remote repository. Subsequently
+## a checkin will be needed to make the submodule update permanent.
+## -----------------------------------------------------------------------
update-submodules:
git submodule foreach git pull
+## -----------------------------------------------------------------------
+## Intent: On-demand cloning of git submodule(s).
+## -----------------------------------------------------------------------
+## Trigger: include $(onf-mk-lib)/include.mk
+## - When the make command attempts to include a makefile from the
+## repo:onf-make submodule, this target/dependency will initialize
+## and checkout all submodules the current repository depends on.
+## -----------------------------------------------------------------------
+$(onf-mk-lib)/include.mk:
+ @echo
+ @echo "** Checkout git submodule(s)"
+ @echo "** -----------------------------------------------------------------------"
+ git submodule update --init --recursive
+ @echo "** -----------------------------------------------------------------------"
+
$(if $(DEBUG),$(warning LEAVE))
# [EOF]