Skip to content

Commit 82aa8bb

Browse files
committed
Merge branch 'dev'
2 parents 59acc20 + 2ab53bd commit 82aa8bb

File tree

3 files changed

+75
-28
lines changed

3 files changed

+75
-28
lines changed

load_repo_dotenv.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ function dnp::load_repository_environment_variables() {
1414
# ....Setup......................................................................................
1515
local TMP_CWD
1616
TMP_CWD=$( pwd )
17-
local DEBUG="false"
17+
local _debug="false"
1818

1919
# ....cli..........................................................................................
2020
while [ $# -gt 0 ]; do
2121
case $1 in
2222
--debug)
23-
DEBUG="true"
23+
_debug="true"
2424
shift # Remove argument (--debug)
2525
;;
2626
*) # Default case
@@ -44,12 +44,12 @@ function dnp::load_repository_environment_variables() {
4444
set +o allexport
4545

4646
# ....Teardown...................................................................................
47-
if [[ "${DNP_DEBUG}" == "true" ]] || [[ "${DEBUG}" == "true" ]]; then
47+
if [[ "${DNP_DEBUG}" == "true" ]] || [[ "${_debug}" == "true" ]]; then
4848
export DNP_DEBUG=true
4949
echo -e "${MSG_DONE_FORMAT}[DNP]${MSG_END_FORMAT} .env.dockerized-norlab-project loaded"
5050
# Debug flags
5151
set -v # echo lines as they are read
52-
set -x # show execution of [file]
52+
export BUILDKIT_PROGRESS=plain
5353
fi
5454

5555
cd "${TMP_CWD}" || { echo "Return to original dir error" 1>&2 && return 1; }

src/lib/core/utils/import_dnp_lib.bash

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
# Usage:
66
# $ source import_dnp_lib.bash
77
#
8+
# Global
9+
# read/write DNP_ROOT
10+
#
811
# =================================================================================================
912
MSG_ERROR_FORMAT="\033[1;31m"
1013
MSG_END_FORMAT="\033[0m"
14+
MSG_DONE_FORMAT="\033[1;32m"
1115

1216
# ....Variable set for export......................................................................
1317

@@ -19,6 +23,8 @@ MSG_END_FORMAT="\033[0m"
1923
#
2024
# Arguments:
2125
# none
26+
# Global:
27+
# read DNP_ROOT
2228
# Outputs:
2329
# An error message to to stderr in case of failure
2430
# Returns:
@@ -29,13 +35,13 @@ function dnp::import_lib_and_dependencies() {
2935
# ....Setup......................................................................................
3036
local TMP_CWD
3137
TMP_CWD=$(pwd)
32-
local DEBUG
38+
local _debug
3339

3440
# ....cli..........................................................................................
3541
while [ $# -gt 0 ]; do
3642
case $1 in
3743
--debug)
38-
DEBUG="true"
44+
_debug="true"
3945
shift # Remove argument (--debug)
4046
;;
4147
*) # Default case
@@ -45,51 +51,92 @@ function dnp::import_lib_and_dependencies() {
4551
done
4652

4753
# ....Find path to script........................................................................
48-
# Note: can handle both sourcing cases
49-
# i.e. from within a script or from an interactive terminal session
50-
local SCRIPT_PATH
51-
local TARGET_ROOT
52-
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]:-'.'}")"
53-
TARGET_ROOT="$(dirname "${SCRIPT_PATH}")"
54-
55-
# ....Find path to target parent directory.......................................................
56-
while [[ $(basename "${TARGET_ROOT}") != "dockerized-norlab-project" ]]; do
57-
TARGET_ROOT="$( dirname "$TARGET_ROOT" )"
58-
done
54+
dnp::find_dnp_root_path || return 1
5955

6056
# ....Pre-condition..............................................................................
6157
# Test extracted path
62-
if [[ ! -d "${TARGET_ROOT:?err}" ]]; then
63-
echo -e "\n${MSG_ERROR_FORMAT}[DNP error]${MSG_END_FORMAT} dockerized-norlab-project is unreachable at '${TARGET_ROOT}'!" 1>&2
58+
if [[ ! -d "${DNP_ROOT:?err}" ]]; then
59+
echo -e "\n${MSG_ERROR_FORMAT}[DNP error]${MSG_END_FORMAT} dockerized-norlab-project is unreachable at '${DNP_ROOT}'!" 1>&2
6460
return 1
6561
fi
6662

6763
# ....Load DNP .env file for N2ST................................................................
68-
source "${TARGET_ROOT}/load_repo_dotenv.bash"
64+
source "${DNP_ROOT}/load_repo_dotenv.bash"
6965

7066
# ....Load NBS...................................................................................
7167
cd "${NBS_PATH:?'Variable not set'}" || return 1
7268
source "import_norlab_build_system_lib.bash" || return 1
7369

7470
# ....(Quickhack) Reload project .env file for N2ST..............................................
75-
source "${TARGET_ROOT}/load_repo_dotenv.bash"
71+
source "${DNP_ROOT}/load_repo_dotenv.bash"
7672

7773
# ....Load N2ST..................................................................................
7874
cd "${N2ST_PATH:?'Variable not set'}" || return 1
7975
source "import_norlab_shell_script_tools_lib.bash" || return 1
8076

