Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support toolchain syntax added in go 1.21 #1304

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- golang: Updates go.mod parser to be compatible with golang v1.21. ([#1304](https://github.com/fossas/fossa-cli/pull/1304))
- `fossa list-targets`: list-target command supports `--format` option with: `ndjson`, `text`, and `legacy`. ([#1296](https://github.com/fossas/fossa-cli/pull/1296))

## v3.8.17
Expand Down
10 changes: 10 additions & 0 deletions src/Strategy/Go/Gomod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ data Statement
-- of go.mod, refer to: https://go.dev/ref/mod#go-mod-file-retract
RetractStatement
| GoVersionStatement Text
| -- | we do not care about values associated with
-- the toolchain block as they are of no use to us today.
-- Refer to: https://go.dev/doc/modules/gomod-ref#toolchain
ToolchainStatement Text
deriving (Eq, Ord, Show)

type PackageName = Text
Expand Down Expand Up @@ -218,6 +222,7 @@ gomodParser = do
where
statement =
(singleton <$> goVersionStatement) -- singleton wraps the Parser Statement into a Parser [Statement]
<|> (singleton <$> toolChainStatements)
<|> requireStatements
<|> replaceStatements
<|> excludeStatements
Expand All @@ -228,6 +233,11 @@ gomodParser = do
goVersionStatement :: Parser Statement
goVersionStatement = GoVersionStatement <$ lexeme (chunk "go") <*> goVersion

-- top-level go version statement
-- e.g., toolchain go1.21.1
toolChainStatements :: Parser Statement
toolChainStatements = ToolchainStatement <$ lexeme (chunk "toolchain") <*> anyToken

-- top-level require statements
-- e.g.:
-- require golang.org/x/text v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions test/Go/testdata/go.mod.edgecases
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module test/package

go 1.12

toolchain go1.21.1

require repo/name/A v1.0.0 // indirect

require (
Expand Down
Loading