You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/01/16 17:05:37 UTC

[incubator-nuttx] branch pr115 updated: remove the hardcode arch/chip list from all tool scripts

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr115
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/pr115 by this push:
     new bb8eeac  remove the hardcode arch/chip list from all tool scripts
bb8eeac is described below

commit bb8eeac7419d96a9e2575b61a0a3e1c4aa9da8cb
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Jan 16 09:16:14 2020 +0800

    remove the hardcode arch/chip list from all tool scripts
    
    Change-Id: Iedfe94dc8c15e973971b6daf83b383b3be2ce5e0
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 tools/configure.c  | 203 +++++++++++++++--------------------------------------
 tools/configure.sh |  59 +++++-----------
 tools/refresh.sh   |  46 ++----------
 tools/testbuild.sh |  28 +-------
 4 files changed, 85 insertions(+), 251 deletions(-)

diff --git a/tools/configure.c b/tools/configure.c
index 2029a7e..d4101b0 100644
--- a/tools/configure.c
+++ b/tools/configure.c
@@ -79,14 +79,23 @@
 
 static void show_usage(const char *progname, int exitcode);
 static void debug(const char *fmt, ...);
-static int  find_archname(const char *boardname, const char *configname);
 static void parse_args(int argc, char **argv);
 static bool check_directory(const char *directory);
 static void verify_directory(const char *directory);
 static bool verify_optiondir(const char *directory);
 static bool verify_file(const char *path);
 static void find_topdir(void);
-static void config_search(const char *boarddir);
+typedef void (*config_callback)(const char *boarddir, const char *archname,
+                                const char *chipname, const char *boardname,
+                                const char *configname, void *data);
+static void config_search(const char *boarddir, config_callback callback, void *data);
+static void find_archname_callback(const char *boarddir, const char *archname,
+                                   const char *chipname, const char *boardname,
+                                   const char *configname, void *data);
+static void find_archname(void);
+static void enumerate_callback(const char *boarddir, const char *archname,
+                               const char *chipname, const char *boardname,
+                               const char *configname, void *data);
 static void enumerate_configs(void);
 static void check_configdir(void);
 static void check_configured(void);
@@ -148,92 +157,6 @@ static char        g_buffer[BUFFER_SIZE];   /* Scratch buffer for forming full p
 static struct variable_s *g_configvars = NULL;
 static struct variable_s *g_versionvars = NULL;
 
-/* Recognized architectures */
-
-static const char *g_archnames[] =
-{
-  "arm",
-  "avr",
-  "hc",
-  "mips",
-  "misoc",
-  "or1k",
-  "renesas",
-  "risc-v",
-  "sim",
-  "x86",
-  "xtensa",
-  "z16",
-  "z80",
-  NULL
-};
-
-/* Recognized chip names */
-
-static const char *g_chipnames[] =
-{
-  "a1x",
-  "am335x",
-  "c5471",
-  "cxd56xx",
-  "dm320",
-  "efm32",
-  "imx6",
-  "imxrt",
-  "kinetis",
-  "kl",
-  "lc823450",
-  "lpc17xx_40xx",
-  "lpc214x",
-  "lpc2378",
-  "lpc31xx",
-  "lpc43xx",
-  "lpc54xx",
-  "max326xx",
-  "moxart",
-  "nrf52",
-  "nuc1xx",
-  "rx65n" 
-  "s32k1xx",
-  "sam34",
-  "sama5",
-  "samd2l2",
-  "samd5e5",
-  "samv7",
-  "stm32",
-  "stm32f0l0g0",
-  "stm32f7",
-  "stm32h7",
-  "stm32l4",
-  "str71x",
-  "tiva",
-  "tms570",
-  "xmc4",
-  "at32uc3",
-  "at90usb",
-  "atmega",
-  "mcs92s12ne64",
-  "pic32mx",
-  "pic32mz",
-  "lm32",
-  "mor1kx",
-  "m32262f8",
-  "sh7032",
-  "fe310",
-  "gap8",
-  "k210",
-  "nr5m100",
-  "sim",
-  "qemu",
-  "esp32",
-  "z16f2811",
-  "ez80",
-  "z180",
-  "z8",
-  "z80",
-  NULL
-};
-
 /* Optional configuration files */
 
 static const char *g_optfiles[] =
@@ -318,49 +241,10 @@ static void debug(const char *fmt, ...)
     }
 }
 
