diff --git a/src/App/Fossa/BinaryDeps.hs b/src/App/Fossa/BinaryDeps.hs index 83b2ecb3c3..edd968f3e4 100644 --- a/src/App/Fossa/BinaryDeps.hs +++ b/src/App/Fossa/BinaryDeps.hs @@ -22,12 +22,20 @@ import Path.Extra (tryMakeRelative) import Srclib.Converter qualified as Srclib import Srclib.Types (AdditionalDepData (..), SourceUnit (..), SourceUserDefDep (..)) import Types (DiscoveredProjectType (BinaryDepsProjectType), GraphBreadth (Complete)) +import Control.Carrier.Reader (Reader) -- | Binary detection is sufficiently different from other analysis types that it cannot be just another strategy. -- Instead, binary detection is run separately over the entire scan directory, outputting its own source unit. -- The goal of this feature is to enable a FOSSA user to flag all vendored binaries (as defined by git) in the project as dependencies. -- Users may then use standard FOSSA UX flows to ignore or add license information to the detected binaries. -analyzeBinaryDeps :: (Has (Lift IO) sig m, Has Diagnostics sig m, Has Logger sig m, Has ReadFS sig m) => Path Abs Dir -> AllFilters -> m (Maybe SourceUnit) +analyzeBinaryDeps :: + (Has (Lift IO) sig m + , Has Diagnostics sig m + , Has Logger sig m + , Has ReadFS sig m + , Has (Reader AllFilters) sig m + ) => + Path Abs Dir -> AllFilters -> m (Maybe SourceUnit) analyzeBinaryDeps dir filters = do binaryPaths <- findBinaries (toPathFilters dir filters) dir if null binaryPaths @@ -43,10 +51,22 @@ analyzeBinaryDeps dir filters = do -- The @Path Abs Dir@ provided is used to render the name of the resulting dependency: -- if we fallback to a plain "unknown binary" strategy its name is reported as the relative path between the provided @Path Abs Dir@ and the @Path Abs File@. -- If the path can't be made relative, the dependency name is the absolute path of the binary. -analyzeSingleBinary :: (Has (Lift IO) sig m, Has Logger sig m, Has ReadFS sig m, Has Diagnostics sig m) => Path Abs Dir -> Path Abs File -> m SourceUserDefDep +analyzeSingleBinary :: + (Has (Lift IO) sig m + , Has Logger sig m + , Has ReadFS sig m + , Has Diagnostics sig m + , Has (Reader AllFilters) sig m + ) => + Path Abs Dir -> Path Abs File -> m SourceUserDefDep analyzeSingleBinary root file = context ("Analyzing " <> toText file) $ resolveBinary strategies root file -findBinaries :: (Has (Lift IO) sig m, Has Diagnostics sig m, Has ReadFS sig m) => PathFilters -> Path Abs Dir -> m [Path Abs File] +findBinaries :: + (Has (Lift IO) sig m + , Has Diagnostics sig m + , Has ReadFS sig m + , Has (Reader AllFilters) sig m + ) => PathFilters -> Path Abs Dir -> m [Path Abs File] findBinaries filters = walk' $ \dir _ files -> do if shouldFingerprintDir dir filters then do @@ -100,7 +120,14 @@ resolveBinary (resolve : remainingStrategies) = \root file -> do resolveBinary [] = strategyRawFingerprint -- | Functions which may be able to resolve a binary to a dependency. -strategies :: (Has (Lift IO) sig m, Has Diagnostics sig m, Has Logger sig m, Has ReadFS sig m) => [(Path Abs Dir -> Path Abs File -> m (Maybe SourceUserDefDep))] +strategies :: + (Has (Lift IO) sig m + , Has Diagnostics sig m + , Has Logger sig m + , Has ReadFS sig m + , Has (Reader AllFilters) sig m + ) => + [(Path Abs Dir -> Path Abs File -> m (Maybe SourceUserDefDep))] strategies = [resolveJar] diff --git a/src/App/Fossa/BinaryDeps/Jar.hs b/src/App/Fossa/BinaryDeps/Jar.hs index 0dc3a29702..4829d06c4b 100644 --- a/src/App/Fossa/BinaryDeps/Jar.hs +++ b/src/App/Fossa/BinaryDeps/Jar.hs @@ -40,6 +40,8 @@ import Strategy.Maven.Pom.PomFile ( pomLicenseName, validatePom, ) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) data JarMetadata = JarMetadata { jarName :: Text @@ -53,7 +55,13 @@ data JarMetadata = JarMetadata -- 2. Search inside for a file named `pom.xml`; if there are multiple pick the one with the shortest path. -- If a representative pom.xml was found, parse it and return metadata derived from it. -- 3. Attempt to open `META-INF/MANIFEST.MF`, parse it, and return metadata derived from it. -resolveJar :: (Has (Lift IO) sig m, Has Diagnostics sig m, Has Logger sig m, Has ReadFS sig m) => Path Abs Dir -> Path Abs File -> m (Maybe SourceUserDefDep) +resolveJar :: + (Has (Lift IO) sig m + , Has Diagnostics sig m + , Has Logger sig m + , Has ReadFS sig m + , Has (Reader AllFilters) sig m + ) => Path Abs Dir -> Path Abs File -> m (Maybe SourceUserDefDep) resolveJar _ file | not $ fileHasSuffix file [".jar", ".aar"] = pure Nothing resolveJar root file = do let fileDescription = toText file @@ -101,7 +109,13 @@ metaInfManifestToMeta manifest = <*> fromMaybeText "Missing implementation version" (Map.lookup "Implementation-Version" manifest) <*> pure "" -- Don't attempt to use Bundle-License; it's a URL and we don't parse it on the backend -tacticPom :: (Has (Lift IO) sig m, Has Diagnostics sig m, Has Logger sig m, Has ReadFS sig m) => Path Abs Dir -> m JarMetadata +tacticPom :: + (Has (Lift IO) sig m + , Has Diagnostics sig m + , Has Logger sig m + , Has ReadFS sig m + , Has (Reader AllFilters) sig m + ) => Path Abs Dir -> m JarMetadata tacticPom archive = context ("Parse representative pom.xml in " <> toText archive) $ do poms <- context "Find pom.xml files" $ walk' (collectFilesNamed "pom.xml") (archive $(mkRelDir "META-INF")) when (length poms > 1) $ diff --git a/src/App/Fossa/LicenseScanner.hs b/src/App/Fossa/LicenseScanner.hs index f30c1605e8..3b903b8bac 100644 --- a/src/App/Fossa/LicenseScanner.hs +++ b/src/App/Fossa/LicenseScanner.hs @@ -81,6 +81,8 @@ import Srclib.Types ( Locator (..), ) import Types (LicenseScanPathFilters (licenseScanPathFilterFileExclude)) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) data LicenseScanErr = NoSuccessfulScans SourceLocation @@ -110,6 +112,7 @@ runLicenseScanOnDir :: , Has (Lift IO) sig m , Has Exec sig m , Has ReadFS sig m + , Has (Reader AllFilters) sig m ) => Text -> Maybe LicenseScanPathFilters -> @@ -130,6 +133,7 @@ recursivelyScanArchives :: , Has Diagnostics sig m , Has Finally sig m , Has Exec sig m + , Has (Reader AllFilters) sig m ) => Text -> Maybe LicenseScanPathFilters -> @@ -202,6 +206,7 @@ scanAndUploadVendoredDep :: , Has Exec sig m , Has ReadFS sig m , Has FossaApiClient sig m + , Has (Reader AllFilters) sig m ) => Path Abs Dir -> Maybe LicenseScanPathFilters -> @@ -220,6 +225,7 @@ scanVendoredDep :: , Has StickyLogger sig m , Has Exec sig m , Has ReadFS sig m + , Has (Reader AllFilters) sig m ) => Path Abs Dir -> Maybe LicenseScanPathFilters -> @@ -247,6 +253,7 @@ scanArchive :: , Has (Lift IO) sig m , Has Exec sig m , Has ReadFS sig m + , Has (Reader AllFilters) sig m , Has StickyLogger sig m ) => Path Abs Dir -> @@ -271,6 +278,7 @@ scanDirectory :: , Has ReadFS sig m , Has Diagnostics sig m , Has (Lift IO) sig m + , Has (Reader AllFilters) sig m ) => Maybe ScannableArchive -> Text -> @@ -287,6 +295,7 @@ scanDirectory origin pathPrefix licenseScanPathFilters uploadKind path = do hasAnyFiles :: ( Has Diagnostics sig m , Has ReadFS sig m + , Has (Reader AllFilters) sig m ) => Path Abs Dir -> m Bool @@ -306,6 +315,7 @@ scanNonEmptyDirectory :: , Has (Lift IO) sig m , Has Diagnostics sig m , Has ReadFS sig m + , Has (Reader AllFilters) sig m ) => Text -> Maybe LicenseScanPathFilters -> @@ -349,6 +359,7 @@ licenseScanSourceUnit :: , Has Logger sig m , Has Exec sig m , Has ReadFS sig m + , Has (Reader AllFilters) sig m , Has FossaApiClient sig m ) => VendoredDependencyScanMode -> diff --git a/src/App/Fossa/Reachability/Maven.hs b/src/App/Fossa/Reachability/Maven.hs index 3dee031702..164204c9a3 100644 --- a/src/App/Fossa/Reachability/Maven.hs +++ b/src/App/Fossa/Reachability/Maven.hs @@ -23,6 +23,8 @@ import Strategy.Maven.Pom.PomFile ( PomBuild (PomBuild), ) import Text.Pretty.Simple (pShow) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) -- | Discovers the JAR files associated with the project at the provided path, -- then returns the parsed results of analyzing these JARs. @@ -32,6 +34,7 @@ mavenJarCallGraph :: , Has Diagnostics sig m , Has Exec sig m , Has (Lift IO) sig m + , Has (Reader AllFilters) sig m ) => Path Abs Dir -> m CallGraphAnalysis @@ -44,6 +47,7 @@ getJarsByBuild :: ( Has Logger sig m , Has ReadFS sig m , Has Diagnostics sig m + , Has (Reader AllFilters) sig m ) => Path Abs Dir -> m [Path Abs File] diff --git a/src/App/Fossa/Reachability/Upload.hs b/src/App/Fossa/Reachability/Upload.hs index a2cec00b94..2b6dd5d306 100644 --- a/src/App/Fossa/Reachability/Upload.hs +++ b/src/App/Fossa/Reachability/Upload.hs @@ -48,6 +48,7 @@ import Srclib.Types ( SourceUnitDependency (..), ) import Types (DiscoveredProjectType (..), GraphBreadth (..)) +import Discovery.Filters (AllFilters) analyzeForReachability :: ( Has Logger sig m @@ -57,6 +58,7 @@ analyzeForReachability :: , Has (Lift IO) sig m , Has Debug sig m , Has (Reader ReachabilityConfig) sig m + , Has (Reader AllFilters) sig m ) => [DiscoveredProjectScan] -> m [SourceUnitReachabilityAttempt] @@ -107,6 +109,7 @@ callGraphOf :: , Has (Lift IO) sig m , Has Debug sig m , Has (Reader ReachabilityConfig) sig m + , Has (Reader AllFilters) sig m ) => DiscoveredProjectScan -> m SourceUnitReachabilityAttempt diff --git a/src/App/Fossa/VSI/Analyze.hs b/src/App/Fossa/VSI/Analyze.hs index a726f0c3bb..5aea4d27aa 100644 --- a/src/App/Fossa/VSI/Analyze.hs +++ b/src/App/Fossa/VSI/Analyze.hs @@ -38,6 +38,7 @@ import Effect.Logger (Color (..), Logger, Severity (SevError, SevInfo, SevWarn), import Effect.ReadFS (ReadFS) import Path (Abs, Dir, File, Path, Rel, isProperPrefixOf, ()) import Path qualified as P +import Control.Carrier.Reader (Reader) runVsiAnalysis :: ( Has (Lift IO) sig m @@ -228,6 +229,7 @@ discover :: , Has Finally sig m , Has TaskPool sig m , Has Logger sig m + , Has (Reader AllFilters) sig m ) => TBMChan (Path Rel File, Combined) -> -- | Filters used to exclude scanned directories diff --git a/src/App/Fossa/VSI/DynLinked/Internal/Resolve.hs b/src/App/Fossa/VSI/DynLinked/Internal/Resolve.hs index 66adfbd776..049af31afc 100644 --- a/src/App/Fossa/VSI/DynLinked/Internal/Resolve.hs +++ b/src/App/Fossa/VSI/DynLinked/Internal/Resolve.hs @@ -35,6 +35,8 @@ import Text.Megaparsec (Parsec, empty, eof, many, takeWhile1P) import Text.Megaparsec.Char (char, space1) import Text.Megaparsec.Char.Lexer qualified as L import Types (DiscoveredProjectType (VsiProjectType), GraphBreadth (Complete)) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) -- | Resolves a set of dynamic dependencies into a @SourceUnit@. -- Any @DynamicDependency@ that isn't resolved to a Linux package dependency is converted to an unknown binary dependency. @@ -43,6 +45,7 @@ toSourceUnit :: , Has Logger sig m , Has ReadFS sig m , Has Diagnostics sig m + , Has (Reader AllFilters) sig m ) => Path Abs Dir -> LinuxDistro -> diff --git a/src/App/Fossa/VSI/Fingerprint.hs b/src/App/Fossa/VSI/Fingerprint.hs index f7cc6e646c..f2ccfdc841 100644 --- a/src/App/Fossa/VSI/Fingerprint.hs +++ b/src/App/Fossa/VSI/Fingerprint.hs @@ -29,6 +29,8 @@ import Data.Word8 (isSpace) import Discovery.Walk (WalkStep (..), walk') import Effect.ReadFS (ReadFS, contentIsBinary) import Path (Abs, Dir, File, Path, toFilePath) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) -- | Fingerprint deterministically idenfies a file and is derived from its content. -- @@ -99,7 +101,7 @@ fingerprintRaw file = context "raw" $ contentIsBinary file >>= doFingerprint fp <- hasher $ toFilePath file pure $ encodeFingerprint fp -fingerprintContentsRaw :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Lift IO) sig m) => Path Abs Dir -> m [Fingerprint Raw] +fingerprintContentsRaw :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Lift IO) sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [Fingerprint Raw] fingerprintContentsRaw = walk' $ \_ _ files -> do fps <- traverse fingerprintRaw files pure (fps, WalkContinue) diff --git a/src/App/Fossa/VSI/IAT/AssertRevisionBinaries.hs b/src/App/Fossa/VSI/IAT/AssertRevisionBinaries.hs index f3480dd210..73caeb6ec6 100644 --- a/src/App/Fossa/VSI/IAT/AssertRevisionBinaries.hs +++ b/src/App/Fossa/VSI/IAT/AssertRevisionBinaries.hs @@ -11,12 +11,15 @@ import Effect.Logger (Logger, logInfo) import Effect.ReadFS (ReadFS) import Path (Abs, Dir, Path) import Srclib.Types (Locator) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) assertRevisionBinaries :: ( Has Diagnostics sig m , Has ReadFS sig m , Has (Lift IO) sig m , Has Logger sig m + , Has (Reader AllFilters) sig m , Has API.FossaApiClient sig m ) => Path Abs Dir -> diff --git a/src/App/Fossa/VSI/IAT/AssertUserDefinedBinaries.hs b/src/App/Fossa/VSI/IAT/AssertUserDefinedBinaries.hs index ce3417fd46..d3783c2ffb 100644 --- a/src/App/Fossa/VSI/IAT/AssertUserDefinedBinaries.hs +++ b/src/App/Fossa/VSI/IAT/AssertUserDefinedBinaries.hs @@ -22,7 +22,10 @@ import Control.Effect.Lift (Lift) import Control.Monad (void) import Effect.Logger (Logger, logInfo) import Effect.ReadFS (ReadFS) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) +-- TODO: pass a `Has (Reader AllFilters) sig m` effect here somehow? linkBinsSubCommand :: SubCommand LinkUserBinsOpts LinkUserBinsConfig linkBinsSubCommand = mkSubCommand assertUserDefinedBinaries @@ -31,6 +34,7 @@ assertUserDefinedBinaries :: , Has ReadFS sig m , Has (Lift IO) sig m , Has Logger sig m + , Has (Reader AllFilters) sig m ) => LinkUserBinsConfig -> m () diff --git a/src/App/Fossa/VSIDeps.hs b/src/App/Fossa/VSIDeps.hs index b4d5e4fc53..02a37e6da4 100644 --- a/src/App/Fossa/VSIDeps.hs +++ b/src/App/Fossa/VSIDeps.hs @@ -32,6 +32,7 @@ import Path (Abs, Dir, Path, toFilePath) import Srclib.Converter qualified as Srclib import Srclib.Types (AdditionalDepData (..), SourceUnit (..), SourceUserDefDep, textToOriginPath) import Types (DiscoveredProjectType (..), GraphBreadth (Complete)) +import Control.Carrier.Reader (Reader) -- | VSI analysis is sufficiently different from other analysis types that it cannot be just another strategy. -- Instead, VSI analysis is run separately over the entire scan directory, outputting its own source unit. diff --git a/src/Discovery/Archive.hs b/src/Discovery/Archive.hs index 9c7deb296a..ac34bc3f1a 100644 --- a/src/Discovery/Archive.hs +++ b/src/Discovery/Archive.hs @@ -51,6 +51,8 @@ import Path qualified as P import Path.IO qualified as PIO import Prettyprinter (Pretty (pretty), hsep, viaShow, vsep) import Prelude hiding (zip) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) data ArchiveUnpackFailure = ArchiveUnpackFailure (Path Abs File) SomeException newtype UnsupportedArchiveErr = UnsupportedArchiveErr (Path Abs File) @@ -84,7 +86,13 @@ convertArchiveToDir file = do -- | Given a function to run over unarchived contents, recursively unpack archives discover :: - (Has (Lift IO) sig m, Has ReadFS sig m, Has Diagnostics sig m, Has Finally sig m, Has TaskPool sig m) => + (Has (Lift IO) sig m + , Has ReadFS sig m + , Has Diagnostics sig m + , Has Finally sig m + , Has TaskPool sig m + , Has (Reader AllFilters) sig m + ) => -- | Callback to run on the discovered file (Path Abs Dir -> Maybe FileAncestry -> m ()) -> -- | Path to the archive diff --git a/src/Discovery/Walk.hs b/src/Discovery/Walk.hs index 7feab80b84..270814c62b 100644 --- a/src/Discovery/Walk.hs +++ b/src/Discovery/Walk.hs @@ -50,6 +50,7 @@ data WalkStep walk :: ( Has ReadFS sig m , Has Diagnostics sig m + , Has (Reader AllFilters) sig m ) => (Path Abs Dir -> [Path Abs Dir] -> [Path Abs File] -> m WalkStep) -> Path Abs Dir -> @@ -90,6 +91,7 @@ walk' :: forall o sig m. ( Has ReadFS sig m , Has Diagnostics sig m + , Has (Reader AllFilters) sig m , Monoid o ) => (Path Abs Dir -> [Path Abs Dir] -> [Path Abs File] -> m (o, WalkStep)) -> @@ -160,7 +162,7 @@ findFilesMatchingGlob g = filter (`Glob.matches` g) -------------- Stolen from path-io; adapted to our own ReadFS effect walkDir :: - (Has ReadFS sig m, Has Diagnostics sig m) => + (Has ReadFS sig m, Has Diagnostics sig m, Has (Reader AllFilters) sig m) => -- | Handler (@dir -> subdirs -> files -> 'WalkAction'@) (Path Abs Dir -> [Path Abs Dir] -> [Path Abs File] -> m (WalkAction Abs)) -> -- | Directory where traversal begins @@ -178,18 +180,24 @@ walkDir handler topdir = Nothing -> pure $ Just () Just traversed' -> walktree traversed' curdir walktree traversed curdir = do - (subdirs, files) <- listDir curdir - action <- handler curdir subdirs files - case action of - WalkFinish -> pure Nothing - WalkExclude xdirs -> - case subdirs \\ xdirs of - [] -> pure $ Just () - ds -> - runMaybeT $ - mapM_ - (MaybeT . walkAvoidLoop traversed) - ds + filters <- ask + let isAllowed = maybe False (pathAllowed filters) (stripProperPrefix topdir curdir) + if isAllowed + then do + (subdirs, files) <- listDir curdir + action <- handler curdir subdirs files + case action of + WalkFinish -> pure Nothing + WalkExclude xdirs -> + case subdirs \\ xdirs of + [] -> pure $ Just () + ds -> + runMaybeT $ + mapM_ + (MaybeT . walkAvoidLoop traversed) + ds + else + pure Nothing checkLoop traversed dir = do identifier <- getIdentifier dir pure $ diff --git a/src/Strategy/Conan/Enrich.hs b/src/Strategy/Conan/Enrich.hs index 5fef3477af..068e3870f7 100644 --- a/src/Strategy/Conan/Enrich.hs +++ b/src/Strategy/Conan/Enrich.hs @@ -36,6 +36,8 @@ import Graphing (Graphing, gmap, vertexList) import Path (Abs, Dir, Path) import Srclib.Converter (fetcherToDepType, toLocator, verConstraintToRevision) import Srclib.Types (Locator (locatorFetcher, locatorProject, locatorRevision)) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) newtype LonelyDeps = LonelyDeps {unLonelyDeps :: [Dependency]} deriving (Eq, Ord, Show) @@ -53,6 +55,7 @@ conanToArchives :: , Has Logger sig m , Has Exec sig m , Has ReadFS sig m + , Has (Reader AllFilters) sig m , Has FossaApiClient sig m ) => Path Abs Dir -> -- directory of the project's manifest diff --git a/src/Strategy/Maven/Pom/Closure.hs b/src/Strategy/Maven/Pom/Closure.hs index 6bc35ebc67..e65404d338 100644 --- a/src/Strategy/Maven/Pom/Closure.hs +++ b/src/Strategy/Maven/Pom/Closure.hs @@ -28,14 +28,16 @@ import Strategy.Maven.Pom.PomFile import Strategy.Maven.Pom.Resolver import Data.Text (Text) +import Control.Carrier.Reader (Reader) +import Discovery.Filters (AllFilters) -findProjects :: (Has ReadFS sig m, Has Diagnostics sig m) => Path Abs Dir -> m [MavenProjectClosure] +findProjects :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [MavenProjectClosure] findProjects basedir = do pomFiles <- context "Finding pom files" $ findPomFiles basedir globalClosure <- context "Building global closure" $ buildGlobalClosure pomFiles context "Building project closures" $ pure (buildProjectClosures basedir globalClosure) -findPomFiles :: (Has ReadFS sig m, Has Diagnostics sig m) => Path Abs Dir -> m [Path Abs File] +findPomFiles :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [Path Abs File] findPomFiles dir = execState @[Path Abs File] [] $ flip walk dir $ \_ _ files -> do let poms = filter (\file -> "pom.xml" `isSuffixOf` fileName file || ".pom" `isSuffixOf` fileName file) files diff --git a/src/Strategy/Node.hs b/src/Strategy/Node.hs index 78ea856d7c..f35ee31bae 100644 --- a/src/Strategy/Node.hs +++ b/src/Strategy/Node.hs @@ -49,7 +49,7 @@ import Discovery.Filters (AllFilters, withMultiToolFilter) import Discovery.Walk ( WalkStep (WalkSkipSome), findFileNamed, - walk', + walk', walkWithFilters', ) import Effect.Logger ( Logger, @@ -129,7 +129,7 @@ discover dir = withMultiToolFilter [YarnProjectType, NpmProjectType, PnpmProject graphs <- context "Splitting global graph into chunks" $ fromMaybe CyclicPackageJson $ splitGraph globalGraph context "Converting graphs to analysis targets" $ traverse (mkProject <=< identifyProjectType) graphs -collectManifests :: (Has ReadFS sig m, Has Diagnostics sig m) => Path Abs Dir -> m [Manifest] +collectManifests :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [Manifest] collectManifests = walk' $ \_ _ files -> case findFileNamed "package.json" files of Nothing -> pure ([], skipJsFolders) diff --git a/src/Strategy/SwiftPM.hs b/src/Strategy/SwiftPM.hs index f6d12c9ee6..04869ad8a8 100644 --- a/src/Strategy/SwiftPM.hs +++ b/src/Strategy/SwiftPM.hs @@ -18,7 +18,7 @@ import Discovery.Simple (simpleDiscover) import Discovery.Walk ( WalkStep (WalkContinue, WalkSkipSome), findFileNamed, - walk', + walkWithFilters', ) import Effect.Logger (Logger, Pretty (pretty), logDebug) import Effect.ReadFS (ReadFS) @@ -54,15 +54,14 @@ instance ToJSON SwiftProject discover :: (Has ReadFS sig m, Has Diagnostics sig m, Has Logger sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [DiscoveredProject SwiftProject] discover = simpleDiscover findProjects mkProject SwiftProjectType -findProjects :: (Has ReadFS sig m, Has Diagnostics sig m, Has Logger sig m) => Path Abs Dir -> m [SwiftProject] +findProjects :: (Has ReadFS sig m, Has Diagnostics sig m, Has Logger sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [SwiftProject] findProjects dir = do swiftPackageProjects <- context "Finding swift package projects" $ findSwiftPackageProjects dir xCodeProjects <- context "Finding xcode projects using swift package manager" $ findXcodeProjects dir pure (swiftPackageProjects <> xCodeProjects) --- TODO: determine if walkWithFilters' is safe here -findSwiftPackageProjects :: (Has ReadFS sig m, Has Diagnostics sig m) => Path Abs Dir -> m [SwiftProject] -findSwiftPackageProjects = walk' $ \dir _ files -> do +findSwiftPackageProjects :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [SwiftProject] +findSwiftPackageProjects = walkWithFilters' $ \dir _ files -> do let packageManifestFile = findFileNamed "Package.swift" files let packageResolvedFile = findFileNamed "Package.resolved" files case (packageManifestFile, packageResolvedFile) of @@ -72,9 +71,8 @@ findSwiftPackageProjects = walk' $ \dir _ files -> do -- Package.resolved without Package.swift or Xcode project file is not a valid swift project. (Nothing, _) -> pure ([], WalkContinue) --- TODO: determine if walkWithFilters' is safe here -findXcodeProjects :: (Has ReadFS sig m, Has Diagnostics sig m, Has Logger sig m) => Path Abs Dir -> m [SwiftProject] -findXcodeProjects = walk' $ \dir _ files -> do +findXcodeProjects :: (Has ReadFS sig m, Has Diagnostics sig m, Has Logger sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [SwiftProject] +findXcodeProjects = walkWithFilters' $ \dir _ files -> do let xcodeProjectFile = findFileNamed "project.pbxproj" files case xcodeProjectFile of Nothing -> pure ([], WalkContinue) @@ -89,8 +87,8 @@ findXcodeProjects = walk' $ \dir _ files -> do -- XCode projects using swift package manager retain Package.resolved, -- not in the same directory as project file, but rather in workspace's xcshareddata/swiftpm directory. -- Reference: https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app. -findFirstResolvedFileRecursively :: (Has ReadFS sig m, Has Diagnostics sig m) => Path Abs Dir -> m (Maybe (Path Abs File)) -findFirstResolvedFileRecursively baseDir = listToMaybe <$> walk' findFile baseDir +findFirstResolvedFileRecursively :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m (Maybe (Path Abs File)) +findFirstResolvedFileRecursively baseDir = listToMaybe <$> walkWithFilters' findFile baseDir where isParentDirSwiftPm :: Path Abs Dir -> Bool isParentDirSwiftPm d = (dirname d) == [reldir|swiftpm|]