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

 Copyright (c) 2014 - 2017 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 Basic

@_exported import enum PackageDescription4.SystemPackageProvider

public class Target: ObjectIdentifierProtocol {
    /// The target kind.
    public enum Kind: String {
        case executable
        case library
        case systemModule = "system-target"
        case test
    }

    /// The name of the target.
    ///
    /// NOTE: This name is not the language-level target (i.e., the importable
    /// name) name in many cases, instead use c99name if you need uniqueness.
    public let name: String

    /// The dependencies of this target.
    public let dependencies: [Target]

    /// The product dependencies of this target.
    public let productDependencies: [(name: String, package: String?)]

    /// The language-level target name.
    public let c99name: String

    /// Suffix that's expected for test targets.
    public static let testModuleNameSuffix = "Tests"

    /// The kind of target.
    public let type: Kind

    /// The sources for the target.
    public let sources: Sources

    fileprivate init(
        name: String,
        type: Kind,
        sources: Sources,
        dependencies: [Target],
        productDependencies: [(name: String, package: String?)] = []
    ) {
        self.name = name
        self.type = type
        self.sources = sources
        self.dependencies = dependencies
        self.productDependencies = productDependencies
        self.c99name = self.name.mangledToC99ExtendedIdentifier()
    }
}

public class SwiftTarget: Target {

    /// The file name of linux main file.
    public static let linuxMainBasename = "LinuxMain.swift"

    /// Create an executable Swift target from linux main test manifest file.
    init(linuxMain: AbsolutePath, name: String, dependencies: [Target]) {
        self.swiftVersion = ToolsVersion.currentToolsVersion.major
        let sources = Sources(paths: [linuxMain], root: linuxMain.parentDirectory)
        super.init(name: name, type: .executable, sources: sources, dependencies: dependencies)
    }

    /// The swift version of this target.
    public let swiftVersion: Int

    public init(
        name: String,
        isTest: Bool = false,
        sources: Sources,
        dependencies: [Target] = [],
        productDependencies: [(name: String, package: String?)] = [],
        swiftVersion: Int
    ) {
        let type: Kind = isTest ? .test : sources.computeModuleType()
        self.swiftVersion = swiftVersion
        super.init(
            name: name,
            type: type,
            sources: sources,
            dependencies: dependencies,
            productDependencies: productDependencies)<commit_msg>[PackageModel] Use correct swiftVersion for linux main targets<commit_after>/*
 This source file is part of the Swift.org open source project

 Copyright (c) 2014 - 2017 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 Basic

@_exported import enum PackageDescription4.SystemPackageProvider

public class Target: ObjectIdentifierProtocol {
    /// The target kind.
    public enum Kind: String {
        case executable
        case library
        case systemModule = "system-target"
        case test
    }

    /// The name of the target.
    ///
    /// NOTE: This name is not the language-level target (i.e., the importable
    /// name) name in many cases, instead use c99name if you need uniqueness.
    public let name: String

    /// The dependencies of this target.
    public let dependencies: [Target]

    /// The product dependencies of this target.
    public let productDependencies: [(name: String, package: String?)]

    /// The language-level target name.
    public let c99name: String

    /// Suffix that's expected for test targets.
    public static let testModuleNameSuffix = "Tests"

    /// The kind of target.
    public let type: Kind

    /// The sources for the target.
    public let sources: Sources

    fileprivate init(
        name: String,
        type: Kind,
        sources: Sources,
        dependencies: [Target],
        productDependencies: [(name: String, package: String?)] = []
    ) {
        self.name = name
        self.type = type
        self.sources = sources
        self.dependencies = dependencies
        self.productDependencies = productDependencies
        self.c99name = self.name.mangledToC99ExtendedIdentifier()
    }
}

public class SwiftTarget: Target {

    /// The file name of linux main file.
    public static let linuxMainBasename = "LinuxMain.swift"

    /// Create an executable Swift target from linux main test manifest file.
    init(linuxMain: AbsolutePath, name: String, dependencies: [Target]) {
        // Look for the first swift test target and use the same swift version
        // for linux main target. This will need to change if we move to a model
        // where we allow per target swift language version build settings.
        let swiftTestTarget = dependencies.first(where: {
            guard case let target as SwiftTarget = $0 else { return false }
            return target.type == .test
        }).flatMap({ $0 as? SwiftTarget })

        self.swiftVersion = swiftTestTarget?.swiftVersion ?? ToolsVersion.currentToolsVersion.major
        let sources = Sources(paths: [linuxMain], root: linuxMain.parentDirectory)
        super.init(name: name, type: .executable, sources: sources, dependencies: dependencies)
    }

    /// The swift version of this target.
    public let swiftVersion: Int

    public init(
        name: String,
        isTest: Bool = false,
        sources: Sources,
        dependencies: [Target] = [],
        productDependencies: [(name: String, package: String?)] = [],
        swiftVersion: Int
    ) {
        let type: Kind = isTest ? .test : sources.computeModuleType()
        self.swiftVersion = swiftVersion
        super.init(
            name: name,
            type: type,
            sources: sources,
            dependencies: dependencies,
            productDependencies: productDependencies)
{'fraction_non_alphanumeric': 0.08440761203192143, 'fraction_numerical': 0.006138735420503376, 'mean_word_length': 2.5, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '951232', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1580, 'n_words': 629}