Skip to content

Commit c1dd25e

Browse files
committed
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 <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Robert Findley <rfindley@google.com>
1 parent 83d7619 commit c1dd25e

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

gopls/internal/migrate.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2022 The Go Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style
5+
# license that can be found in the LICENSE file.
6+
#
7+
# Migrates the internal/lsp directory to gopls/internal/lsp. Run this script
8+
# from the root of x/tools to migrate in-progress CLs.
9+
#
10+
# See golang/go#54509 for more details. This script may be deleted once a
11+
# reasonable amount of time has passed such that all active in-progress CLs
12+
# have been rebased.
13+
14+
set -eu
15+
16+
# A portable -i flag. Darwin requires two parameters.
17+
# See https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
18+
# for more details.
19+
sedi=(-i)
20+
case "$(uname)" in
21+
Darwin*) sedi=(-i "")
22+
esac
23+
24+
# mvpath moves the directory at the relative path $1 to the relative path $2,
25+
# moving files and rewriting import paths.
26+
#
27+
# It uses heuristics to identify import path literals, and therefore may be
28+
# imprecise.
29+
function mvpath() {
30+
# If the source also doesn't exist, it may have already been moved.
31+
# Skip so that this script is idempotent.
32+
if [[ ! -d $1 ]]; then
33+
echo "WARNING: skipping nonexistent source directory $1"
34+
return 0
35+
fi
36+
37+
# git can sometimes leave behind empty directories, which can change the
38+
# behavior of the mv command below.
39+
if [[ -d $2 ]] || [[ -f $2 ]]; then
40+
echo "ERROR: destination $2 already exists"
41+
exit 1
42+
fi
43+
44+
mv $1 $2
45+
46+
local old="golang.org/x/tools/$1"
47+
local new="golang.org/x/tools/$2"
48+
49+
# Replace instances of the old import path with the new. This is imprecise,
50+
# but we are a bit careful to avoid replacing golang.org/x/tools/foox with
51+
# golang.org/x/tools/barx when moving foo->bar: the occurrence of the import
52+
# path must be followed by whitespace, /, or a closing " or `.
53+
local replace="s:${old}\([[:space:]/\"\`]\):${new}\1:g"
54+
find . -type f \( \
55+
-name ".git" -prune -o \
56+
-name "*.go" -o \
57+
-name "*.in" -o \
58+
-name "*.golden" -o \
59+
-name "*.hlp" -o \
60+
-name "*.md" \) \
61+
-exec sed "${sedi[@]}" -e $replace {} \;
62+
}
63+
64+
mvpath internal/lsp/diff internal/diff
65+
mvpath internal/lsp/fuzzy internal/fuzzy
66+
mvpath internal/lsp/debug/tag internal/event/tag
67+
mvpath internal/lsp/bug internal/bug
68+
mvpath internal/lsp gopls/internal/lsp

0 commit comments

Comments
 (0)