Newer
Older
dub_jkp / test / issue895-local-configuration.sh
@Ömer Faruk IRMAK Ömer Faruk IRMAK on 1 Dec 2020 2 KB Use DC env variable as the default compiler
  1. #!/usr/bin/env bash
  2. . $(dirname "${BASH_SOURCE[0]}")/common.sh
  3.  
  4. if [ -e /var/lib/dub/settings.json ]; then
  5. die $LINENO 'Found existing system wide DUB configuration. Aborting.'
  6. fi
  7.  
  8. if [ -e ~/.dub/settings.json ]; then
  9. die $LINENO 'Found existing user wide DUB configuration. Aborting.'
  10. fi
  11.  
  12. cd ${CURR_DIR}
  13. mkdir -p ../etc/dub
  14. echo "{\"defaultCompiler\": \"foo\"}" > ../etc/dub/settings.json
  15. echo "Empty file named foo." > ../bin/foo
  16.  
  17. function cleanup {
  18. rm -r ../etc
  19. }
  20.  
  21. trap cleanup EXIT
  22.  
  23. unset DC
  24.  
  25. if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Unknown compiler: $(dirname $CURR_DIR)/bin/foo"; then
  26. rm ../bin/foo
  27. die $LINENO 'DUB did not find the local configuration with an adjacent compiler.'
  28. fi
  29.  
  30. echo "{\"defaultCompiler\": \"$CURR_DIR/foo\"}" > ../etc/dub/settings.json
  31. mv ../bin/foo $CURR_DIR
  32.  
  33. if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Unknown compiler: $CURR_DIR/foo"; then
  34. rm $CURR_DIR/foo
  35. die $LINENO 'DUB did not find a locally-configured compiler with an absolute path.'
  36. fi
  37.  
  38. echo "{\"defaultCompiler\": \"~/.dub/foo\"}" > ../etc/dub/settings.json
  39. mv $CURR_DIR/foo ~/.dub/
  40.  
  41. if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Unknown compiler: "; then
  42. rm ~/.dub/foo
  43. die $LINENO 'DUB did not find a locally-configured compiler with a tilde-prefixed path.'
  44. fi
  45.  
  46. echo "{\"defaultCompiler\": \"\$DUB_BINARY_PATH/../foo\"}" > ../etc/dub/settings.json
  47. mv ~/.dub/foo ..
  48.  
  49. if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Unknown compiler: $(dirname $CURR_DIR)/bin/../foo"; then
  50. rm ../foo
  51. die $LINENO 'DUB did not find a locally-configured compiler with a DUB-relative path.'
  52. fi
  53.  
  54. echo "{\"defaultCompiler\": \"../foo\"}" > ../etc/dub/settings.json
  55.  
  56. if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "defaultCompiler specified in a DUB config file cannot use an unqualified relative path"; then
  57. rm ../foo
  58. die $LINENO 'DUB did not error properly for a locally-configured compiler with a relative path.'
  59. fi
  60.  
  61. rm ../etc/dub/settings.json
  62. echo "Empty file named ldc2." > ../bin/ldc2
  63.  
  64. if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Failed to invoke the compiler $(dirname $CURR_DIR)/bin/ldc2 to determine the build platform"; then
  65. rm ../bin/ldc2
  66. die $LINENO 'DUB did not find ldc2 adjacent to it.'
  67. fi
  68.  
  69. echo "{\"defaultCompiler\": \"foo\"}" > ../etc/dub/settings.json
  70. rm ../bin/ldc2
  71. export PATH=$(dirname $CURR_DIR)${PATH:+:$PATH}
  72.  
  73. if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Unknown compiler: foo"; then
  74. rm ../foo
  75. die $LINENO 'DUB did not find a locally-configured compiler in its PATH.'
  76. fi
  77.  
  78. rm ../foo