Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Handle multiple spec files in one directory #138

Merged
merged 2 commits into from
Sep 26, 2020
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
@@ -1,5 +1,6 @@
# v2.3.1

- RPM: Merge spec file results in the analyzer. ([#138](https://github.com/fossas/spectrometer/pull/138))
- Gradle: Accept and tag all build configuration names. ([#134](https://github.com/fossas/spectrometer/pull/134))

# v2.3.0
Expand Down
29 changes: 21 additions & 8 deletions src/Strategy/RPM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module Strategy.RPM
where

import Control.Effect.Diagnostics
import Data.Foldable (traverse_)
import Control.Monad (unless, when)
import Data.List (isSuffixOf)
import qualified Data.Map.Strict as M
import Data.Maybe (mapMaybe)
import Data.Maybe (mapMaybe, catMaybes)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Extra (splitOnceOn)
Expand Down Expand Up @@ -53,14 +53,27 @@ data Dependencies
deriving (Eq, Ord, Show)

discover :: HasDiscover sig m => Path Abs Dir -> m ()
discover = walk $ \dir _ files ->
discover = walk $ \dir _ files -> do
let specs = filter (\f -> ".spec" `isSuffixOf` fileName f) files
analyzeFile specFile = runSimpleStrategy "rpm-spec" RPMGroup $ fmap (mkProjectClosure dir) (analyze specFile)
in traverse_ analyzeFile specs >> pure WalkContinue

unless (null specs) $ runSimpleStrategy "rpm-spec" RPMGroup $ fmap (mkProjectClosure dir) (analyze specs)
pure WalkContinue

analyze :: (Has ReadFS sig m, Has Diagnostics sig m) => Path Abs File -> m (Graphing Dependency)
analyze specFile = do
specFileText <- readContentsText specFile
analyze :: (Has ReadFS sig m, Has Diagnostics sig m) => [Path Abs File] -> m (Graphing Dependency)
analyze specFiles = do
results <- traverse (recover . analyzeSingle) specFiles
let successful = catMaybes results

when (null successful) $ fatalText "Analysis failed for all discovered *.spec files"

let graphing :: Graphing Dependency
graphing = mconcat successful

pure graphing

analyzeSingle :: (Has ReadFS sig m, Has Diagnostics sig m) => Path Abs File -> m (Graphing Dependency)
analyzeSingle file = do
specFileText <- readContentsText file
pure . buildGraph $ getSpecDeps specFileText

mkProjectClosure :: Path Abs Dir -> Graphing Dependency -> ProjectClosureBody
Expand Down