-static int find_archname(const char *boardname, const char *configname)
-{
-  const char **archname;
-  const char **chipname;
-  struct stat statbuf;
-  int ret;
-
-  /* Try each combination of board and chip names */
-
-  for (archname = g_archnames; *archname != NULL; archname++)
-    {
-      for (chipname = g_chipnames; *chipname != NULL; chipname++)
-        {
-          /* Get the architecture directory under boards.  Path format:
-           * board/<arch-name>/<chip-name>/<board-name>/configs/<config-name>
-           */
-
-          snprintf(g_buffer, BUFFER_SIZE, "boards%c%s%c%s%c%s%cconfigs%c%s",
-                   g_delim, *archname, g_delim, *chipname, g_delim, boardname,
-                   g_delim, g_delim, configname);
-
-          /* Check if there is a directory at this path */
-
-          ret = stat(g_buffer, &statbuf);
-          if (ret == 0 && S_ISDIR(statbuf.st_mode))
-            {
-              g_archdir = *archname;
-              g_chipdir = *chipname;
-              return 0;
-            }
-        }
-    }
-
-  g_archdir = "unknown";
-  g_chipdir = "unknown";
-  return -1;
-}
-
 static void parse_args(int argc, char **argv)
 {
   char *ptr;
   int ch;
-  int ret;
 
   /* Parse command line options */
 
@@ -477,13 +361,6 @@ static void parse_args(int argc, char **argv)
       fprintf(stderr, "ERROR: Unexpected garbage at the end of the line\n");
       show_usage(argv[0], EXIT_FAILURE);
     }
-
-  ret = find_archname(g_boarddir, g_configdir);
-  if (ret != 0)
-    {
-      fprintf(stderr, "ERROR: Architecture for board %s not found\n",
-              g_boarddir);
-    }
 }
 
 static bool check_directory(const char *directory)
@@ -633,7 +510,7 @@ static void find_topdir(void)
     }
 }
 
-static void config_search(const char *boarddir)
+static void config_search(const char *boarddir, config_callback callback, void *data)
 {
   DIR *dir;
   struct dirent *dp;
@@ -667,7 +544,7 @@ static void config_search(const char *boarddir)
 
   /* Visit each entry in the directory */
 
-  while ((dp = readdir (dir)) != NULL)
+  while ((dp = readdir(dir)) != NULL)
     {
       /* Ignore directory entries that start with '.' */
 
@@ -700,7 +577,7 @@ static void config_search(const char *boarddir)
           char *tmppath;
           snprintf(g_buffer, BUFFER_SIZE, "%s%c%s", boarddir, g_delim, child);
           tmppath = strdup(g_buffer);
-          config_search(tmppath);
+          config_search(tmppath, callback, data);
           free(tmppath);
         }
 
@@ -712,10 +589,11 @@ static void config_search(const char *boarddir)
 
       else if (S_ISREG(buf.st_mode) && strcmp("defconfig", child) == 0)
         {
+          char *archname;
+          char *chipname;
           char *boardname;
           char *configname;
           char *delim;
-          char *tmp;
 
           /* Get the board directory near the beginning of the 'boarddir' path:
            * <archdir>/<chipdir>/<boarddir>/configs/<configdir>
@@ -725,7 +603,9 @@ static void config_search(const char *boarddir)
 
           strncpy(g_buffer, boarddir, BUFFER_SIZE);
 
-          /* Skip over <archdir> */
+          /* Save the <archdir> */
+
+          archname = g_buffer;
 
           delim = strchr(g_buffer, g_delim);
           if (delim == NULL)
@@ -734,13 +614,15 @@ static void config_search(const char *boarddir)
             }
           else
             {
-              /* Skip over <chipdir> */
+              /* Save the <chipdir> */
+
+              *delim   = '\0';
+              chipname = delim + 1;
 
-              tmp   = delim + 1;
-              delim = strchr(tmp, g_delim);
+              delim = strchr(chipname, g_delim);
               if (delim == NULL)
                 {
-                  debug("ERROR: delimiter not found in path: %s\n", tmp);
+                  debug("ERROR: delimiter not found in path: %s\n", chipname);
                 }
               else
                 {
@@ -768,7 +650,7 @@ static void config_search(const char *boarddir)
                       else
                         {
                           configname = delim + 1;
-                          fprintf(stderr, "  %s:%s\n", boardname, configname);
+                          callback(boarddir, archname, chipname, boardname, configname, data);
                         }
                     }
                 }
@@ -782,10 +664,39 @@ static void config_search(const char *boarddir)
   closedir(dir);
 }
 
