cuelang.org/go@v0.10.1/internal/golangorgx/revendorToolsInternal.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -eu
     4  shopt -s extglob
     5  
     6  # revendorInternal.sh is a script for "vendoring" (internal) parts of the
     7  # golang.org/x repos for use locally. It currently fixes on versions of
     8  # x/tools, x/tools/gopls and x/telemetry. It takes a list of target packages,
     9  # vendors their transitive dependencies, then copies the resulting set of
    10  # packages under a local directory. Import paths are adjusted to the new
    11  # location, go:generate directives are stripped out, *_test.go and testdata
    12  # directories are removed.
    13  #
    14  # Whilst this script could be adapted to be run regularly, it's most likely useful
    15  # as a one-shot wrapper (which sort of suggests the module versions, package listsj)
    16  
    17  # Save location of root of repo and change there to start
    18  SCRIPT_DIR="$( command cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"/
    19  cd $SCRIPT_DIR
    20  
    21  # golang.org/x/tools(/gopls) version
    22  toolsVersion=v0.17.1-0.20240207023750-c11269ccb0bf
    23  goplsVersion=v0.0.0-20240207023750-c11269ccb0bf
    24  telemetryVersion=v0.0.0-20240201224847-0a1d30dda509
    25  
    26  # Establish a temporary module to collect and vendor
    27  # our internal requirements
    28  td=$(mktemp -d)
    29  trap "rm -rf $td" EXIT
    30  cd $td
    31  cp $SCRIPT_DIR/vendoring/* .
    32  go mod vendor
    33  
    34  tools_regex='s+golang.org/x/tools/internal+cuelang.org/go/internal/golangorgx/tools+g'
    35  gopls_regex='s+golang.org/x/tools/gopls/internal+cuelang.org/go/internal/golangorgx/gopls+g'
    36  telemetry_regex='s+golang.org/x/telemetry+cuelang.org/go/internal/golangorgx/telemetry+g'
    37  
    38  # Adjust imports
    39  find ./ -name "*.go" -exec sed -i $tools_regex {} +
    40  find ./ -name "*.go" -exec sed -i $gopls_regex {} +
    41  find ./ -name "*.go" -exec sed -i $telemetry_regex {} +
    42  
    43  # Strip go:generate directives
    44  find ./ -name "*.go" -exec sed -i '/^\/\/go:generate/d' {} +
    45  
    46  # Remove frontend json files
    47  find ./ -name "*.json" -exec rm {} +
    48  
    49  cd $SCRIPT_DIR
    50  
    51  # Force-sync to original
    52  rsync -a --delete --chmod=D0755,F0644 $td/vendor/golang.org/x/tools/internal/ ./tools
    53  rsync -a --delete --chmod=D0755,F0644 $td/vendor/golang.org/x/tools/gopls/internal/ ./gopls
    54  rsync -a --delete --chmod=D0755,F0644 $td/vendor/golang.org/x/telemetry/ ./telemetry
    55  
    56  # Cleanup; ensure all copied files are well formatted, and our module is tidy.
    57  go mod tidy
    58  gofmt -w .