|
| 1 | +#!/bin/bash |
1 | 2 | # |
2 | 3 | # Licensed to the Apache Software Foundation (ASF) under one or more |
3 | 4 | # contributor license agreements. See the NOTICE file distributed with |
|
16 | 17 | # Initialize the configuration files of inlong components |
17 | 18 | # |
18 | 19 |
|
19 | | -#!/bin/bash |
20 | | - |
21 | 20 | set -e |
22 | 21 |
|
| 22 | +# Parse command line arguments |
| 23 | +TARGET_DIR="" |
| 24 | +if [ $# -eq 1 ]; then |
| 25 | + TARGET_DIR="$1" |
| 26 | + echo "Using user-specified target directory: $TARGET_DIR" |
| 27 | + # Check if the target directory exists early to avoid wasting compilation time |
| 28 | + if [ ! -d "$TARGET_DIR" ]; then |
| 29 | + echo "Error: Target directory '$TARGET_DIR' does not exist!" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | +elif [ $# -gt 1 ]; then |
| 33 | + echo "Usage: $0 [target_directory]" |
| 34 | + echo " target_directory: Optional. Directory to install .so files. If not provided, will use system site-packages directories." |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
23 | 38 | BASE_DIR=$(dirname "$0") |
24 | 39 | PY_SDK_DIR=$(cd "$BASE_DIR"; pwd) |
25 | 40 |
|
@@ -73,8 +88,8 @@ if [ ! -d "$PY_SDK_DIR/pybind11/build" ]; then |
73 | 88 | trap 'echo "Error occurred during pybind11 build. Deleting pybind11 folder..."; cd $PY_SDK_DIR; rm -r pybind11; exit 1' ERR |
74 | 89 |
|
75 | 90 | cmake "$PY_SDK_DIR/pybind11" |
76 | | - cmake --build "$PY_SDK_DIR/pybind11/build" --config Release --target check |
77 | | - make -j 4 |
| 91 | + cmake --build "$PY_SDK_DIR/pybind11/build" --config Release |
| 92 | + make -j"$(nproc)" |
78 | 93 |
|
79 | 94 | # Remove the trap command if the build is successful |
80 | 95 | trap - ERR |
@@ -105,37 +120,31 @@ if [ -d "$PY_SDK_DIR/build" ]; then |
105 | 120 | fi |
106 | 121 | mkdir "$PY_SDK_DIR/build" && cd "$PY_SDK_DIR/build" |
107 | 122 | cmake "$PY_SDK_DIR" |
108 | | -make -j 4 |
109 | | - |
110 | | -# Get all existing Python site-packages directories |
111 | | -SITE_PACKAGES_DIRS=($(python -c "import site,os; print(' '.join([p for p in site.getsitepackages() if os.path.isdir(p)]))")) |
112 | | - |
113 | | -# Check if the SITE_PACKAGES_DIRS array is not empty |
114 | | -if [ ${#SITE_PACKAGES_DIRS[@]} -ne 0 ]; then |
115 | | - # If not empty, display all found site-packages directories to the user |
116 | | - echo "Your system's existing Python site-packages directories are:" |
117 | | - for dir in "${SITE_PACKAGES_DIRS[@]}"; do |
118 | | - echo " $dir" |
119 | | - done |
120 | | -else |
121 | | - # If empty, warn the user and prompt them to enter the target directory in the next step |
122 | | - echo "Warn: No existing site-packages directories found, please enter the target directory for the .so files in the following step!" |
123 | | -fi |
| 123 | +make -j"$(nproc)" |
124 | 124 |
|
125 | | -# Prompt user for the target directory for .so files |
126 | | -read -r -p "Enter the target directory for the .so files (Press Enter to use all above site-packages directories): " target_dir |
127 | | - |
128 | | -# If user input is empty, use all found site-packages directories |
129 | | -if [ -z "$target_dir" ]; then |
130 | | - for dir in "${SITE_PACKAGES_DIRS[@]}"; do |
131 | | - echo "Copying .so files to $dir" |
132 | | - # Find all .so files in $PY_SDK_DIR/build and copy them to the current site-packages directory |
133 | | - find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp {} "$dir" |
134 | | - done |
| 125 | +# Handle installation based on command line arguments |
| 126 | +if [ -n "$TARGET_DIR" ]; then |
| 127 | + # User specified a target directory via command line argument |
| 128 | + echo "Copying .so files to user-specified directory: $TARGET_DIR" |
| 129 | + find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp {} "$TARGET_DIR" |
135 | 130 | else |
136 | | - # If user specified a directory, copy .so files there |
137 | | - echo "Copying .so files to $target_dir" |
138 | | - find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp {} "$target_dir" |
| 131 | + # No command line argument provided, use system site-packages directories |
| 132 | + # Get all existing Python site-packages directories |
| 133 | + SITE_PACKAGES_DIRS=($(python -c "import site,os; print(' '.join([p for p in site.getsitepackages() if os.path.isdir(p)]))")) |
| 134 | + if [ ${#SITE_PACKAGES_DIRS[@]} -ne 0 ]; then |
| 135 | + echo "No target directory specified, using system site-packages directories:" |
| 136 | + for dir in "${SITE_PACKAGES_DIRS[@]}"; do |
| 137 | + echo " $dir" |
| 138 | + done |
| 139 | + for dir in "${SITE_PACKAGES_DIRS[@]}"; do |
| 140 | + echo "Copying .so files to $dir" |
| 141 | + # Find all .so files in $PY_SDK_DIR/build and copy them to the current site-packages directory |
| 142 | + find "$PY_SDK_DIR/build" -name "*.so" -print0 | xargs -0 -I {} cp {} "$dir" |
| 143 | + done |
| 144 | + else |
| 145 | + echo "Error: No system site-packages directories found and no target directory specified!" |
| 146 | + echo "The .so file is located in $PY_SDK_DIR/build, you can copy it manually to your project" |
| 147 | + fi |
139 | 148 | fi |
140 | 149 |
|
141 | 150 | # Clean the cpp dataproxy directory |
|
0 commit comments