+static void find_archname_callback(const char *boarddir, const char *archname,
+                                   const char *chipname, const char *boardname,
+                                   const char *configname, void *data)
+{
+  if (strcmp(g_boarddir, boardname) == 0 &&
+      strcmp(g_configdir, configname) == 0)
+    {
+      g_archdir = strdup(archname);
+      g_chipdir = strdup(chipname);
+    }
+}
+
+static void find_archname(void)
+{
+  config_search("", find_archname_callback, NULL);
+  if (g_archdir == NULL || g_chipdir == NULL)
+    {
+      g_archdir = "unknown";
+      g_chipdir = "unknown";
+    }
+}
+
+static void enumerate_callback(const char *boarddir, const char *archname,
+                               const char *chipname, const char *boardname,
+                               const char *configname, void *data)
+{
+  fprintf(stderr, "  %s:%s\n", boardname, configname);
+}
+
 static void enumerate_configs(void)
 {
   fprintf(stderr, "Options for <board-name>:<config-name> include:\n\n");
-  config_search("");
+  config_search("", enumerate_callback, NULL);
 }
 
 static void check_configdir(void)
@@ -802,6 +713,8 @@ static void check_configdir(void)
    * boards/<archdir>/<chipdir>/<boarddir>/configs/<configdir>
    */
 
+  find_archname();
+
   snprintf(g_buffer, BUFFER_SIZE, "%s%cboards%c%s%c%s%c%s%cconfigs%c%s",
            g_topdir, g_delim, g_delim, g_archdir, g_delim, g_chipdir,
            g_delim, g_boarddir, g_delim, g_delim, g_configdir);
diff --git a/tools/configure.sh b/tools/configure.sh
index b91b391..1194b76 100755
--- a/tools/configure.sh
+++ b/tools/configure.sh
@@ -142,33 +142,12 @@ else
   boarddir=`echo ${boardconfig} | cut -d':' -f1`
 fi
 
-# Detect the architecture of this board.
-
-archs="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
-chips="a1x am335x c5471 cxd56xx dm320 efm32 imx6 imxrt kinetis kl lc823450
- lpc17xx_40xx lpc214x lpc2378 lpc31xx lpc43xx lpc54xx max326xx moxart nrf52
- nuc1xx rx65n s32k1xx sam34 sama5 samd2l2 samd5e5 samv7 stm32 stm32f0l0g0 stm32f7 stm32h7
- stm32l4 str71x tiva tms570 xmc4 at32uc3 at90usb atmega mcs92s12ne64 pic32mx
- pic32mz lm32 mor1kx m32262f8 sh7032 fe310 k210 gap8 nr5m100 sim qemu esp32 z16f2811
- ez80 z180 z8 z80"
-
-for arc in ${archs}; do
-for chip in ${chips}; do
-  if [ -f ${TOPDIR}/boards/${arc}/${chip}/${boarddir}/Kconfig ]; then
-    archdir=${arc}
-    chipdir=${chip}
-    echo "  Detected ${archdir} Architecture"
-    echo "  Detected ${chipdir} Chip"
-  fi
-done
-done
-
-configpath=${TOPDIR}/boards/${archdir}/${chipdir}/${boarddir}/configs/${configdir}
-if [ ! -d "${configpath}" ]; then
+configpath=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}
+if [ ! -d ${configpath} ]; then
   # Try direct path used with custom configurations.
 
   configpath=${TOPDIR}/${boardconfig}
-  if [ ! -d "${configpath}" ]; then
+  if [ ! -d ${configpath} ]; then
     echo "Directory for ${boardconfig} does not exist.  Options are:"
     echo ""
     echo "Select one of the following options for <board-name>:"
@@ -185,26 +164,26 @@ if [ ! -d "${configpath}" ]; then
   fi
 fi
 
-src_makedefs="${TOPDIR}/boards/${archdir}/${chipdir}/${boarddir}/configs/${configdir}/Make.defs"
+src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}/Make.defs
 dest_makedefs="${TOPDIR}/Make.defs"
 
-if [ ! -r "${src_makedefs}" ]; then
-  src_makedefs="${TOPDIR}/boards/${archdir}/${chipdir}/${boarddir}/scripts/Make.defs"
+if [ ! -r ${src_makedefs} ]; then
+  src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/scripts/Make.defs
 
