Skip to content

Commit

Permalink
contrib: Add Go multimod workspace setup script.
Browse files Browse the repository at this point in the history
This adds a script to the contrib directory that initializes a Go
multi-module workspace and adds all of the modules provided by the dcrd
repository to it on an as needed basis.  Note that workspaces require Go
1.18+.

This is useful when developing across multiple modules in the repository
and allows development environments that make use of the Go language
server (aka gopls), such as VSCode, to provide full support without also
needing to temporarily create replacements in the various go.mod files
or individually add every module.

Do note, however, that workspaces are local, so final submissions to the
repository will still require the appropriate changes to the relevant
go.mod files to ensure resolution outside of the workspace.

Finally, it also updates the README.md in the contrib directory
accordingly.
  • Loading branch information
davecgh committed Mar 29, 2022
1 parent 84058da commit 47c1d48
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,20 @@ The project does not officially provide container images. However, all of the
necessary files to build your own lightweight non-root container image based on
`scratch` from the latest source code are available in the docker directory.
See [docker/README.md](./docker/README.md) for more details.

### Go Multi-Module Workspace Setup Script

The [dcr_setup_go_workspace.sh](./dcr_setup_go_workspace.sh) script initializes
a Go multi-module workspace (via `go work init`) and adds all of the modules
provided by the dcrd repository to it (via `go work use`) on an as needed basis.
Note that workspaces require Go 1.18+.

This is useful when developing across multiple modules in the repository and
allows development environments that make use of the Go language server (aka
`gopls`), such as VSCode, to provide full support without also needing to
temporarily create replacements in the various `go.mod` files or individually
add every module.

Do note, however, that workspaces are local, so final submissions to the
repository will still require the appropriate changes to the relevant `go.mod`
files to ensure resolution outside of the workspace.
40 changes: 40 additions & 0 deletions contrib/dcr_setup_go_workspace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 The Decred developers
# Use of this source code is governed by an ISC
# license that can be found in the LICENSE file.
#
# Script to initialize a multi-module workspace that includes all of the modules
# provided by the dcrd repository.

set -e

# Ensure the script is run from either the root of the repo or the contrib dir
SCRIPT=$(basename $0)
MAIN_CODE_FILE="dcrd.go"
if [ -f "../${MAIN_CODE_FILE}" ]; then
cd ..
fi
if [ ! -f "${MAIN_CODE_FILE}" ]; then
echo "$SCRIPT: error: ${MAIN_CODE_FILE} not found in the current directory"
exit 1
fi

# Verify Go is available
if ! type go >/dev/null 2>&1; then
echo -n "$SCRIPT: error: Unable to find 'go' in the system path."
exit 1
fi

# Create workspace unless one already exists
if [ ! -f "go.work" ]; then
go work init
fi

# Add all of the modules as needed
go work use . ./addrmgr ./bech32 ./blockchain ./blockchain/stake
go work use ./blockchain/standalone ./certgen ./chaincfg ./chaincfg/chainhash
go work use ./connmgr ./container/apbf ./crypto/blake256 ./crypto/ripemd160
go work use ./database ./dcrec ./dcrec/edwards ./dcrec/secp256k1 ./dcrjson
go work use ./dcrutil ./gcs ./hdkeychain ./lru ./math/uint256 ./peer
go work use ./rpc/jsonrpc/types ./rpcclient ./txscript ./wire

0 comments on commit 47c1d48

Please sign in to comment.