         guard let pkgConfig = manifest.package.pkgConfig else { return nil }
         return RelativePath(pkgConfig)
     }
-    
+
+    /// Returns path to all the items in a directory.
+    func directoryContents(_ path: AbsolutePath) throws -> [AbsolutePath] {
+        return try fileSystem.getDirectoryContents(path).map { path.appending(component: $0) }
+    }
+
     func sourceRoot() throws -> AbsolutePath {
-        let viableRoots = try walk(packagePath, recursively: false).filter { entry in
-            switch entry.basename.lowercased() {
+        let viableRoots = try fileSystem.getDirectoryContents(packagePath).filter { basename in
+            let entry = packagePath.appending(component: basename)
+            switch basename.lowercased() {
             case "sources", "source", "src", "srcs":
-                return entry.asString.isDirectory && !excludedPaths.contains(entry)
+                return fileSystem.isDirectory(entry) && !excludedPaths.contains(entry)
             default:
                 return false
             }

        if path.basename.hasPrefix(".") { return false }
        if path == manifest.path { return false }
        if excludedPaths.contains(path) { return false }
        if !path.asString.isFile { return false }
        guard let ext = path.asString.fileExt else { return false }
        return validExtensions.contains(ext)
    }
    
    private func shouldConsiderDirectory(_ path: AbsolutePath) -> Bool {

        case 0:
            return packagePath
        case 1:
            return packagePath.appending(component: viableRoots[0])
        default:
            // eg. there is a `Sources' AND a `src'
            throw ModuleError.invalidLayout(.multipleSourceRoots(viableRoots.map{ packagePath.appending(component: $0).asString }))
        }
    }

    /// Collects the modules which are defined by a package.
    private func constructModules() throws -> [Module] {
        let moduleMapPath = packagePath.appending("module.modulemap")
        if fileSystem.isFile(moduleMapPath) {
            let sources = Sources(paths: [moduleMapPath], root: packagePath)
            return [try CModule(name: manifest.name, sources: sources, path: packagePath, pkgConfig: pkgConfigPath, providers: manifest.package.providers)]
        }