-  if [ ! -r "${src_makedefs}" ]; then
-    src_makedefs="${TOPDIR}/${boardconfig}/Make.defs"
-    if [ ! -r "${src_makedefs}" ]; then
+  if [ ! -r ${src_makedefs} ]; then
+    src_makedefs=${TOPDIR}/${boardconfig}/Make.defs
+    if [ ! -r ${src_makedefs} ]; then
       echo "File Make.defs could not be found"
       exit 4
     fi
   fi
 fi
 
-src_config="${configpath}/defconfig"
+src_config=${configpath}/defconfig
 dest_config="${TOPDIR}/.config"
 
-if [ ! -r "${src_config}" ]; then
-  echo "File \"${src_config}\" does not exist"
+if [ ! -r ${src_config} ]; then
+  echo "File ${src_config} does not exist"
   exit 5
 fi
 
@@ -223,7 +202,7 @@ fi
 # If we are going to some host other then windows native or to a windows
 # native host, then don't even check what is in the defconfig file.
 
-oldnative=`grep CONFIG_WINDOWS_NATIVE= "${src_config}" | cut -d'=' -f2`
+oldnative=`grep CONFIG_WINDOWS_NATIVE= ${src_config} | cut -d'=' -f2`
 if [ "X$host" != "Xwindows" -o "X$wenv" != "Xnative" ]; then
   unset winnative
 else
@@ -241,7 +220,7 @@ fi
 
 defappdir=y
 if [ -z "${appdir}" -a "X$oldnative" = "$winnative" ]; then
-  quoted=`grep "^CONFIG_APPS_DIR=" "${src_config}" | cut -d'=' -f2`
+  quoted=`grep "^CONFIG_APPS_DIR=" ${src_config} | cut -d'=' -f2`
   if [ ! -z "${quoted}" ]; then
     appdir=`echo ${quoted} | sed -e "s/\"//g"`
     defappdir=n
@@ -288,15 +267,15 @@ fi
 # Okay... Everything looks good.  Setup the configuration
 
 echo "  Copy files"
-install -m 644 "${src_makedefs}" "${dest_makedefs}" || \
-  { echo "Failed to copy \"${src_makedefs}\"" ; exit 8 ; }
-install -m 644 "${src_config}" "${dest_config}" || \
-  { echo "Failed to copy \"${src_config}\"" ; exit 9 ; }
+install -m 644 ${src_makedefs} "${dest_makedefs}" || \
+  { echo "Failed to copy ${src_makedefs}" ; exit 8 ; }
+install -m 644 ${src_config} "${dest_config}" || \
+  { echo "Failed to copy ${src_config}" ; exit 9 ; }
 
 # Install any optional files
 
 for opt in ${OPTFILES}; do
-  test -f "${configpath}/${opt}" && install "${configpath}/${opt}" "${TOPDIR}/"
+  test -f ${configpath}/${opt} && install ${configpath}/${opt} "${TOPDIR}/"
 done
 
 # If we did not use the CONFIG_APPS_DIR that was in the defconfig config file,
diff --git a/tools/refresh.sh b/tools/refresh.sh
index 3e7c7af..914a52e 100755
--- a/tools/refresh.sh
+++ b/tools/refresh.sh
@@ -33,7 +33,6 @@
 #
 
 WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
-TOPDIR="${WD}/.."
 
 USAGE="USAGE: $0 [options] <board>:<config>"
 ADVICE="Try '$0 --help' for more information"
@@ -115,39 +114,6 @@ else
   BOARDSUBDIR=`echo ${CONFIG} | cut -d':' -f1`
 fi
 
-# Detect the architecture of this board.
-
-ARCHLIST="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
-ARCHLIST="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
-CHIPLIST="a1x am335x c5471 cxd56xx dm320 efm32 imx6 imxrt kinetis kl lc823450
-  lpc17xx_40xx lpc214x lpc2378 lpc31xx lpc43xx lpc54xx max326xx moxart nrf52
-  nuc1xx rx65n s32k1xx sam34 sama5 samd2l2 samd5e5 samv7 stm32 stm32f0l0g0 stm32f7 stm32h7
-  stm32l4 str71x tiva tms570 xmc4 at32uc3 at90usb atmega mcs92s12ne64 pic32mx
-  pic32mz lm32 mor1kx m32262f8 sh7032 fe310 k210 gap8 nr5m100 sim qemu esp32 z16f2811
-  ez80 z180 z8 z80"
-
-for ARCH in ${ARCHLIST}; do
-  for CHIP in ${CHIPLIST}; do
-    if [ -f ${TOPDIR}/boards/${ARCH}/${CHIP}/${BOARDSUBDIR}/Kconfig ]; then
-      ARCHSUBDIR=${ARCH}
-      CHIPSUBDIR=${CHIP}
-      echo "  Detected ${ARCHSUBDIR} Architecture"
-      echo "  Detected ${CHIPSUBDIR} Chip"
-    fi
-  done
-done
-
-for ARCH in ${ARCHLIST}; do
-  if [ -f boards/${ARCH}/${BOARDSUBDIR}/Kconfig ]; then
-    ARCHSUBDIR=${ARCH}
-  fi
-done
-
-if [ -z "${ARCHSUBDIR}" ]; then
-  echo "ERROR:  Architecture of ${BOARDSUBDIR} not found"
-  exit 1
-fi
-
 # Where are we
 
 MYNAME=`basename $0`
