@@ -296,7 +296,6 @@ SAFE_ENVVARS="\
296296 DISABLE_DOCS \
297297 ENABLE_DOCSPEC \
298298 DISABLE_DIST_CHECKS \
299- PATH \
300299 TOOLS_DIR \
301300 STACKVER \
302301 STACK_YAML \
@@ -322,9 +321,6 @@ SAFE_ENVVARS="\
322321 DOCSPEC_URL \
323322 DOCSPEC_OPTIONS \
324323 CHECK_ENV \
325- LANG \
326- LC_ALL \
327- BASE_TIME \
328324"
329325
330326UNSAFE_ENVVARS=" \
@@ -334,60 +330,45 @@ UNSAFE_ENVVARS="\
334330 CABAL_HACKAGE_MIRROR \
335331"
336332
337- ALLOW_CMD_PARAMS=" \
338- APPDATA \
339- NUMBER_OF_PROCESSORS \
340- PROCESSOR_IDENTIFIER \
333+ # Packcheck's own params
334+ PACKCHECK_ENVVARS=" $SAFE_ENVVARS $UNSAFE_ENVVARS "
335+
336+ # Standard environment variables allowed on command line
337+ ALLOW_COMMON_ENVVARS=" \
338+ PATH \
339+ LANG \
340+ LC_ALL \
341+ LC_CTYPE \
342+ HOME \
343+ XDG_CONFIG_HOME \
344+ XDG_CACHE_HOME \
345+ XDG_DATA_HOME \
346+ TMPDIR \
347+ LD_LIBRARY_PATH \
348+ DYLD_LIBRARY_PATH \
349+ LIBRARY_PATH \
350+ C_INCLUDE_PATH \
351+ PKG_CONFIG_PATH \
352+ HTTP_PROXY \
353+ HTTPS_PROXY \
354+ NO_PROXY \
341355CABAL_DIR \
342356CABAL_CONFIG \
343357CABAL_BUILDDIR \
344358STACK_ROOT \
345- HTTP_PROXY \
346- HTTPS_PROXY \
347- NO_PROXY \
348- "
349-
350- ENVVARS=" $SAFE_ENVVARS $UNSAFE_ENVVARS $ALLOW_CMD_PARAMS "
351-
352- ALLOW_SPECIAL_ENVVARS=" _"
353-
354- # These are allowed even in a clean environment.
355- # These are either critical to the functioning ro do not affect the produced
356- # artifacts..
357- ALLOW_COMMON_ENVVARS=" \
358- CHECK_ENV \
359- PWD \
360- SHLVL \
359+ GHC \
360+ GHC_PACKAGE_PATH \
361+ GHCRTS \
361362"
362363
363364ALLOW_WIN_ENVVARS=" \
364- MSYSTEM \
365- SYSTEMROOT \
366- WINDIR \
367365WINVER \
366+ APPDATA \
367+ NUMBER_OF_PROCESSORS \
368+ PROCESSOR_IDENTIFIER \
368369"
369370
370- ALLOW_OTHER_ENVVARS=" $ALLOW_COMMON_ENVVARS $ALLOW_WIN_ENVVARS "
371-
372- ALLOW_ENVVARS=" $ALLOW_SPECIAL_ENVVARS $ALLOW_OTHER_ENVVARS $ALLOW_WIN_ENVVARS "
373-
374- # We do not use HOME, we determine it independently and then set it internally.
375- OTHER_ENVVARS=" \
376- HOME \
377- XDG_CONFIG_HOME \
378- XDG_CACHE_HOME \
379- XDG_DATA_HOME \
380- TMPDIR \
381- LC_CTYPE \
382- LD_LIBRARY_PATH \
383- DYLD_LIBRARY_PATH \
384- C_INCLUDE_PATH \
385- LIBRARY_PATH \
386- PKG_CONFIG_PATH \
387- GHC \
388- GHC_PACKAGE_PATH \
389- GHCRTS \
390- "
371+ SYSTEM_ENVVARS=" $ALLOW_COMMON_ENVVARS $ALLOW_WIN_ENVVARS "
391372
392373# $1: varname
393374# $2: list of vars to find in
@@ -400,44 +381,15 @@ find_var() {
400381}
401382
402383error_novar () {
403- find_var " $1 " " $ENVVARS " || die " Unknown parameter or environment variable [$1 ]\nTry --help for supported parameters"
404- }
405-
406- error_clean_env () {
407- # $1 will now contain the list of all offending variables
408- echo " Error: The following unallowed environment variables are set:"
409- echo " $1 "
410- echo
411- echo " Error: No environment variables except [$ALLOW_OTHER_ENVVARS ] are allowed when using CHECK_ENV=y."
412- die " Please use a clean environment (e.g. env -i) with CHECK_ENV."
384+ find_var " $1 " " $PACKCHECK_ENVVARS " || die " Unknown parameter or environment variable [$1 ]\nTry --help for supported parameters"
413385}
414386
415387error_clean_param () {
416- die " Unknown parameter [$1 ] specified on command line.\nTry --help for supported parameters"
417- }
418-
419- check_clean_env () {
420- local vars=$( env | cut -f1 -d=)
421- local found_bad_vars=" "
422-
423- for i in $vars
424- do
425- if ! find_var " $i " " $ALLOW_ENVVARS " ; then
426- # Append the variable to our list
427- if [ -z " $found_bad_vars " ]; then
428- found_bad_vars=" $i "
429- else
430- found_bad_vars=" $found_bad_vars , $i "
431- fi
432- fi
433- done
434-
435- # If the list is not empty, report all of them and die
436- if [ -n " $found_bad_vars " ]; then
437- error_clean_env " $found_bad_vars "
438- fi
388+ die " Unknown command line parameter or environment variable [$1 ].\nTry --help for supported parameters"
439389}
440390
391+ # XXX We should not clear TMPDIR and any other temp dir related envvars
392+ # ghcup may depend on it.
441393unset_all_env () {
442394 # compgen -e lists only exported environment variables
443395 # It returns names only, so no parsing with 'cut' is needed
@@ -613,7 +565,7 @@ show_help() {
613565 # To catch spelling mistakes in envvar names passed, otherwise they will be
614566 # silently ignored and we will be wondering why the script is not working.
615567 help_envvar CHECK_ENV " [y] Treat unknown env variables as error, used with env -i"
616- help_envvar BASE_TIME " System time to be used as base for timeline reporting"
568+ # help_envvar BASE_TIME "System time to be used as base for timeline reporting"
617569}
618570
619571check_all_boolean_vars () {
@@ -658,7 +610,7 @@ show_build_command() {
658610 echo " You can use the following command to reproduce this build:"
659611 echo
660612 echo -n " $( basename $0 ) $BUILD "
661- for i in $SAFE_ENVVARS
613+ for i in $SAFE_ENVVARS $SYSTEM_ENVVARS
662614 do
663615 local val=" $( show_nonempty_var $i ) "
664616 test -z " $val " || echo -n " $val "
@@ -692,22 +644,20 @@ show_build_command() {
692644}
693645
694646# Environment on entry to packcheck
695- show_build_env () {
696- for i in $ALLOW_OTHER_ENVVARS $OTHER_ENVVARS
647+ show_system_env () {
648+ for i in $SYSTEM_ENVVARS
697649 do
698650 show_nonempty_var $i
699651 done
700652}
701653
702654# Environment just before the build, packcheck may have changed things.
703- show_build_config () {
655+ show_packcheck_config () {
704656 check_all_boolean_vars
705- for i in $ENVVARS
657+ for i in $PACKCHECK_ENVVARS
706658 do
707659 show_nonempty_var $i
708660 done
709- echo
710- show_build_env
711661}
712662
713663need_stack () {
@@ -1618,6 +1568,8 @@ ensure_cabal_project() {
16181568 if test -n " $implicit_proj_file "
16191569 then
16201570 echo " Implicit cabal project file found at [$implicit_proj_file ]"
1571+ else
1572+ echo " No cabal project file found or specified."
16211573 fi
16221574 fi
16231575 echo " Using cabal command [$CABALCMD ]"
@@ -2072,16 +2024,19 @@ build_and_test() {
20722024 case " $BUILD " in
20732025 stack)
20742026 show_step " Build and test"
2027+ echo " pwd: $( pwd) "
20752028 run_verbose_errexit $SDIST_STACKCMD build $STACK_BUILD_OPTIONS ;;
20762029 cabal-v2)
20772030 show_step " Build"
2031+ echo " pwd: $( pwd) "
20782032 run_verbose_errexit $SDIST_CABALCMD v2-build \
20792033 --with-compiler " $COMPILER_EXE_PATH " \
20802034 $GHCJS_FLAG $CABAL_BUILD_OPTIONS $CABAL_BUILD_TARGETS
20812035
20822036 if test -z " $DISABLE_DOCS "
20832037 then
20842038 show_step " Build haddock docs"
2039+ echo " pwd: $( pwd) "
20852040 run_verbose_errexit $SDIST_CABALCMD v2-haddock \
20862041 --with-compiler " $COMPILER_EXE_PATH " \
20872042 $GHCJS_FLAG $CABAL_BUILD_OPTIONS \
@@ -2099,6 +2054,7 @@ build_and_test() {
20992054 then
21002055 SHOW_DETAILS=" --test-show-details=streaming"
21012056 fi
2057+ echo " pwd: $( pwd) "
21022058 run_verbose_errexit $SDIST_CABALCMD v2-test \
21032059 --with-compiler " $COMPILER_EXE_PATH " \
21042060 $SHOW_DETAILS $GHCJS_FLAG $CABAL_BUILD_OPTIONS $CABAL_TEST_OPTIONS $CABAL_BUILD_TARGETS
@@ -2350,9 +2306,6 @@ build_pre_dep() {
23502306}
23512307
23522308build_post_dep () {
2353- show_step " Prepare to build"
2354- echo " pwd: $( pwd) "
2355-
23562309 build_and_test
23572310
23582311 if test -n " $COVERALLS_OPTIONS "
@@ -2463,17 +2416,13 @@ build_compile () {
24632416 fi
24642417 fi
24652418
2466- show_step " Prepare to install tools"
2467-
24682419 test -z " $( need_stack) " \
24692420 || ensure_stack ${LOCAL_BIN}
24702421
24712422 # The tar installed by pacman does not seem to work. Maybe we need to have it
24722423 # packed with msys itself.
24732424 # ensure_msys_tools "tar" && require_cmd tar
24742425
2475- # This may use STACKCMD so happens after stack install
2476- determine_build_type
24772426 ensure_ghc
24782427 ensure_cabal ${LOCAL_BIN}
24792428 ensure_docspec
@@ -2484,11 +2433,14 @@ build_compile () {
24842433 ;;
24852434 esac
24862435
2487- show_step " Effective build config"
2488- show_build_config
2436+ show_step " System environment before build"
2437+ show_system_env
2438+
2439+ show_step " Examine build and project definition files"
2440+ # This may use STACKCMD so happens after stack install
2441+ determine_build_type
24892442
24902443 # ---------Create dist, unpack, install deps, test--------
2491- show_step " Check tools and build configuration"
24922444 dont_need_cabal || ensure_cabal_project
24932445 if test -z " $DISABLE_SDIST_BUILD "
24942446 then
@@ -2502,6 +2454,7 @@ build_compile () {
25022454 # should be used.
25032455 if test -z " $DISABLE_SDIST_BUILD "
25042456 then
2457+ show_step " Prepare to build from source distribution"
25052458 if test -f " ./configure.ac"
25062459 then
25072460 echo " Package contains a 'configure.ac' file."
@@ -2510,12 +2463,7 @@ build_compile () {
25102463 echo " option if you do not have 'autoreconf' available"
25112464 require_cmd autoreconf
25122465 fi
2513- fi
2514-
2515- if test -z " $DISABLE_SDIST_BUILD "
2516- then
25172466 # Note this function leaves us in the package dir unpacked from sdist
2518- show_step " Prepare to build from source distribution"
25192467 create_and_unpack_pkg_dist $PACKAGE_FULL_NAME
25202468 fi
25212469
@@ -2544,7 +2492,7 @@ eval_env() {
25442492 (* =* )
25452493 key=${1%% =* }
25462494 val=${1#* =}
2547- find_var $key " $ENVVARS $ALLOW_ENVVARS " || error_clean_param " $key "
2495+ find_var $key " $PACKCHECK_ENVVARS $SYSTEM_ENVVARS " || error_clean_param " $key "
25482496 eval " export $key =\" $val \" "
25492497 ;;
25502498 (* )
@@ -2647,19 +2595,19 @@ esac
26472595BUILD=$1 ; shift
26482596case $BUILD in
26492597 cabal|cabal-v2|stack|hlint)
2650- show_step1 " Implicit environment"
2598+ show_step1 " Implicit System environment on entry "
26512599 if test -n " $CHECK_ENV "
26522600 then
26532601 check_boolean_var CHECK_ENV
26542602 echo " CHECK_ENV=y; ignoring all environment, make sure to pass a sensible PATH on command line"
26552603 unset_all_env
26562604 fi
2657- show_build_env
2605+ show_system_env
26582606 ;;
26592607 * ) ;;
26602608esac
26612609
2662- # This allows only ALLOW_ENVVARS to be set on the command line
2610+ # This allows only SYSTEM_ENVVARS to be set on the command line
26632611eval_env " $@ "
26642612# After eval_env the PATH changes
26652613hash -r
@@ -2671,9 +2619,20 @@ test -n "$BASE_TIME" || BASE_TIME=$(get_sys_time)
26712619
26722620# ------------------------------------------------------------------------------
26732621
2622+ SHELL_HOME=$( echo ~ )
2623+
26742624# Need these to produce help
26752625# Determine home independent of the environment
2676- export HOME=$( echo ~ )
2626+ if test -z " $HOME "
2627+ then
2628+ export HOME=" $SHELL_HOME "
2629+ else
2630+ if test " $HOME " ! = " $SHELL_HOME "
2631+ then
2632+ die " HOME environment variable [$HOME ] is not the same as shell's ~ [$SHELL_HOME ]"
2633+ fi
2634+ fi
2635+
26772636set_os_specific_vars # depends on HOME
26782637
26792638LOCAL_BIN=$OS_APP_HOME /$OS_LOCAL_DIR /bin
@@ -2727,6 +2686,16 @@ bash --version
27272686show_step " Build command"
27282687show_build_command
27292688
2689+ echo
2690+ echo " Packcheck config parameters:"
2691+ echo
2692+ show_packcheck_config
2693+
2694+ echo
2695+ echo " System environment parameters"
2696+ echo
2697+ show_system_env
2698+
27302699if test -n " $BUILD_DEPS_ONLY " -a -n " $BUILD_PACKAGE_ONLY "
27312700then
27322701 die " Both [BUILD_DEPS_ONLY] and [BUILD_PACKAGE_ONLY] cannot be set at the same time."
0 commit comments