1*da0073e9SAndroid Build Coastguard Worker# Simple script used to easily search all packages in conda for their 2*da0073e9SAndroid Build Coastguard Worker# dependency requirements 3*da0073e9SAndroid Build Coastguard Worker# TODO also search through output of ldd 4*da0073e9SAndroid Build Coastguard Worker# TODO update conda info syntax for different channels 5*da0073e9SAndroid Build Coastguard Worker 6*da0073e9SAndroid Build Coastguard Workerif [ -z "$CONDA_ROOT" ]; then 7*da0073e9SAndroid Build Coastguard Worker # TODO create our own environment 8*da0073e9SAndroid Build Coastguard Worker echo "Please set CONDA_ROOT so that I know where to search for conda libraries" 9*da0073e9SAndroid Build Coastguard Worker echo "I expect CONDA_ROOT to be the path to the current conda environment." 10*da0073e9SAndroid Build Coastguard Worker echo "Also FYI I will probably mess up the current conda environment." 11*da0073e9SAndroid Build Coastguard Worker exit 1 12*da0073e9SAndroid Build Coastguard Workerfi 13*da0073e9SAndroid Build Coastguard Worker 14*da0073e9SAndroid Build Coastguard Workerif [ -z "$1" ]; then 15*da0073e9SAndroid Build Coastguard Worker echo "Please give me a package name to search for" 16*da0073e9SAndroid Build Coastguard Worker exit 1 17*da0073e9SAndroid Build Coastguard Workerfi 18*da0073e9SAndroid Build Coastguard WorkerPKG_NAME="$1" 19*da0073e9SAndroid Build Coastguard Worker 20*da0073e9SAndroid Build Coastguard Workerif [ -n "$2" ]; then 21*da0073e9SAndroid Build Coastguard Worker echo "Searching in channel $2" 22*da0073e9SAndroid Build Coastguard Worker CONDA_CHANNEL="$2" 23*da0073e9SAndroid Build Coastguard Workerfi 24*da0073e9SAndroid Build Coastguard Worker 25*da0073e9SAndroid Build Coastguard Worker# These are the packages of interest to search the dependencies for 26*da0073e9SAndroid Build Coastguard Worker# TODO use this 27*da0073e9SAndroid Build Coastguard WorkerPACKAGES_OF_INTEREST=( libgcc-ng libprotobuf numpy ) 28*da0073e9SAndroid Build Coastguard Worker 29*da0073e9SAndroid Build Coastguard Worker# We will run `conda install` and `conda uninstall` a lot, but we don't want 30*da0073e9SAndroid Build Coastguard Worker# this very noisy output to clutter the user experience 31*da0073e9SAndroid Build Coastguard WorkerVERBOSE_LOG='read_conda_versions.log' 32*da0073e9SAndroid Build Coastguard Workerecho "Conda install/uninstall log for $PKG_NAME" > $VERBOSE_LOG 33*da0073e9SAndroid Build Coastguard Worker 34*da0073e9SAndroid Build Coastguard Worker 35*da0073e9SAndroid Build Coastguard Worker 36*da0073e9SAndroid Build Coastguard Worker# 37*da0073e9SAndroid Build Coastguard Worker# Build up the name of the installed library to call `nm` on 38*da0073e9SAndroid Build Coastguard Worker# 39*da0073e9SAndroid Build Coastguard WorkerPKG_INSTALLED_LIB="$PKG_NAME" 40*da0073e9SAndroid Build Coastguard Worker 41*da0073e9SAndroid Build Coastguard Worker# opencv installs a bunch of libraries. We'll just check libopencv_core 42*da0073e9SAndroid Build Coastguard Workerif [[ $PKG_NAME == opencv ]]; then 43*da0073e9SAndroid Build Coastguard Worker PKG_INSTALLED_LIB="${PKG_INSTALLED_LIB}_core" 44*da0073e9SAndroid Build Coastguard Workerfi 45*da0073e9SAndroid Build Coastguard Worker 46*da0073e9SAndroid Build Coastguard Worker# Most packages prepend a 'lib' to the package name, but libprotobuf is an 47*da0073e9SAndroid Build Coastguard Worker# exception 48*da0073e9SAndroid Build Coastguard Workerif [[ $PKG_NAME != lib* ]]; then 49*da0073e9SAndroid Build Coastguard Worker PKG_INSTALLED_LIB="lib${PKG_INSTALLED_LIB}" 50*da0073e9SAndroid Build Coastguard Workerfi 51*da0073e9SAndroid Build Coastguard Worker 52*da0073e9SAndroid Build Coastguard Worker# The shared library suffix differs on macOS an Linux 53*da0073e9SAndroid Build Coastguard Workerif [[ "$(uname)" == Darwin ]]; then 54*da0073e9SAndroid Build Coastguard Worker PKG_INSTALLED_LIB="${PKG_INSTALLED_LIB}.dylib" 55*da0073e9SAndroid Build Coastguard Workerelse 56*da0073e9SAndroid Build Coastguard Worker PKG_INSTALLED_LIB="${PKG_INSTALLED_LIB}.so" 57*da0073e9SAndroid Build Coastguard Workerfi 58*da0073e9SAndroid Build Coastguard Workerecho "Determined the library name of $PKG_NAME to be $PKG_INSTALLED_LIB" 59*da0073e9SAndroid Build Coastguard Workerecho "Determined the library name of $PKG_NAME to be $PKG_INSTALLED_LIB" >> $VERBOSE_LOG 60*da0073e9SAndroid Build Coastguard Worker 61*da0073e9SAndroid Build Coastguard Worker 62*da0073e9SAndroid Build Coastguard Worker 63*da0073e9SAndroid Build Coastguard Worker# 64*da0073e9SAndroid Build Coastguard Worker# Get all available packages with conda-search 65*da0073e9SAndroid Build Coastguard Worker# 66*da0073e9SAndroid Build Coastguard Worker 67*da0073e9SAndroid Build Coastguard Worker# Split the output from conda search into an array, one line per package (plus 68*da0073e9SAndroid Build Coastguard Worker# the header) 69*da0073e9SAndroid Build Coastguard Workerconda_search_packages=() 70*da0073e9SAndroid Build Coastguard Workerwhile read -r line; do conda_search_packages+=("$line"); done <<< "$(conda search $PKG_NAME $CONDA_CHANNEL)" 71*da0073e9SAndroid Build Coastguard Worker 72*da0073e9SAndroid Build Coastguard Worker### Typical `conda search` output looks like 73*da0073e9SAndroid Build Coastguard Worker### Loading channels: done 74*da0073e9SAndroid Build Coastguard Worker### Name Version Build Channel 75*da0073e9SAndroid Build Coastguard Worker### protobuf 2.6.1 py27_0 defaults 76*da0073e9SAndroid Build Coastguard Worker### 2.6.1 py27_1 defaults 77*da0073e9SAndroid Build Coastguard Worker### 3.2.0 py27_0 defaults 78*da0073e9SAndroid Build Coastguard Worker### 3.2.0 py35_0 defaults 79*da0073e9SAndroid Build Coastguard Worker### 3.2.0 py36_0 defaults 80*da0073e9SAndroid Build Coastguard Worker### 3.4.1 py27h66c1d77_0 defaults 81*da0073e9SAndroid Build Coastguard Worker### 3.4.1 py35h9d33684_0 defaults 82*da0073e9SAndroid Build Coastguard Worker### 3.4.1 py36h314970b_0 defaults 83*da0073e9SAndroid Build Coastguard Worker### 3.5.1 py27h0a44026_0 defaults 84*da0073e9SAndroid Build Coastguard Worker### 3.5.1 py35h0a44026_0 defaults 85*da0073e9SAndroid Build Coastguard Worker### 3.5.1 py36h0a44026_0 defaults 86*da0073e9SAndroid Build Coastguard Worker## 87*da0073e9SAndroid Build Coastguard Worker### Typical `conda info` output looks like 88*da0073e9SAndroid Build Coastguard Worker### protobuf 3.5.1 py36h0a44026_0 89*da0073e9SAndroid Build Coastguard Worker### ----------------------------- 90*da0073e9SAndroid Build Coastguard Worker### file name : protobuf-3.5.1-py36h0a44026_0.tar.bz2 91*da0073e9SAndroid Build Coastguard Worker### name : protobuf 92*da0073e9SAndroid Build Coastguard Worker### version : 3.5.1 93*da0073e9SAndroid Build Coastguard Worker### build string: py36h0a44026_0 94*da0073e9SAndroid Build Coastguard Worker### build number: 0 95*da0073e9SAndroid Build Coastguard Worker### channel : https://repo.continuum.io/pkgs/main/osx-64 96*da0073e9SAndroid Build Coastguard Worker### size : 589 KB 97*da0073e9SAndroid Build Coastguard Worker### arch : None 98*da0073e9SAndroid Build Coastguard Worker### constrains : () 99*da0073e9SAndroid Build Coastguard Worker### license : New BSD License 100*da0073e9SAndroid Build Coastguard Worker### license_family: BSD 101*da0073e9SAndroid Build Coastguard Worker### md5 : 7dbdb06612e21c42fbb8a62354e13e10 102*da0073e9SAndroid Build Coastguard Worker### platform : None 103*da0073e9SAndroid Build Coastguard Worker### subdir : osx-64 104*da0073e9SAndroid Build Coastguard Worker### timestamp : 1519951502766 105*da0073e9SAndroid Build Coastguard Worker### url : https://repo.continuum.io/pkgs/main/osx-64/protobuf-3.5.1-py36h0a44026_0.tar.bz2 106*da0073e9SAndroid Build Coastguard Worker### dependencies: 107*da0073e9SAndroid Build Coastguard Worker### libcxx >=4.0.1 108*da0073e9SAndroid Build Coastguard Worker### libprotobuf >=3.5.1,<3.6.0a0 109*da0073e9SAndroid Build Coastguard Worker### python >=3.6,<3.7.0a0 110*da0073e9SAndroid Build Coastguard Worker### six 111*da0073e9SAndroid Build Coastguard Worker 112*da0073e9SAndroid Build Coastguard Worker# Echo what packages we'll look through. 113*da0073e9SAndroid Build Coastguard Workerecho "Processing these packages:" 114*da0073e9SAndroid Build Coastguard Workerfor pkg in "${conda_search_packages[@]:2}"; do 115*da0073e9SAndroid Build Coastguard Worker echo " $pkg" 116*da0073e9SAndroid Build Coastguard Workerdone 117*da0073e9SAndroid Build Coastguard Worker 118*da0073e9SAndroid Build Coastguard Worker 119*da0073e9SAndroid Build Coastguard Worker 120*da0073e9SAndroid Build Coastguard Worker# 121*da0073e9SAndroid Build Coastguard Worker# Look up each package in conda info, then install it and search the exported 122*da0073e9SAndroid Build Coastguard Worker# symbols for signs of cxx11 123*da0073e9SAndroid Build Coastguard Worker# 124*da0073e9SAndroid Build Coastguard Workerfor pkg in "${conda_search_packages[@]:2}"; do 125*da0073e9SAndroid Build Coastguard Worker echo "Processing $pkg" >> $VERBOSE_LOG 126*da0073e9SAndroid Build Coastguard Worker 127*da0073e9SAndroid Build Coastguard Worker # Split each line into an array and build the package specification 128*da0073e9SAndroid Build Coastguard Worker # <package_name (1st line only)> maj.min.patch build_string channel_name 129*da0073e9SAndroid Build Coastguard Worker line_parts=( $pkg ) 130*da0073e9SAndroid Build Coastguard Worker if [[ ${line_parts[0]} == $PKG_NAME ]]; then 131*da0073e9SAndroid Build Coastguard Worker # First line of output 132*da0073e9SAndroid Build Coastguard Worker PKG_VERSION="${line_parts[1]}" 133*da0073e9SAndroid Build Coastguard Worker PKG_BUILD_STR="${line_parts[2]}" 134*da0073e9SAndroid Build Coastguard Worker else 135*da0073e9SAndroid Build Coastguard Worker PKG_VERSION="${line_parts[0]}" 136*da0073e9SAndroid Build Coastguard Worker PKG_BUILD_STR="${line_parts[1]}" 137*da0073e9SAndroid Build Coastguard Worker fi 138*da0073e9SAndroid Build Coastguard Worker PKG_SPEC="$PKG_NAME=$PKG_VERSION=$PKG_BUILD_STR" 139*da0073e9SAndroid Build Coastguard Worker 140*da0073e9SAndroid Build Coastguard Worker # Output current pkg spec 141*da0073e9SAndroid Build Coastguard Worker echo 142*da0073e9SAndroid Build Coastguard Worker echo "${PKG_SPEC}:" 143*da0073e9SAndroid Build Coastguard Worker echo "Determined that the package spec is $PKG_SPEC" >> $VERBOSE_LOG 144*da0073e9SAndroid Build Coastguard Worker 145*da0073e9SAndroid Build Coastguard Worker # Split the output of conda_info into an array of lines 146*da0073e9SAndroid Build Coastguard Worker pkg_dependencies=() 147*da0073e9SAndroid Build Coastguard Worker while read -r line; do pkg_dependencies+=("$line"); done <<< "$(conda info "$PKG_SPEC" $CONDA_CHANNEL)" 148*da0073e9SAndroid Build Coastguard Worker 149*da0073e9SAndroid Build Coastguard Worker # List all the listed dependencies in `conda info` 150*da0073e9SAndroid Build Coastguard Worker if [ "${#pkg_dependencies[@]}" -gt 19 ]; then 151*da0073e9SAndroid Build Coastguard Worker echo " Listed dependencies:" 152*da0073e9SAndroid Build Coastguard Worker echo " Listed dependencies:" >> $VERBOSE_LOG 153*da0073e9SAndroid Build Coastguard Worker for pkg_dependency in "${pkg_dependencies[@]:20}"; do 154*da0073e9SAndroid Build Coastguard Worker echo " $pkg_dependency" 155*da0073e9SAndroid Build Coastguard Worker echo " $pkg_dependency" >> $VERBOSE_LOG 156*da0073e9SAndroid Build Coastguard Worker done 157*da0073e9SAndroid Build Coastguard Worker else 158*da0073e9SAndroid Build Coastguard Worker echo " No listed dependencies in conda-info" >> $VERBOSE_LOG 159*da0073e9SAndroid Build Coastguard Worker fi 160*da0073e9SAndroid Build Coastguard Worker 161*da0073e9SAndroid Build Coastguard Worker # But sometimes (a lot of the time) the gcc with which a package was built 162*da0073e9SAndroid Build Coastguard Worker # against is not listed in dependencies. So we try to figure it out manually 163*da0073e9SAndroid Build Coastguard Worker # We install this exact package, and then grep the exported symbols for signs 164*da0073e9SAndroid Build Coastguard Worker # of cxx11 165*da0073e9SAndroid Build Coastguard Worker echo "Calling conda-uninstall on $PKG_NAME" >> $VERBOSE_LOG 166*da0073e9SAndroid Build Coastguard Worker echo "conda uninstall -y $PKG_NAME --quiet" >> $VERBOSE_LOG 167*da0073e9SAndroid Build Coastguard Worker conda uninstall -y "$PKG_NAME" --quiet >> $VERBOSE_LOG 2>&1 168*da0073e9SAndroid Build Coastguard Worker 169*da0073e9SAndroid Build Coastguard Worker echo "Calling conda-install on $PKG_SPEC" >> $VERBOSE_LOG 170*da0073e9SAndroid Build Coastguard Worker echo "conda install -y $PKG_SPEC --quiet --no-deps $CONDA_CHANNEL" >> $VERBOSE_LOG 171*da0073e9SAndroid Build Coastguard Worker conda install -y "$PKG_SPEC" --quiet --no-deps $CONDA_CHANNEL >> $VERBOSE_LOG 2>&1 172*da0073e9SAndroid Build Coastguard Worker if [ $? -eq 0 ]; then 173*da0073e9SAndroid Build Coastguard Worker # Only grep the exported symbols if the library was installed correctly 174*da0073e9SAndroid Build Coastguard Worker 175*da0073e9SAndroid Build Coastguard Worker MENTIONS_CXX11="$(nm "$CONDA_ROOT/lib/$PKG_INSTALLED_LIB" | grep cxx11 | wc -l)" 176*da0073e9SAndroid Build Coastguard Worker if [ $MENTIONS_CXX11 -gt 0 ]; then 177*da0073e9SAndroid Build Coastguard Worker echo " This package is built against the recent gcc ABI ($MENTIONS_CXX11 mentions of cxx11)" 178*da0073e9SAndroid Build Coastguard Worker echo "$CONDA_ROOT/lib/$PKG_INSTALLED_LIB mentions cxx11 $MENTIONS_CXX11 times" >> $VERBOSE_LOG 179*da0073e9SAndroid Build Coastguard Worker fi 180*da0073e9SAndroid Build Coastguard Worker else 181*da0073e9SAndroid Build Coastguard Worker echo "Error installing $PKG_SPEC , continuing" 182*da0073e9SAndroid Build Coastguard Worker echo "Error installing $PKG_SPEC , continuing" >> $VERBOSE_LOG 183*da0073e9SAndroid Build Coastguard Worker fi 184*da0073e9SAndroid Build Coastguard Workerdone 185