<commit_before>/*
 This source file is part of the Swift.org open source project

 Copyright 2015 - 2016 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import PackageModel
import Utility

extension ModuleProtocol {
    /// Returns the pkgConfig flags (cFlags + libs) escaping the cflags with -Xcc.
    //
    // FIXME: This isn't correct. We need to scan both list of flags and escape
    // the flags (using -Xcc and -Xlinker) which can't be passed directly to
    // swift compiler.
    public func pkgConfigSwiftcArgs() throws -> [String] {
        let pkgArgs = try pkgConfigArgs()
        return pkgArgs.cFlags.map{["-Xcc", $0]}.flatten() + pkgArgs.libs
    }

    /// Finds cFlags and link flags for all the CModule i.e. System Module
    /// dependencies of a module for which a pkgConfigName is provided in the
    /// manifest file. Also prints the help text in case the .pc file
    /// for that System Module is not found.
    /// Note: The flags are exactly what one would get from pkg-config without
    /// any escaping like -Xcc or -Xlinker which is needed for swift compiler.
    public func pkgConfigArgs() throws -> (cFlags: [String], libs: [String]) {
        var cFlags = [String]()
        var libs = [String]()
        try recursiveDependencies.forEach { module in
            guard case let module as CModule = module, let pkgConfigName = module.pkgConfig else {
                return
            }
            do {
                let pkgConfig = try PkgConfig(name: pkgConfigName.asString)<commit_msg>[PackageLoading] Use flatMap vs map + flatten.<commit_after>/*
 This source file is part of the Swift.org open source project

 Copyright 2015 - 2016 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import PackageModel
import Utility

extension ModuleProtocol {
    /// Returns the pkgConfig flags (cFlags + libs) escaping the cflags with -Xcc.
    //
    // FIXME: This isn't correct. We need to scan both list of flags and escape
    // the flags (using -Xcc and -Xlinker) which can't be passed directly to
    // swift compiler.
    public func pkgConfigSwiftcArgs() throws -> [String] {
        let pkgArgs = try pkgConfigArgs()
        return pkgArgs.cFlags.flatMap{ ["-Xcc", $0] } + pkgArgs.libs
    }

    /// Finds cFlags and link flags for all the CModule i.e. System Module
    /// dependencies of a module for which a pkgConfigName is provided in the
    /// manifest file. Also prints the help text in case the .pc file
    /// for that System Module is not found.
    /// Note: The flags are exactly what one would get from pkg-config without
    /// any escaping like -Xcc or -Xlinker which is needed for swift compiler.
    public func pkgConfigArgs() throws -> (cFlags: [String], libs: [String]) {
        var cFlags = [String]()
        var libs = [String]()
        try recursiveDependencies.forEach { module in
            guard case let module as CModule = module, let pkgConfigName = module.pkgConfig else {
                return
            }
            do {
                let pkgConfig = try PkgConfig(name: pkgConfigName.asString)
{'fraction_non_alphanumeric': 0.08234614273331407, 'fraction_numerical': 0.006356544351343542, 'mean_word_length': 2.5950155763239877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6335959', 'n_tokens_mistral': 974, 'n_tokens_neox': 893, 'n_words': 411}