Skip to content

Commit

Permalink
Support toolchain syntax added in go 1.21 (#1304)
Browse files Browse the repository at this point in the history
* support toolchains

* test go.mod

* Changelog
  • Loading branch information
zlav authored Oct 18, 2023
1 parent f959abe commit a11e107
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
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

0 comments on commit a11e107

Please sign in to comment.