conan: [bug] generated conanbuildenv appears to be missing list "for v in"

Describe the bug

Attempting to start using conan2 building on AIX Power8 ppc64 Conan 2.12

AIX toolbox installed Python 3.7 CMake 2.16

default shell is /bin/ksh, but same happens if changing to /bin/sh

Building expat, c-ares or any other dependency so far

======== Input profiles ======== Profile host: [settings] arch=ppc64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=8 os=AIX [conf]

Profile build: [settings] arch=ppc64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=8 os=AIX [conf]

Build gives error, that looks like cmake failing, but seems to be from the generated conanbuildenv

-------- Installing package expat/2.7.1 (1 of 11) -------- expat/2.7.1: Building from source expat/2.7.1: Package expat/2.7.1:4b3487e36b23b8c80576f6b45c4385b61d49f7c8 expat/2.7.1: Copying sources to build folder expat/2.7.1: Building your package in ~/.conan2/p/b/expat06579fa46dd6b/b expat/2.7.1: Calling generate() expat/2.7.1: Generators folder: ~/.conan2/p/b/expat06579fa46dd6b/b/build/Release/generators expat/2.7.1: CMakeToolchain generated: conan_toolchain.cmake expat/2.7.1: CMakeToolchain generated: ~/.conan2/p/b/expat06579fa46dd6b/b/build/Release/generators/CMakePresets.json expat/2.7.1: CMakeToolchain generated: ~/.conan2/p/b/expat06579fa46dd6b/b/src/CMakeUserPresets.json expat/2.7.1: Generating aggregated env files expat/2.7.1: Generated aggregated env files: [‘conanbuild.sh’, ‘conanrun.sh’] expat/2.7.1: Calling build() expat/2.7.1: apply_conandata_patches(): No patches defined in conandata expat/2.7.1: Running CMake.configure() expat/2.7.1: RUN: cmake -G “Unix Makefiles” -DCMAKE_TOOLCHAIN_FILE=“generators/conan_toolchain.cmake” -DCMAKE_INSTALL_PREFIX=“~/.conan2/p/b/expat06579fa46dd6b/p” -DCMAKE_POLICY_DEFAULT_CMP0091=“NEW” -DCMAKE_BUILD_TYPE=“Release” “~/.conan2/p/b/expat06579fa46dd6b/b/src” /bin/sh: 0403-057 Syntax error at line 4 : `newline or ;’ is not expected.

expat/2.7.1: ERROR: Package ‘4b3487e36b23b8c80576f6b45c4385b61d49f7c8’ build failed expat/2.7.1: WARN: Build folder ~/.conan2/p/b/expat06579fa46dd6b/b/build/Release ERROR: expat/2.7.1: Error in build() method, line 68 cmake.configure() ConanException: Error 2 while executing

Trying to debug I found similar error message running ~/.conan2/p/b/expat06579fa46dd6b/b/build/Release/generators/conanbuildenv-release-ppc64.sh

~/.conan2/p/b/expat06579fa46dd6b/b/build/Release/generators/conanbuildenv-release-ppc64.sh[3]: 0403-057 Syntax error at line 4 : `newline or ;’ is not expected.

script_folder="/home/nds_cm/.conan2/p/b/expat06579fa46dd6b/b/build/Release/generators"
echo "echo Restoring environment" > "$script_folder/deactivate_conanbuildenv-release-ppc64.sh"
for v in
do
    is_defined="true"
    value=$(printenv $v) || is_defined="" || true
    if [ -n "$value" ] || [ -n "$is_defined" ]
    then
        echo export "$v='$value'" >> "$script_folder/deactivate_conanbuildenv-release-ppc64.sh"
    else
        echo unset $v >> "$script_folder/deactivate_conanbuildenv-release-ppc64.sh"
    fi
done

Line 4 seems to be missing a list of some sort

How to reproduce it

Cut down conan file demonstrates the issue conanfile.zip

conan install ../conanfile.py -r aauth -u -pr:b=gcc8-aix -pr:h=gcc8-aix -u --output-folder=. -s build_type=Release --build missing

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

Trying with newer korn 93 shell, problem is avoided

That is good news, it sounds that the default korn shell is the older one, and the syntax support was lacking.

The admin would really prefer not to change the default /bin/sh of the system Is there any possibility to make it a configurable option ?

At the moment it is not planned, we haven’t seen enough evidence of demand for this, and this still looks like a very niche use case. I can discuss this with the team and get some more opinitions, marking as “Look into”

other issue with linking - static build seems to be a problem

This sounds completely unrelated, would need a different ticket, might be a recipe (it looks cares) issue, like it is possible that some recipes in ConanCenter do not build for AIX, and it could be a thing from the Conan recipe or it might be the library itself lacking support to build in AIX.

/bin/sh: 0403-057 Syntax error: `;’ is not expected.

But it seems that you are using sh. Can you please try with a bash shell?

Is my understanding correct it’s actually cmake calling the script in this case via /bin/sh in some way, or is conan reporting a description of trying to perform cmake configure, which has a first step of applying the env config source conanbuildenv-release-ppc64.sh before actually calling cmake?

Not really. If you use the conan .... -vvv to see extra verbose messages, you will see that the actual commands are more like:

$ source /path/to/conanbuild.sh && cmake ...

And it would be the sourcing of the conanbuild.sh

It seems the shell in AIX is not accepting iterating over an empty set. In linux both work:

for v in 1 2 3
do
  echo $v
done

produces

source myscript.sh
1
2
3

And

for v in
do
  echo $v
done

Produces just a blank line, nothing is output, but it doesn’t fail or crash either.

Wondering if always including the command end separator can get around the limitation in the shell because ‘do’ is on the next line often the ‘in [list]’ command end seperator ‘;’ can be left out, but in this /bin/sh or ksh it seems helpful. is there an easy way to test that?

ie.

for v in ; do

Some quick feedback, not sure if it does make a difference regarding the error that you are seeing.

The scripts are not intended to be executed, they will not work if executed, they need to be sourced, like:

source  myfile.sh
. myfile.sh # the dot is the same as "source"

This is why they don’t have shebang, because they cannot execute in a child shell, they need to execute in the current shell (sourced).