|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # |
3 | 3 | # Copyright (c) nexB Inc. and others. All rights reserved. |
4 | | -# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# SPDX-License-Identifier: Apache-2.0 AND MIT |
5 | 5 | # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. |
| 6 | +# ScanCode is a trademark of nexB Inc. |
6 | 7 | # See https://github.com/nexB/ for support or download. |
7 | 8 | # See https://aboutcode.org for more information about nexB OSS projects. |
8 | 9 | # |
9 | 10 |
|
10 | 11 | set -e |
11 | 12 | #set -x |
12 | 13 |
|
| 14 | +################################################################################### |
| 15 | +################################################################################### |
| 16 | +# from https://raw.githubusercontent.com/mkropat/sh-realpath/58c03982cfd8accbcf0c4426a4adf0f120a8b2bb/realpath.sh |
| 17 | +# realpath emulation for portability on *nix |
| 18 | +# this allow running scancode from arbitrary locations and from symlinks |
| 19 | +# |
| 20 | +# Copyright (c) 2014 Michael Kropat |
| 21 | +# |
| 22 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 23 | +# of this software and associated documentation files (the "Software"), to deal |
| 24 | +# in the Software without restriction, including without limitation the rights |
| 25 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 26 | +# copies of the Software, and to permit persons to whom the Software is |
| 27 | +# furnished to do so, subject to the following conditions: |
| 28 | +# |
| 29 | +# The above copyright notice and this permission notice shall be included in |
| 30 | +# all copies or substantial portions of the Software. |
| 31 | +# |
| 32 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 33 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 34 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 35 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 36 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 37 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 38 | +# THE SOFTWARE. |
| 39 | + |
| 40 | + |
| 41 | +realpath() { |
| 42 | + canonicalize_path "$(resolve_symlinks "$1")" |
| 43 | +} |
| 44 | + |
| 45 | +resolve_symlinks() { |
| 46 | + _resolve_symlinks "$1" |
| 47 | +} |
| 48 | + |
| 49 | +_resolve_symlinks() { |
| 50 | + _assert_no_path_cycles "$@" || return |
| 51 | + |
| 52 | + local dir_context path |
| 53 | + path=$(readlink -- "$1") |
| 54 | + if [ $? -eq 0 ]; then |
| 55 | + dir_context=$(dirname -- "$1") |
| 56 | + _resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@" |
| 57 | + else |
| 58 | + printf '%s\n' "$1" |
| 59 | + fi |
| 60 | +} |
| 61 | + |
| 62 | +_prepend_dir_context_if_necessary() { |
| 63 | + if [ "$1" = . ]; then |
| 64 | + printf '%s\n' "$2" |
| 65 | + else |
| 66 | + _prepend_path_if_relative "$1" "$2" |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | +_prepend_path_if_relative() { |
| 71 | + case "$2" in |
| 72 | + /* ) printf '%s\n' "$2" ;; |
| 73 | + * ) printf '%s\n' "$1/$2" ;; |
| 74 | + esac |
| 75 | +} |
| 76 | + |
| 77 | +_assert_no_path_cycles() { |
| 78 | + local target path |
| 79 | + |
| 80 | + target=$1 |
| 81 | + shift |
| 82 | + |
| 83 | + for path in "$@"; do |
| 84 | + if [ "$path" = "$target" ]; then |
| 85 | + return 1 |
| 86 | + fi |
| 87 | + done |
| 88 | +} |
| 89 | + |
| 90 | +canonicalize_path() { |
| 91 | + if [ -d "$1" ]; then |
| 92 | + _canonicalize_dir_path "$1" |
| 93 | + else |
| 94 | + _canonicalize_file_path "$1" |
| 95 | + fi |
| 96 | +} |
| 97 | + |
| 98 | +_canonicalize_dir_path() { |
| 99 | + (cd "$1" 2>/dev/null && pwd -P) |
| 100 | +} |
| 101 | + |
| 102 | +_canonicalize_file_path() { |
| 103 | + local dir file |
| 104 | + dir=$(dirname -- "$1") |
| 105 | + file=$(basename -- "$1") |
| 106 | + (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file") |
| 107 | +} |
| 108 | + |
| 109 | +################################################################################### |
| 110 | +################################################################################### |
| 111 | + |
| 112 | +# Now run configure proper |
| 113 | + |
| 114 | +################################ |
| 115 | +# Setup current directory where this script lives |
| 116 | +CFG_BIN="$( realpath "${BASH_SOURCE[0]}" )" |
| 117 | +CFG_ROOT_DIR="$( cd "$( dirname "${CFG_BIN}" )" && pwd )" |
| 118 | + |
| 119 | +CFG_BIN_DIR=$CFG_ROOT_DIR/$VIRTUALENV_DIR/bin |
| 120 | + |
| 121 | +# force relaunching under X86-64 architecture on macOS M1/ARM |
| 122 | +if [[ $OSTYPE == 'darwin'* && $(uname -m) == 'arm64' ]]; then |
| 123 | + arch -x86_64 /bin/bash -c "$CFG_ROOT_DIR/configure $@" |
| 124 | + exit $? |
| 125 | +fi |
| 126 | + |
13 | 127 | ################################ |
14 | 128 | # A configuration script to set things up: |
15 | 129 | # create a virtualenv and install or update thirdparty packages. |
@@ -52,14 +166,21 @@ CFG_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
52 | 166 | CFG_BIN_DIR=$CFG_ROOT_DIR/$VIRTUALENV_DIR/bin |
53 | 167 |
|
54 | 168 |
|
| 169 | +################################ |
| 170 | +# Install with or without and index. With "--no-index" this is using only local wheels |
| 171 | +# This is an offline mode with no index and no network operations |
| 172 | +NO_INDEX="--no-index " |
| 173 | + |
| 174 | + |
55 | 175 | ################################ |
56 | 176 | # Thirdparty package locations and index handling |
57 | | -# Find packages from the local thirdparty directory or from thirdparty.aboutcode.org |
58 | | -# offline mode for scancode installation with no index at all |
59 | | -if [ -d "$CFG_ROOT_DIR/thirdparty" ]; then |
60 | | - PIP_EXTRA_ARGS="--no-index --find-links $CFG_ROOT_DIR/thirdparty" |
| 177 | +# Find packages from the local thirdparty directory if present |
| 178 | +thirddir=$CFG_ROOT_DIR/thirdparty |
| 179 | +if [[ "$(echo $thirddir/*.whl)x" != "$thirddir/*.whlx" ]]; then |
| 180 | + PIP_EXTRA_ARGS="$NO_INDEX --find-links $CFG_ROOT_DIR/thirdparty" |
61 | 181 | fi |
62 | 182 |
|
| 183 | + |
63 | 184 | ################################ |
64 | 185 | # Set the quiet flag to empty if not defined |
65 | 186 | if [[ "$CFG_QUIET" == "" ]]; then |
@@ -102,25 +223,13 @@ create_virtualenv() { |
102 | 223 | wget -O "$VIRTUALENV_PYZ" "$VIRTUALENV_PYZ_URL" 2>/dev/null || curl -o "$VIRTUALENV_PYZ" "$VIRTUALENV_PYZ_URL" |
103 | 224 | fi |
104 | 225 |
|
105 | | - if [[ $OSTYPE == 'darwin'* && $(uname -m) == 'arm64' ]]; then |
106 | | - arch -x86_64 /bin/bash -c "$PYTHON_EXECUTABLE \"$VIRTUALENV_PYZ\" \ |
107 | | - --wheel embed --pip embed --setuptools embed \ |
108 | | - --seeder pip \ |
109 | | - --never-download \ |
110 | | - --no-periodic-update \ |
111 | | - --no-vcs-ignore \ |
112 | | - $CFG_QUIET \ |
113 | | - \"$CFG_ROOT_DIR/$VENV_DIR\" " |
114 | | - else |
115 | | - $PYTHON_EXECUTABLE "$VIRTUALENV_PYZ" \ |
116 | | - --wheel embed --pip embed --setuptools embed \ |
117 | | - --seeder pip \ |
118 | | - --never-download \ |
119 | | - --no-periodic-update \ |
120 | | - --no-vcs-ignore \ |
121 | | - $CFG_QUIET \ |
122 | | - "$CFG_ROOT_DIR/$VENV_DIR" |
123 | | - fi |
| 226 | + $PYTHON_EXECUTABLE "$VIRTUALENV_PYZ" \ |
| 227 | + --wheel embed --pip embed --setuptools embed \ |
| 228 | + --never-download \ |
| 229 | + --no-periodic-update \ |
| 230 | + --no-vcs-ignore \ |
| 231 | + $CFG_QUIET \ |
| 232 | + "$CFG_ROOT_DIR/$VENV_DIR" |
124 | 233 | fi |
125 | 234 | } |
126 | 235 |
|
|
0 commit comments