You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
14 KiB

  1. #!/bin/bash
  2. # WARNING: This script will modify file associations and MIME types on the system it
  3. # runs on. Use at your own risk!
  4. # The root of the code directory is the first argument
  5. KICAD_CODE_DIR=$1
  6. # The root of the build directory is the second argument
  7. KICAD_BUILD_DIR=$2
  8. KICAD_LAUNCHER_DIR=$KICAD_BUILD_DIR/resources/linux/launchers
  9. KICAD_METAINFO_DIR=$KICAD_BUILD_DIR/resources/linux/metainfo
  10. KICAD_MIME_DIR=$KICAD_BUILD_DIR/resources/linux/mime
  11. KICAD_ICON_DIR=$KICAD_CODE_DIR/resources/linux/icons/hicolor
  12. KICAD_MIME_TEST_FILES=$KICAD_CODE_DIR/qa/resources/linux/mimeFiles
  13. ###################################################################
  14. # Verify the metainfo file
  15. # There are two different checkers we can use, and each distro prefers
  16. # different ones - so lets just test using them both and make them both
  17. # happy.
  18. ###################################################################
  19. METAINFO_VALID=1
  20. echo "Validating metainfo files"
  21. # Test using appstreamcli to see its errors
  22. appstreamcli validate --explain --pedantic $KICAD_METAINFO_DIR/org.kicad.kicad.metainfo.xml
  23. [ $? -ne 0 ] && METAINFO_VALID=0
  24. # Test using the appstream-util package to see its errors
  25. appstream-util validate-strict $KICAD_METAINFO_DIR/org.kicad.kicad.metainfo.xml
  26. [ $? -ne 0 ] && METAINFO_VALID=0
  27. if [ $METAINFO_VALID -eq 1 ]
  28. then
  29. echo "Metainfo files passed both checkers successfully"
  30. fi
  31. ###################################################################
  32. # Verify the launcher files
  33. ###################################################################
  34. LAUNCHERS_VALID=1
  35. echo ""
  36. echo "Validating desktop launcher files"
  37. # Bitmap2component
  38. desktop-file-validate $KICAD_LAUNCHER_DIR/org.kicad.bitmap2component.desktop
  39. [ $? -ne 0 ] && LAUNCHERS_VALID=0
  40. # Eeschema standalone
  41. desktop-file-validate $KICAD_LAUNCHER_DIR/org.kicad.eeschema.desktop
  42. [ $? -ne 0 ] && LAUNCHERS_VALID=0
  43. # GerbView
  44. desktop-file-validate $KICAD_LAUNCHER_DIR/org.kicad.gerbview.desktop
  45. [ $? -ne 0 ] && LAUNCHERS_VALID=0
  46. # Main KiCad application
  47. desktop-file-validate $KICAD_LAUNCHER_DIR/org.kicad.kicad.desktop
  48. [ $? -ne 0 ] && LAUNCHERS_VALID=0
  49. # PCB calculator
  50. desktop-file-validate $KICAD_LAUNCHER_DIR/org.kicad.pcbcalculator.desktop
  51. [ $? -ne 0 ] && LAUNCHERS_VALID=0
  52. # Pcbnew standalond
  53. desktop-file-validate $KICAD_LAUNCHER_DIR/org.kicad.pcbnew.desktop
  54. [ $? -ne 0 ] && LAUNCHERS_VALID=0
  55. if [ $LAUNCHERS_VALID -eq 1 ]
  56. then
  57. echo "All launcher files valid"
  58. else
  59. echo "Errors with launcher files"
  60. fi
  61. ###################################################################
  62. # Install the desktop and MIME-type files and update the databases
  63. ###################################################################
  64. GERBER_MIME_INSTALLED=0
  65. KICAD_MIME_INSTALLED=0
  66. echo ""
  67. echo "Installing MIME type files for testing"
  68. mkdir -p ~/.local/share/mime
  69. xdg-mime install --mode user $KICAD_MIME_DIR/kicad-gerbers.xml
  70. [ $? -eq 0 ] && GERBER_MIME_INSTALLED=1
  71. xdg-icon-resource install --mode user --context mimetypes --size 128 $KICAD_ICON_DIR/128x128/mimetypes/application-x-kicad-pcb.png
  72. xdg-icon-resource install --mode user --context mimetypes --size 128 $KICAD_ICON_DIR/128x128/mimetypes/application-x-kicad-project.png
  73. xdg-icon-resource install --mode user --context mimetypes --size 128 $KICAD_ICON_DIR/128x128/mimetypes/application-x-kicad-schematic.png
  74. xdg-mime install --mode user $KICAD_MIME_DIR/kicad-kicad.xml
  75. [ $? -eq 0 ] && KICAD_MIME_INSTALLED=1
  76. # Install the desktop files
  77. echo ""
  78. echo "Installing desktop files for testing"
  79. # Ensure the directory exists (it might not in the CI image)
  80. mkdir -p ~/.local/share/applications
  81. # For some reason, desktop-file-install doesn't seem to actually install it properly, so just copy them
  82. cp $KICAD_LAUNCHER_DIR/org.kicad.bitmap2component.desktop ~/.local/share/applications/
  83. cp $KICAD_LAUNCHER_DIR/org.kicad.eeschema.desktop ~/.local/share/applications/
  84. cp $KICAD_LAUNCHER_DIR/org.kicad.gerbview.desktop ~/.local/share/applications/
  85. cp $KICAD_LAUNCHER_DIR/org.kicad.kicad.desktop ~/.local/share/applications/
  86. cp $KICAD_LAUNCHER_DIR/org.kicad.pcbcalculator.desktop ~/.local/share/applications/
  87. cp $KICAD_LAUNCHER_DIR/org.kicad.pcbnew.desktop ~/.local/share/applications/
  88. # Force a database update to get the desktop files and MIME types associated
  89. update-desktop-database ~/.local/share/applications/
  90. update-mime-database ~/.local/share/mime/
  91. ###################################################################
  92. # Validate the MIME types
  93. ###################################################################
  94. KICAD_MIME_VALID=1
  95. GERBER_MIME_VALID=1
  96. # Fake a Gnome desktop environment to force xdg-mime to query using gio and ensure the MIME types are installed
  97. # for a desktop environment. Otherwise it fallsback to using the "file --mime-type" command, which has prebuilt
  98. # magic files from https://github.com/file/file/blob/master/magic/Magdir/kicad and isn't affected by the MIME
  99. # type files we just installed.
  100. export DE=gnome
  101. # Test install the gerber MIME file to test with it
  102. echo ""
  103. if [ $GERBER_MIME_INSTALLED -eq 1 ]
  104. then
  105. echo "Validating Gerber MIME-type"
  106. # Test the drl extension default
  107. OUT_STR=$(xdg-mime query default application/x-excellon 2>&1)
  108. printf " Testing drill file default application: %s\n" "$OUT_STR"
  109. [[ "$OUT_STR" != "org.kicad.gerbview.desktop" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  110. # Test the gerber extension default
  111. OUT_STR=$(xdg-mime query default application/x-gerber 2>&1)
  112. printf " Testing gerber file default application: %s\n" "$OUT_STR"
  113. [[ "$OUT_STR" != "org.kicad.gerbview.desktop" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  114. # Test the drl extension
  115. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/drillFiles/drillFile.drl 2>&1)
  116. printf " Testing drill file with extension drl: %s\n" "$OUT_STR"
  117. [[ "$OUT_STR" != "application/x-excellon" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  118. # Test the parsing of the header for M48
  119. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/drillFiles/drillFileNoExt 2>&1)
  120. printf " Testing drill file header M48 check: %s\n" "$OUT_STR"
  121. [[ "$OUT_STR" != "application/x-excellon" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  122. # Test the official gbr extension
  123. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/gerberFiles/gerber.gbr 2>&1)
  124. printf " Testing gerber file with gbr extension: %s\n" "$OUT_STR"
  125. [[ "$OUT_STR" != "application/x-gerber" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  126. # Test the parsing of the header for a comment (G04)
  127. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/gerberFiles/gerberCommentNoExt 2>&1)
  128. printf " Testing gerber file header G04 check: %s\n" "$OUT_STR"
  129. [[ "$OUT_STR" != "application/x-gerber" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  130. # Test the parsing of the header for %FSLA
  131. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/gerberFiles/gerberFSLANoExt 2>&1)
  132. printf " Testing gerber file header %%FLSA check: %s\n" "$OUT_STR"
  133. [[ "$OUT_STR" != "application/x-gerber" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  134. # Test the parsing of the header for %MO
  135. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/gerberFiles/gerberMONoExt 2>&1)
  136. printf " Testing gerber file header %%MO check: %s\n" "$OUT_STR"
  137. [[ "$OUT_STR" != "application/x-gerber" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  138. # Test the parsing of the header for %TF.
  139. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/gerberFiles/gerberTFNoExt 2>&1)
  140. printf " Testing gerber file header %%TF. check: %s\n" "$OUT_STR"
  141. [[ "$OUT_STR" != "application/x-gerber" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  142. # Test the parsing of the header for G75*.
  143. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/gerberFiles/gerberG75NoExt 2>&1)
  144. printf " Testing gerber file header G75* check: %s\n" "$OUT_STR"
  145. [[ "$OUT_STR" != "application/x-gerber" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  146. # Test parsing another popular gerber extension (will require a lookup)
  147. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/gerbers/gerberFiles/gerber.gts 2>&1)
  148. printf " Testing gerber file with gts extension (not glob'd): %s\n" "$OUT_STR"
  149. [[ "$OUT_STR" != "application/x-gerber" ]] && echo " ERROR" && GERBER_MIME_VALID=0
  150. if [ $GERBER_MIME_VALID -eq 1 ]
  151. then
  152. echo "All Gerber MIME-type files valid"
  153. else
  154. echo "Errors with Gerber MIME-type files"
  155. fi
  156. else
  157. echo "Gerber MIME type files not installed, skipping validation"
  158. GERBER_MIME_VALID=0
  159. fi
  160. # Test install the KiCad MIME file to test with it
  161. echo ""
  162. if [ $KICAD_MIME_INSTALLED -eq 1 ]
  163. then
  164. echo "Validating KiCad MIME-type"
  165. # Test the KiCad project file extension default
  166. OUT_STR=$(xdg-mime query default application/x-kicad-project 2>&1)
  167. printf " Testing KiCad project file default application: %s\n" "$OUT_STR"
  168. [[ "$OUT_STR" != "org.kicad.kicad.desktop" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  169. # Test the KiCad schematic file extension default
  170. OUT_STR=$(xdg-mime query default application/x-kicad-schematic 2>&1)
  171. printf " Testing KiCad schematic file default application: %s\n" "$OUT_STR"
  172. [[ "$OUT_STR" != "org.kicad.eeschema.desktop" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  173. # Test the KiCad project file extension default
  174. OUT_STR=$(xdg-mime query default application/x-kicad-pcb 2>&1)
  175. printf " Testing KiCad board file default application: %s\n" "$OUT_STR"
  176. [[ "$OUT_STR" != "org.kicad.pcbnew.desktop" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  177. # Test the old pcbnew board file extension (brd) - (will cause lookup since not glob'd)
  178. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/boardFiles/brd.brd 2>&1)
  179. printf " Testing old Pcbnew board file with extension brd: %s\n" "$OUT_STR"
  180. [[ "$OUT_STR" != "application/x-kicad-pcb" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  181. # Test the old pcbnew board file with header check
  182. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/boardFiles/brdNoExt 2>&1)
  183. printf " Testing old Pcbnew board file header: %s\n" "$OUT_STR"
  184. [[ "$OUT_STR" != "application/x-kicad-pcb" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  185. # Test the new pcbnew board file extension (kicad_pcb)
  186. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/boardFiles/kicadpcb.kicad_pcb 2>&1)
  187. printf " Testing new Pcbnew board file with extension kicad_pcb: %s\n" "$OUT_STR"
  188. [[ "$OUT_STR" != "application/x-kicad-pcb" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  189. # Test the new pcbnew board file with header check
  190. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/boardFiles/kicadpcbNoExt 2>&1)
  191. printf " Testing new Pcbnew board file header: %s\n" "$OUT_STR"
  192. [[ "$OUT_STR" != "application/x-kicad-pcb" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  193. # Test the old eeschema schematic file extension (sch)
  194. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/schematicFiles/sch.sch 2>&1)
  195. printf " Testing old Eeschema schematic file with extension sch: %s\n" "$OUT_STR"
  196. [[ "$OUT_STR" != "application/x-kicad-schematic" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  197. # Test the brd extension
  198. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/schematicFiles/schNoExt 2>&1)
  199. printf " Testing old Eeschema schematic file header: %s\n" "$OUT_STR"
  200. [[ "$OUT_STR" != "application/x-kicad-schematic" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  201. # Test the new Eeschema schematic file extension (kicad_sch)
  202. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/schematicFiles/kicadsch.kicad_sch 2>&1)
  203. printf " Testing new Eeschema schematic file with extension kicad_sch: %s\n" "$OUT_STR"
  204. [[ "$OUT_STR" != "application/x-kicad-schematic" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  205. # Test the new Eeschema board file with header check
  206. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/schematicFiles/kicadschNoExt 2>&1)
  207. printf " Testing new Eeschema schematic file header: %s\n" "$OUT_STR"
  208. [[ "$OUT_STR" != "application/x-kicad-schematic" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  209. # Test the old project file extension (pro)
  210. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/projectFiles/pro.pro 2>&1)
  211. printf " Testing old KiCad project file with extension pro: %s\n" "$OUT_STR"
  212. [[ "$OUT_STR" != "application/x-kicad-project" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  213. # Test the new project file extension (kicad_pro)
  214. OUT_STR=$(xdg-mime query filetype $KICAD_MIME_TEST_FILES/kicad/projectFiles/kicadpro.kicad_pro 2>&1)
  215. printf " Testing new KiCad project file with extension kicad_pro: %s\n" "$OUT_STR"
  216. [[ "$OUT_STR" != "application/x-kicad-project" ]] && echo " ERROR" && KICAD_MIME_VALID=0
  217. if [ $KICAD_MIME_VALID -eq 1 ]
  218. then
  219. echo "All KiCad MIME-type files valid"
  220. else
  221. echo "Errors with KiCad MIME-type files"
  222. fi
  223. else
  224. echo "KiCad MIME type files not installed, skipping validation"
  225. KICAD_MIME_VALID=0
  226. fi
  227. ###################################################################
  228. # Process return codes to flag errors for CI
  229. ###################################################################
  230. [ $METAINFO_VALID -ne 0 ] && exit 1
  231. [ $LAUNCHERS_VALID -ne 0 ] && exit 1
  232. [ $KICAD_MIME_VALID -ne 0 ] && exit 1
  233. [ $GERBER_MIME_VALID -ne 0 ] && exit 1
  234. exit 0