openenclave: openenclaverc does not allow switching between different OE SDK installs

I was investigating an issue where I needed to build OE within different configurations, install and then build a test application. Turns out that openenclaverc appends to PATH and PKG_CONFIG_PATH variables.

source install1/share/openenclave/openenclaverc
do some stuff

source install2/share/openenclave/openenclaverc
do some more stuff <- this ends up using install1

Since paths are appended, the first install of OE SDK is always picked up.

I am not sure what the Linux way of fixing this is. Prepend to the paths? CC: @andschwa @johnkord

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@aserdean I think we’re going to go with @andschwa 's suggestion above, where we won’t be setting a user’s PATH or PKG_CONFIG_PATH or cmake path, and we will completely remove this script and document how a user should set their variables to use our dev tools.

My recommendation is to retain the feature but get it working right. Here is a solution:

# Remove __OPEN_ENCLAVE_CURRENT_BINDIR from path and extend the path.
extend_path()
{
    # Delete __OPEN_ENCLAVE_CURRENT_BINDIR from PATH:
    if [ ! -z "${__OPEN_ENCLAVE_CURRENT_BINDIR}" ]; then
        export PATH=${PATH/:${__OPEN_ENCLAVE_CURRENT_BINDIR}/}
    fi

    # Save this variable so it can be removed when path is extended again.
    export __OPEN_ENCLAVE_CURRENT_BINDIR=$1

    # Add ${__OPEN_ENCLAVE_CURRENT_BINDIR} to the path:
    export PATH=${PATH}:${__OPEN_ENCLAVE_CURRENT_BINDIR}
}

extend_path "/opt/oe1/bin"
echo "PATH=${PATH}"
extend_path "/opt/oe2/bin"
echo "PATH=${PATH}"
extend_path "/opt/oe3/bin"
echo "PATH=${PATH}"

This is a fun one 😄

I’m with Andy, providing this rc file is something I’ve never seen another linux library do and I don’t think we should either. It does very little, if users want to add the install location to their path that should be up to them.

I think the real problem here is that the open-enclave package doesn’t install our libraries/includes/pkgconfig in canonical locations (such as /usr/lib for libraries). So the openenclaverc is a bandaid to fix that problem.

Agree that cleaner way will be to remove the openenclaverc file and provide guidance to the developers/users. Here are some specific caveats: The openenclaverc file is run before samples can be built or run from the install directory. If this file is removed, then samples/README.md should be modified and adequately tested with this PR. I also suspect there may be a few other places where this file is populated, etc. which will need to be changed as well.

@soccerGB

Less code written is less code maintained 😁