trns1997 commented on code in PR #16976:
URL: https://github.com/apache/nuttx/pull/16976#discussion_r2339492633


##########
tools/mkexport.sh:
##########
@@ -364,70 +367,101 @@ cp -LR -p "${TOPDIR}/include" "${EXPORTDIR}/." || \
 ${MAKE} -C ${ARCHDIR} export_startup TOPDIR=${TOPDIR} EXPORT_DIR="${EXPORTDIR}"
 
 # Copy architecture-specific header files into the arch export sub-directory.
-# This is tricky because each architecture does things in a little different
-# way.
-#
-# First copy any header files in the architecture src/ sub-directory (some
-# architectures keep all of the header files there, some a few, and others
-# none
-
-cp -f "${ARCHDIR}"/*.h "${EXPORTDIR}"/arch/. 2>/dev/null
-
-# Then look a list of possible places where other architecture-specific
-# header files might be found.  If those places exist (as directories or
-# as symbolic links to directories, then copy the header files from
-# those directories into the EXPORTDIR
+# Some architectures keep all headers in src/, some only a few, and others 
none.
+
+if [ -d "${ARCHDIR}" ]; then
+    # Expand the glob safely
+    set -- "${ARCHDIR}"/*.h
+    if [ -e "$1" ]; then
+        echo "Copying architecture headers from ${ARCHDIR} to 
${EXPORTDIR}/arch"
+        if ! cp -f "$@" "${EXPORTDIR}/arch/"; then
+            echo "Error: Failed to copy headers from ${ARCHDIR}" >&2
+            exit 1
+        fi
+    else
+        echo "Notice: No header files found in ${ARCHDIR}" >&2
+    fi
+else
+    echo "Warning: Architecture directory ${ARCHDIR} does not exist" >&2
+fi
 
 if [ "X${USRONLY}" != "Xy" ]; then
   ARCH_HDRDIRS="arm armv7-m avr avr32 board common chip mips32"
+
   for hdir in $ARCH_HDRDIRS; do
+    srcdir="${ARCHDIR}/${hdir}"
+    dstdir="${EXPORTDIR}/arch/${hdir}"
 
     # Does the directory (or symbolic link) exist?
+    if [ -d "$srcdir" ] || [ -h "$srcdir" ]; then
+      mkdir -p "$dstdir" || {
+        echo "Error: mkdir $dstdir failed" >&2
+        exit 1
+      }
+
+      # Copy headers if they exist
+      set -- "$srcdir"/*.h
+      if [ -e "$1" ]; then
+        echo "Copying headers from $srcdir to $dstdir"
+        if ! cp -f "$@" "$dstdir/"; then
+          echo "Error: Failed to copy headers from $srcdir" >&2
+          exit 1
+        fi
+      else
+        echo "Notice: No header files found in $srcdir" >&2
+      fi
 
-    if [ -d "${ARCHDIR}/${hdir}" -o -h "${ARCHDIR}/${hdir}" ]; then
-
-      # Yes.. create a export sub-directory of the same name
-
-      mkdir "${EXPORTDIR}/arch/${hdir}" || \
-        { echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}' failed"; exit 1; }
-
-      # Then copy the header files (only) into the new directory
-
-      cp -f "${ARCHDIR}"/${hdir}/*.h "${EXPORTDIR}"/arch/${hdir}/. 2>/dev/null
-
-      # Most architectures have low directory called "hardware" that
-      # holds the header files
-
-      if [ -d "${ARCHDIR}/${hdir}/hardware" ]; then
-
-        # Yes.. create a export sub-directory of the same name
-
-        mkdir "${EXPORTDIR}/arch/${hdir}/hardware" || \
-          { echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}/hardware' failed"; exit 
1; }
-
-        # Then copy the header files (only) into the new directory
-
-        cp -f "${ARCHDIR}"/${hdir}/hardware/*.h 
"${EXPORTDIR}"/arch/${hdir}/hardware/. 2>/dev/null
+      # Handle hardware subdir if it exists
+      if [ -d "$srcdir/hardware" ]; then
+        mkdir -p "$dstdir/hardware" || {
+          echo "Error: mkdir $dstdir/hardware failed" >&2
+          exit 1
+        }
+
+        set -- "$srcdir/hardware"/*.h
+        if [ -e "$1" ]; then
+          echo "Copying headers from $srcdir/hardware to $dstdir/hardware"
+          if ! cp -f "$@" "$dstdir/hardware/"; then
+            echo "Error: Failed to copy headers from $srcdir/hardware" >&2
+            exit 1
+          fi
+        else
+          echo "Notice: No hardware headers in $srcdir/hardware" >&2
+        fi
       fi
     fi
   done
 
-  # Copy OS internal header files as well.  They are used by some architecture-
-  # specific header files.
-
-  mkdir "${EXPORTDIR}/arch/os" || \
-    { echo "MK: 'mkdir ${EXPORTDIR}/arch/os' failed"; exit 1; }
+  # Copy OS internal header files
+  mkdir -p "${EXPORTDIR}/arch/os" || {
+    echo "Error: mkdir ${EXPORTDIR}/arch/os failed" >&2
+    exit 1
+  }
 
   OSDIRS="clock environ errno group init irq mqueue paging pthread sched 
semaphore signal task timer wdog"
 
   for dir in ${OSDIRS}; do
-    mkdir "${EXPORTDIR}/arch/os/${dir}" || \
-      { echo "MK: 'mkdir ${EXPORTDIR}/arch/os/${dir}' failed"; exit 1; }
-    cp -f "${TOPDIR}"/sched/${dir}/*.h "${EXPORTDIR}"/arch/os/${dir}/. 
2>/dev/null
-  done
+    srcdir="${TOPDIR}/sched/${dir}"
+    dstdir="${EXPORTDIR}/arch/os/${dir}"
 
-  # Add the board library to the list of libraries
+    mkdir -p "$dstdir" || {
+      echo "Error: mkdir $dstdir failed" >&2
+      exit 1
+    }
+
+    set -- "$srcdir"/*.h
+    if [ -e "$1" ]; then
+      echo "Copying OS headers from $srcdir to $dstdir"
+      if ! cp -f "$@" "$dstdir/"; then
+        echo "Error: Failed to copy headers from $srcdir" >&2

Review Comment:
   add `MK:` to output message



##########
tools/mkexport.sh:
##########
@@ -364,70 +367,101 @@ cp -LR -p "${TOPDIR}/include" "${EXPORTDIR}/." || \
 ${MAKE} -C ${ARCHDIR} export_startup TOPDIR=${TOPDIR} EXPORT_DIR="${EXPORTDIR}"
 
 # Copy architecture-specific header files into the arch export sub-directory.
-# This is tricky because each architecture does things in a little different
-# way.
-#
-# First copy any header files in the architecture src/ sub-directory (some
-# architectures keep all of the header files there, some a few, and others
-# none
-
-cp -f "${ARCHDIR}"/*.h "${EXPORTDIR}"/arch/. 2>/dev/null
-
-# Then look a list of possible places where other architecture-specific
-# header files might be found.  If those places exist (as directories or
-# as symbolic links to directories, then copy the header files from
-# those directories into the EXPORTDIR
+# Some architectures keep all headers in src/, some only a few, and others 
none.
+
+if [ -d "${ARCHDIR}" ]; then
+    # Expand the glob safely
+    set -- "${ARCHDIR}"/*.h
+    if [ -e "$1" ]; then
+        echo "Copying architecture headers from ${ARCHDIR} to 
${EXPORTDIR}/arch"
+        if ! cp -f "$@" "${EXPORTDIR}/arch/"; then
+            echo "Error: Failed to copy headers from ${ARCHDIR}" >&2
+            exit 1
+        fi
+    else
+        echo "Notice: No header files found in ${ARCHDIR}" >&2
+    fi
+else
+    echo "Warning: Architecture directory ${ARCHDIR} does not exist" >&2
+fi
 
 if [ "X${USRONLY}" != "Xy" ]; then
   ARCH_HDRDIRS="arm armv7-m avr avr32 board common chip mips32"
+
   for hdir in $ARCH_HDRDIRS; do
+    srcdir="${ARCHDIR}/${hdir}"
+    dstdir="${EXPORTDIR}/arch/${hdir}"
 
     # Does the directory (or symbolic link) exist?
+    if [ -d "$srcdir" ] || [ -h "$srcdir" ]; then
+      mkdir -p "$dstdir" || {
+        echo "Error: mkdir $dstdir failed" >&2
+        exit 1
+      }
+
+      # Copy headers if they exist
+      set -- "$srcdir"/*.h
+      if [ -e "$1" ]; then
+        echo "Copying headers from $srcdir to $dstdir"
+        if ! cp -f "$@" "$dstdir/"; then
+          echo "Error: Failed to copy headers from $srcdir" >&2
+          exit 1
+        fi
+      else
+        echo "Notice: No header files found in $srcdir" >&2
+      fi
 
-    if [ -d "${ARCHDIR}/${hdir}" -o -h "${ARCHDIR}/${hdir}" ]; then
-
-      # Yes.. create a export sub-directory of the same name
-
-      mkdir "${EXPORTDIR}/arch/${hdir}" || \
-        { echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}' failed"; exit 1; }
-
-      # Then copy the header files (only) into the new directory
-
-      cp -f "${ARCHDIR}"/${hdir}/*.h "${EXPORTDIR}"/arch/${hdir}/. 2>/dev/null
-
-      # Most architectures have low directory called "hardware" that
-      # holds the header files
-
-      if [ -d "${ARCHDIR}/${hdir}/hardware" ]; then
-
-        # Yes.. create a export sub-directory of the same name
-
-        mkdir "${EXPORTDIR}/arch/${hdir}/hardware" || \
-          { echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}/hardware' failed"; exit 
1; }
-
-        # Then copy the header files (only) into the new directory
-
-        cp -f "${ARCHDIR}"/${hdir}/hardware/*.h 
"${EXPORTDIR}"/arch/${hdir}/hardware/. 2>/dev/null
+      # Handle hardware subdir if it exists
+      if [ -d "$srcdir/hardware" ]; then
+        mkdir -p "$dstdir/hardware" || {
+          echo "Error: mkdir $dstdir/hardware failed" >&2
+          exit 1
+        }
+
+        set -- "$srcdir/hardware"/*.h
+        if [ -e "$1" ]; then
+          echo "Copying headers from $srcdir/hardware to $dstdir/hardware"
+          if ! cp -f "$@" "$dstdir/hardware/"; then
+            echo "Error: Failed to copy headers from $srcdir/hardware" >&2
+            exit 1
+          fi
+        else
+          echo "Notice: No hardware headers in $srcdir/hardware" >&2
+        fi
       fi
     fi
   done
 
-  # Copy OS internal header files as well.  They are used by some architecture-
-  # specific header files.
-
-  mkdir "${EXPORTDIR}/arch/os" || \
-    { echo "MK: 'mkdir ${EXPORTDIR}/arch/os' failed"; exit 1; }
+  # Copy OS internal header files
+  mkdir -p "${EXPORTDIR}/arch/os" || {
+    echo "Error: mkdir ${EXPORTDIR}/arch/os failed" >&2
+    exit 1
+  }
 
   OSDIRS="clock environ errno group init irq mqueue paging pthread sched 
semaphore signal task timer wdog"
 
   for dir in ${OSDIRS}; do
-    mkdir "${EXPORTDIR}/arch/os/${dir}" || \
-      { echo "MK: 'mkdir ${EXPORTDIR}/arch/os/${dir}' failed"; exit 1; }
-    cp -f "${TOPDIR}"/sched/${dir}/*.h "${EXPORTDIR}"/arch/os/${dir}/. 
2>/dev/null
-  done
+    srcdir="${TOPDIR}/sched/${dir}"
+    dstdir="${EXPORTDIR}/arch/os/${dir}"
 
-  # Add the board library to the list of libraries
+    mkdir -p "$dstdir" || {
+      echo "Error: mkdir $dstdir failed" >&2
+      exit 1
+    }
+
+    set -- "$srcdir"/*.h
+    if [ -e "$1" ]; then
+      echo "Copying OS headers from $srcdir to $dstdir"
+      if ! cp -f "$@" "$dstdir/"; then
+        echo "Error: Failed to copy headers from $srcdir" >&2
+        exit 1
+      fi
+    else
+      echo "Notice: No headers in $srcdir" >&2

Review Comment:
   add `MK:` to output message



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to