text_2025-12-19_17-31-26.txt

#!/bin/bash
DEPS_FILE="SkyAgentProvider.deps.json"

if [ ! -f "$DEPS_FILE" ]; then
    echo "Error: $DEPS_FILE not found!"
    exit 1
fi

# Parsing logic updated to handle 'runtimes' folder correctly
awk -F'"' '
    # 1. Detect start of a package block (e.g., "Grpc.Core/2.37.0": {)
    $2 ~ /^[a-zA-Z0-9\.]+\/[0-9\.]+.*$/ {
        pkg_id = $2
        lower_pkg_id = tolower(pkg_id)
        base_dir = lower_pkg_id
    }

    # 2. Detect file lines (matches dll, so, dylib, pdb, xml)
    # This regex catches lines like "runtimes/linux-x64/native/libgrpc_csharp_ext.x64.so": {
    base_dir && $2 ~ /\.(dll|so|dylib|pdb|xml)$/ {
        rel_path = $2
        
        # Calculate just the filename for fallback check
        n = split(rel_path, parts, "/")
        filename = parts[n]

        # Destination directory (e.g., grpc.core/2.37.0/runtimes/linux-x64/native/)
        dest_dir = base_dir "/" substr(rel_path, 1, length(rel_path) - length(filename))
        dest_path = base_dir "/" rel_path

        # GENERATE SHELL COMMAND:
        # 1. Create the deep destination directory
        # 2. Check if file exists at strict relative path (e.g., inside "runtimes/") AND move it
        # 3. OR check if file exists in root (flattened) AND move it
        
        print "mkdir -p " dest_dir " && if [ -f \"" rel_path "\" ]; then mv \"" rel_path "\" \"" dest_path "\"; elif [ -f \"" filename "\" ]; then mv \"" filename "\" \"" dest_path "\"; fi"
    }
' "$DEPS_FILE" | sh

# Clean up empty directories (this removes the now-empty "runtimes" folder from root)
find . -type d -empty -delete
Back to List