@@ -163,7 +129,7 @@ fi
 
 # Set up the environment
 
-BOARDDIR=boards/$ARCHSUBDIR/$CHIPSUBDIR/$BOARDSUBDIR
+BOARDDIR=boards/*/*/$BOARDSUBDIR
 SCRIPTSDIR=$BOARDDIR/scripts
 MAKEDEFS1=$SCRIPTSDIR/Make.defs
 
@@ -179,25 +145,25 @@ CMPCONFIGMAKEDIR=tools
 
 # Check the board configuration directory
 
-if [ ! -d "$BOARDDIR" ]; then
+if [ ! -d $BOARDDIR ]; then
   echo "No board directory found at $BOARDDIR"
   exit 1
 fi
 
-if [ ! -d "$CONFIGDIR" ]; then
+if [ ! -d $CONFIGDIR ]; then
   echo "No configuration directory found at $CONFIGDIR"
   exit 1
 fi
 
-if [ ! -r "$DEFCONFIG" ]; then
+if [ ! -r $DEFCONFIG ]; then
   echo "No readable defconfig file at $DEFCONFIG"
   exit 1
 fi
 
-if [ -r "$MAKEDEFS1" ]; then
+if [ -r $MAKEDEFS1 ]; then
   MAKEDEFS=$MAKEDEFS1
 else
-  if [ -r "$MAKEDEFS2" ]; then
+  if [ -r $MAKEDEFS2 ]; then
     MAKEDEFS=$MAKEDEFS2
   else
     echo "No readable Make.defs file at $MAKEDEFS1 or $MAKEDEFS2"
diff --git a/tools/testbuild.sh b/tools/testbuild.sh
index 3925fdf..d23ca89 100755
--- a/tools/testbuild.sh
+++ b/tools/testbuild.sh
@@ -296,32 +296,8 @@ for line in $testlist; do
       boarddir=`echo $config | cut -d':' -f1`
     fi
 
-    # Detect the architecture of this board.
-
-    ARCHLIST="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
-    CHIPLIST="a1x am335x c5471 cxd56xx dm320 efm32 imx6 imxrt kinetis kl lc823450
-      lpc17xx_40xx lpc214x lpc2378 lpc31xx lpc43xx lpc54xx max326xx moxart nrf52
-      nuc1xx rx65n s32k1xx sam34 sama5 samd2l2 samd5e5 samv7 stm32 stm32f0l0g0 stm32f7 stm32h7
-      stm32l4 str71x tiva tms570 xmc4 at32uc3 at90usb atmega mcs92s12ne64 pic32mx
-      pic32mz lm32 mor1kx m32262f8 sh7032 fe310 k210 gap8 nr5m100 sim qemu esp32 z16f2811
-      ez80 z180 z8 z80"
-
-    for arch in ${ARCHLIST}; do
-      for chip in ${CHIPLIST}; do
-        if [ -f ${nuttx}/boards/${arch}/${chip}/${boarddir}/Kconfig ]; then
-          archdir=${arch}
-          chipdir=${chip}
-        fi
-      done
-    done
-
-    if [ -z "${archdir}" ]; then
-      echo "ERROR:  Architecture of ${boarddir} not found"
-      exit 1
-    fi
-
-    path=$nuttx/boards/$archdir/$chipdir/$boarddir/configs/$configdir
-    if [ ! -r "$path/defconfig" ]; then
+    path=$nuttx/boards/*/*/$boarddir/configs/$configdir
+    if [ ! -r $path/defconfig ]; then
       echo "ERROR: no configuration found at $path"
       showusage
     fi