8177
# ....(Quickhack) Reload project .env file for N2ST..............................................
82-
source "${TARGET_ROOT}/load_repo_dotenv.bash"
78+
source "${DNP_ROOT}/load_repo_dotenv.bash"
8379

8480
# ....Teardown...................................................................................
85-
if [[ "${DNP_DEBUG}" == "true" ]] || [[ "${DEBUG}" == "true" ]]; then
81+
if [[ "${DNP_DEBUG}" == "true" ]] || [[ "${_debug}" == "true" ]]; then
8682
export DNP_DEBUG=true
8783
echo -e "${MSG_DONE_FORMAT}[DNP]${MSG_END_FORMAT} librairies loaded"
8884
fi
8985
cd "${TMP_CWD}" || { echo "Return to original dir error" 1>&2 && return 1; }
9086
return 0
9187
}
9288

89+
# =================================================================================================
90+
# Function to find the DNP root path. It seek for the .env.dockerized-norlab-project
91+
# file which should be at the project root by moving up the directory tree from cwd.
92+
#
93+
# Usage:
94+
# $ dnp::find_dnp_root_path
95+
#
96+
# Arguments:
97+
# none
98+
# Outputs:
99+
# An error message to to stderr in case of failure
100+
# Globals:
101+
# write DNP_ROOT
102+
# Returns:
103+
# 1 on faillure, 0 otherwise
104+
# =================================================================================================
105+
dnp::find_dnp_root_path() {
106+
107+
# ....Find path to script........................................................................
108+
# Note: can handle both sourcing cases
109+
# i.e. from within a script or from an interactive terminal session
110+
local SCRIPT_PATH
111+
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]:-'.'}")"
112+
DNP_ROOT="$(dirname "${SCRIPT_PATH}")"
113+
114+
local max_iterations=10 # Safety limit to prevent infinite loops
115+
local iterations_count=0
116+
117+
while [[ "$DNP_ROOT" != "/" && $iterations_count -lt $max_iterations ]]; do
118+
119+
# Move up to parent directory path
120+
DNP_ROOT="$( dirname "$DNP_ROOT" )"
121+
((iterations_count++))
122+
123+
# Note: the .env.dockerized-norlab-project check instead of dir dockerized-norlab-project
124+
# check is for case where the repo root was clone with a different name, e.g., in teamcity
125+
if [[ -f "${DNP_ROOT}/.env.dockerized-norlab-project" ]]; then
126+
echo -e "${MSG_DONE_FORMAT}[DNP]${MSG_END_FORMAT} Found .env.dockerized-norlab-project in: $DNP_ROOT"
127+
export DNP_ROOT
128+
return 0
129+
elif [[ "${DNP_DEBUG}" == "true" ]]; then
130+
echo "Level ${iterations_count} › DNP_ROOT=$DNP_ROOT"
131+
fi
132+
133+
done
134+
135+
# If we get here, the directory was not found
136+
echo -e "${MSG_ERROR_FORMAT}[DNP error]${MSG_END_FORMAT} dockerized-norlab-project root directory not found in any parent directory" >&2
137+
return 1
138+
}
139+
93140
# ::::Main:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
94141

95142
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then

src/lib/core/utils/load_super_project_config.bash

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare -x SUPER_PROJECT_REPO_NAME
2828
# Outputs:
2929
# An error message to to stderr in case of failure
3030
# Globals:
31-
# write SUPER_PROJECT_ROOT
31+
# read/write SUPER_PROJECT_ROOT
3232
# write SUPER_PROJECT_REPO_NAME
3333
# Returns:
3434
# 1 on faillure, 0 otherwise
@@ -38,13 +38,13 @@ function dnp::load_super_project_configurations() {
3838
# ....Setup......................................................................................
3939
local TMP_CWD
4040
TMP_CWD=$(pwd)
41-
local DEBUG
41+
local _debug
4242

4343
# ....cli..........................................................................................
4444
while [ $# -gt 0 ]; do
4545
case $1 in
4646
--debug)
47-
DEBUG="true"
47+
_debug="true"
4848
shift # Remove argument (--debug)
4949
;;
5050
*) # Default case
@@ -91,7 +91,7 @@ function dnp::load_super_project_configurations() {
9191

9292

9393
# ....Teardown...................................................................................
94-
if [[ "${DNP_DEBUG}" == "true" ]] || [[ "${DEBUG}" == "true" ]]; then
94+
if [[ "${DNP_DEBUG}" == "true" ]] || [[ "${_debug}" == "true" ]]; then
9595
export DNP_DEBUG=true
9696
echo -e "${MSG_DONE_FORMAT}[DNP]${MSG_END_FORMAT} ${SUPER_PROJECT_REPO_NAME} project configurations loaded"
9797
fi
@@ -103,7 +103,7 @@ function dnp::load_super_project_configurations() {
103103

104104
# =================================================================================================
105105
# Function to find the DNP user side project path. It seek for the .dockerized_norlab_project
106-
# directory which sould be at the project root by moving up the directory tree from cwd.
106+
# directory which should be at the project root by moving up the directory tree from cwd.
107107
#
108108
# Usage:
109109
# $ dnp::find_dnp_super_project_dir

0 commit comments

Comments
 (0)