Skip to content

Commit

Permalink
Expose a static only Go modules tactic.
Browse files Browse the repository at this point in the history
  • Loading branch information
csasarak committed Dec 3, 2024
1 parent 4ed7eab commit 4cc7bf5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Strategy/Gomodules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Strategy.Gomodules (
getDeps,
mkProject,
GomodulesProject (..),
) where
)
where

import App.Fossa.Analyze.Types (AnalyzeProject (analyzeProjectStaticOnly), analyzeProject)
import App.Fossa.Config.Analyze (ExperimentalAnalyzeConfig (useV3GoResolver), GoDynamicTactic (..))
Expand Down Expand Up @@ -57,7 +58,7 @@ instance ToJSON GomodulesProject

instance AnalyzeProject GomodulesProject where
analyzeProject _ proj = asks useV3GoResolver >>= getDeps proj
analyzeProjectStaticOnly _ = const $ fatalText "Cannot analyze GoModule project statically"
analyzeProjectStaticOnly _ proj = staticAnalysisResults proj <$> staticAnalysis proj

mkProject :: GomodulesProject -> DiscoveredProject GomodulesProject
mkProject project =
Expand All @@ -71,7 +72,7 @@ mkProject project =
getDeps :: (GetDepsEffs sig m) => GomodulesProject -> GoDynamicTactic -> m DependencyResults
getDeps project goDynamicTactic = do
mode <- ask
(graph, graphBreadth) <- context "Gomodules" $ dynamicAnalysis <||> guardStrictMode mode staticAnalysis
(graph, graphBreadth) <- context "Gomodules" $ dynamicAnalysis <||> guardStrictMode mode (staticAnalysis project)
stdlib <- recover . context "Collect go standard library information" . listGoStdlibPackages $ gomodulesDir project
pure $
DependencyResults
Expand All @@ -86,9 +87,6 @@ getDeps project goDynamicTactic = do
filterGraph Nothing deps = deps
filterGraph (Just stdlib) deps = filterGoStdlibPackages stdlib deps

staticAnalysis :: (Has Exec sig m, Has ReadFS sig m, Has Diagnostics sig m) => m (Graphing Dependency, GraphBreadth)
staticAnalysis = context "Static analysis" (Gomod.analyze' (gomodulesGomod project))

dynamicAnalysis :: (Has Exec sig m, Has Diagnostics sig m) => m (Graphing Dependency, GraphBreadth)
dynamicAnalysis =
context "Dynamic analysis" $ do
Expand All @@ -98,3 +96,14 @@ getDeps project goDynamicTactic = do
\This option will be removed in a future release and result in an error."

context "analysis using go list (V3 Resolver)" (GoListPackages.analyze (gomodulesDir project))

staticAnalysis :: (Has Exec sig m, Has ReadFS sig m, Has Diagnostics sig m) => GomodulesProject -> m (Graphing Dependency, GraphBreadth)
staticAnalysis project = context "Static analysis" (Gomod.analyze' (gomodulesGomod project))

staticAnalysisResults :: GomodulesProject -> (Graphing Dependency, GraphBreadth) -> DependencyResults
staticAnalysisResults proj (graph, graphBreadth) =
DependencyResults
{ dependencyGraph = graph
, dependencyGraphBreadth = graphBreadth
, dependencyManifestFiles = [gomodulesGomod proj]
}

0 comments on commit 4cc7bf5

Please sign in to comment.