From c1dd25e80b559a5b0e8e2dd7d5bd1e946aa996a0 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Tue, 30 Aug 2022 14:09:52 -0400 Subject: [PATCH] gopls/internal/migrate.sh: a script to migrate internal/lsp to gopls/ Add a script that does the migration of the internal/lsp directory to gopls/internal/lsp. This is done in a separate CL so that in-progress CLs can rebase on top of *this CL*, run this script, and then rebase to tip. For golang/go#54509 Change-Id: I6f529c1e4ba29b4d88dc26278d54a055f1ef212e Reviewed-on: https://go-review.googlesource.com/c/tools/+/426795 gopls-CI: kokoro TryBot-Result: Gopher Robot Reviewed-by: Alan Donovan Run-TryBot: Robert Findley --- gopls/internal/migrate.sh | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 gopls/internal/migrate.sh diff --git a/gopls/internal/migrate.sh b/gopls/internal/migrate.sh new file mode 100755 index 00000000000..6f2bebc6ad6 --- /dev/null +++ b/gopls/internal/migrate.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# +# Copyright 2022 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. +# +# Migrates the internal/lsp directory to gopls/internal/lsp. Run this script +# from the root of x/tools to migrate in-progress CLs. +# +# See golang/go#54509 for more details. This script may be deleted once a +# reasonable amount of time has passed such that all active in-progress CLs +# have been rebased. + +set -eu + +# A portable -i flag. Darwin requires two parameters. +# See https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux +# for more details. +sedi=(-i) +case "$(uname)" in + Darwin*) sedi=(-i "") +esac + +# mvpath moves the directory at the relative path $1 to the relative path $2, +# moving files and rewriting import paths. +# +# It uses heuristics to identify import path literals, and therefore may be +# imprecise. +function mvpath() { + # If the source also doesn't exist, it may have already been moved. + # Skip so that this script is idempotent. + if [[ ! -d $1 ]]; then + echo "WARNING: skipping nonexistent source directory $1" + return 0 + fi + + # git can sometimes leave behind empty directories, which can change the + # behavior of the mv command below. + if [[ -d $2 ]] || [[ -f $2 ]]; then + echo "ERROR: destination $2 already exists" + exit 1 + fi + + mv $1 $2 + + local old="golang.org/x/tools/$1" + local new="golang.org/x/tools/$2" + + # Replace instances of the old import path with the new. This is imprecise, + # but we are a bit careful to avoid replacing golang.org/x/tools/foox with + # golang.org/x/tools/barx when moving foo->bar: the occurrence of the import + # path must be followed by whitespace, /, or a closing " or `. + local replace="s:${old}\([[:space:]/\"\`]\):${new}\1:g" + find . -type f \( \ + -name ".git" -prune -o \ + -name "*.go" -o \ + -name "*.in" -o \ + -name "*.golden" -o \ + -name "*.hlp" -o \ + -name "*.md" \) \ + -exec sed "${sedi[@]}" -e $replace {} \; +} + +mvpath internal/lsp/diff internal/diff +mvpath internal/lsp/fuzzy internal/fuzzy +mvpath internal/lsp/debug/tag internal/event/tag +mvpath internal/lsp/bug internal/bug +mvpath internal/lsp gopls/internal/lsp