-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run build tool plugins for C-family targets
While we intentionally don't support generating C sources from plugins today since we haven't figured out how to deal with headers etc, not running plugins at all without any diagnostics whatsoever seems like an implementation oversight based on the fact that we have two completely different implementations for Swift and C-family targets (which is something we also need to rectify at some point). With this change, we're running build-tool plugins in the exact same way as we are doing it for Swift targets. We are only doing this for packages with tools-version 5.9 or higher in order to have any unintentional impact on existing packages. rdar://101671614 Co-authored-by: Max Desiatov <[email protected]> (cherry picked from commit 678e683)
- Loading branch information
Showing
7 changed files
with
179 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Sources/Build/BuildDescription/SharedTargetBuildDescription.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2023 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 the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Basics | ||
import PackageGraph | ||
import PackageLoading | ||
import PackageModel | ||
import SPMBuildCore | ||
|
||
import struct TSCBasic.AbsolutePath | ||
|
||
/// Shared functionality between `ClangTargetBuildDescription` and `SwiftTargetBuildDescription` with the eventual hope of having a single type. | ||
struct SharedTargetBuildDescription { | ||
static func computePluginGeneratedFiles( | ||
target: ResolvedTarget, | ||
toolsVersion: ToolsVersion, | ||
additionalFileRules: [FileRuleDescription], | ||
buildParameters: BuildParameters, | ||
buildToolPluginInvocationResults: [BuildToolPluginInvocationResult], | ||
prebuildCommandResults: [PrebuildCommandResult], | ||
observabilityScope: ObservabilityScope | ||
) -> (pluginDerivedSources: Sources, pluginDerivedResources: [Resource]) { | ||
var pluginDerivedSources = Sources(paths: [], root: buildParameters.dataPath) | ||
|
||
// Add any derived files that were declared for any commands from plugin invocations. | ||
var pluginDerivedFiles = [AbsolutePath]() | ||
for command in buildToolPluginInvocationResults.reduce([], { $0 + $1.buildCommands }) { | ||
for absPath in command.outputFiles { | ||
pluginDerivedFiles.append(absPath) | ||
} | ||
} | ||
|
||
// Add any derived files that were discovered from output directories of prebuild commands. | ||
for result in prebuildCommandResults { | ||
for path in result.derivedFiles { | ||
pluginDerivedFiles.append(path) | ||
} | ||
} | ||
|
||
// Let `TargetSourcesBuilder` compute the treatment of plugin generated files. | ||
let (derivedSources, derivedResources) = TargetSourcesBuilder.computeContents( | ||
for: pluginDerivedFiles, | ||
toolsVersion: toolsVersion, | ||
additionalFileRules: additionalFileRules, | ||
defaultLocalization: target.defaultLocalization, | ||
targetName: target.name, | ||
targetPath: target.underlyingTarget.path, | ||
observabilityScope: observabilityScope | ||
) | ||
let pluginDerivedResources = derivedResources | ||
derivedSources.forEach { absPath in | ||
let relPath = absPath.relative(to: pluginDerivedSources.root) | ||
pluginDerivedSources.relativePaths.append(relPath) | ||
} | ||
|
||
return (pluginDerivedSources, pluginDerivedResources) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters