?login_element?

Subversion Repositories NedoOS

Rev

Rev 129 | Blame | Compare with Previous | Last modification | View Log | Download

  1. #!/usr/bin/env bash
  2.  
  3. ## script init + helper functions
  4. HELP_STRING="Run the script from \033[96mproject root\033[0m directory without arguments."
  5. PROJECT_DIR=$PWD
  6. BUILD_DIR="$PROJECT_DIR/build/examples"
  7. exitCode=0
  8. totalAsmFiles=0        # +1 per ASM
  9.  
  10. source ContinuousIntegration/common_fn.sh
  11.  
  12. # read list of files to ignore, preserve spaces in file names, ignore comments
  13. ignoreAsmFiles=()
  14. if [[ -s ContinuousIntegration/examples_ignore.txt ]]; then
  15.     OLD_IFS=$IFS
  16.     IFS=$'\n'           # input/internal field separator
  17.     while read line; do
  18.         [[ -z "$line" ]] && continue            # skip empty lines
  19.         [[ "#" == ${line::1} ]] && continue     # skip comments
  20.         lineLen=${#line}
  21.         [[ '"' == ${line::1} && '"' == ${line:${lineLen}-1} ]] && line=${line:1:${lineLen}-2}
  22.         ignoreAsmFiles+=("${line}")
  23.     done < ContinuousIntegration/examples_ignore.txt
  24.     IFS=$OLD_IFS
  25. fi
  26. echo -e "Files to ignore: \033[93m${ignoreAsmFiles[@]}\033[0m"
  27.  
  28. echo -n -e "Project dir \"\033[96m${PROJECT_DIR}\033[0m\". "
  29.  
  30. # verify the directory structure is set up as expected and the working directory is project root
  31. [[ ! -f "${PROJECT_DIR}/ContinuousIntegration/test_folder_examples.sh" ]] && \
  32. echo -e "\033[91munexpected working directory\033[0m\n$HELP_STRING" && exit 1
  33. # check for unexpected arguments, bail out
  34. if [[ $# -gt 0 ]]; then
  35.     echo -e $HELP_STRING && exit 0
  36. fi
  37.  
  38. [[ -n "$EXE" ]] && echo -e "Using EXE=\033[96m$EXE\033[0m as assembler binary"
  39.  
  40. ## find the most fresh executable
  41. #[[ -z "$EXE" ]] && find_newest_binary sjasmplus "$PROJECT_DIR" \
  42. #    && echo -e "The most fresh binary found: \033[96m$EXE\033[0m"
  43. # reverted back to hard-coded "sjasmplus" for binary, as the date check seems to not work on some windows machines
  44.  
  45. [[ -z "$EXE" ]] && EXE=sjasmplus
  46.  
  47. # seek for files to be processed
  48. echo -n -e "Searching \033[96mexamples/**\033[0m for '*.asm'. "
  49. OLD_IFS=$IFS
  50. IFS=$'\n'
  51. EXAMPLE_FILES=($(find "$PROJECT_DIR/examples/"* -type f | grep -v -E '\.i\.asm$' | grep -E '\.asm$'))
  52. IFS=$OLD_IFS
  53.  
  54. # check if some files were found, print help message if search failed
  55. [[ -z $EXAMPLE_FILES ]] && echo -e "\033[91mno files found\033[0m\n$HELP_STRING" && exit 1
  56.  
  57. ## create temporary build directory for output
  58. echo -e "Creating temporary: \033[96m$BUILD_DIR\033[0m"
  59. rm -rf "$BUILD_DIR"
  60. # terminate in case the create+cd will fail, this is vital
  61. # also make sure the build dir has all required permissions
  62. mkdir -p "$BUILD_DIR" && chmod 700 "$BUILD_DIR" && cd "$BUILD_DIR" || exit 1
  63.  
  64. ## go through all asm files in examples directory and try to assemble them
  65. for f in "${EXAMPLE_FILES[@]}"; do
  66.     ## ignore files in the ignore list
  67.     for ignoreFile in "${ignoreAsmFiles[@]}"; do
  68.         [[ "$ignoreFile" == "${f#${PROJECT_DIR}/examples/}" ]] && f='IGNORE' && break
  69.     done
  70.     [[ 'IGNORE' == $f ]] && continue
  71.     ## standalone .asm file was found, try to build it
  72.     totalAsmFiles=$((totalAsmFiles + 1))
  73.     dirpath=`dirname "$f"`
  74.     asmname=`basename "$f"`
  75.     mainname="${f%.asm}"
  76.     # see if there are extra options defined
  77.     optionsF="${mainname}.options"
  78.     options=()
  79.     [[ -s "$optionsF" ]] && options=(`cat "${optionsF}"`)
  80.     ## built it with sjasmplus (remember exit code)
  81.     echo -e "\033[95mAssembling\033[0m \"\033[96m${asmname}\033[0m\" in \"\033[96m${dirpath##$PROJECT_DIR/}\033[0m\", options [\033[96m${options[@]}\033[0m]"
  82.     $MEMCHECK "$EXE" --nologo --msg=war --fullpath --inc="${dirpath}" "${options[@]}" "$f"
  83.     last_result=$?
  84.     ## report assembling exit code problem
  85.     if [[ $last_result -ne 0 ]]; then
  86.         echo -e "\033[91mError status $last_result\033[0m"
  87.         exitCode=$((exitCode + 1))
  88.     else
  89.         echo -e "\033[92mOK: done\033[0m"
  90.     fi
  91. done
  92. # display OK message if no error was detected
  93. [[ $exitCode -eq 0 ]] \
  94.     && echo -e "\033[92mFINISHED: OK, $totalAsmFiles examples built \033[91m\u25A0\033[93m\u25A0\033[32m\u25A0\033[96m\u25A0\033[0m" \
  95.     && exit 0
  96. # display error summary and exit with error code
  97. echo -e "\033[91mFINISHED: $exitCode/$totalAsmFiles examples failed \033[91m\u25A0\033[93m\u25A0\033[32m\u25A0\033[96m\u25A0\033[0m"
  98. exit $exitCode
  99.