Skip to content

Commit

Permalink
Add description of issue with pre-build commands
Browse files Browse the repository at this point in the history
  • Loading branch information
doozMen committed Jul 28, 2022
1 parent 266f0e8 commit 52b2ccf
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 4 deletions.
Expand Up @@ -91,6 +91,8 @@
C04DE67328911A9A00913661 /* PBXTargetDependency */,
);
name = SPMPluginXcode;
packageProductDependencies = (
);
productName = SPMPluginXcode;
productReference = C04DD8B028911A3A00913661 /* SPMPluginXcode.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -119,6 +121,8 @@
Base,
);
mainGroup = C04DD8A728911A3A00913661;
packageReferences = (
);
productRefGroup = C04DD8B128911A3A00913661 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C04DD8AF28911A3A00913661"
BuildableName = "SPMPluginXcode.app"
BlueprintName = "SPMPluginXcode"
ReferencedContainer = "container:SPMPluginXcode.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C04DD8AF28911A3A00913661"
BuildableName = "SPMPluginXcode.app"
BlueprintName = "SPMPluginXcode"
ReferencedContainer = "container:SPMPluginXcode.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "--brand HUB"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C04DD8AF28911A3A00913661"
BuildableName = "SPMPluginXcode.app"
BlueprintName = "SPMPluginXcode"
ReferencedContainer = "container:SPMPluginXcode.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
78 changes: 75 additions & 3 deletions Plugins/Plug/Plug.swift
Expand Up @@ -33,14 +33,22 @@ struct Plug: BuildToolPlugin {
FileManager.default.createFile(atPath: output.string, contents: nil)
print("🔌 did create ouput file at \(output.string)")
}
print("tool pre build = \(tool.path)")

return [
.prebuildCommand(
displayName: "PRE BUILD Copy all resources",
executable: tool.path, // ⚠️ The tool is not yet build at pre-build and so the output of this build phase will be that it cannot find the tool
arguments: [workingDirectory.string, input.string, output.string],
outputFilesDirectory: workingDirectory),
.buildCommand(
displayName: "Hello from plug into file",
executable: tool.path,
displayName: "BUILD Hello from plug into file",
executable: tool.path, // At this point the tool works and can be found
arguments: [input.string, output.string],
inputFiles: [input],
outputFiles: [output]
)]
)
]
}
}

Expand All @@ -56,6 +64,14 @@ extension Plug: XcodeBuildToolPlugin {
let sourceFiles = target.inputFiles
let pluginWorkingDirectory = context.pluginWorkDirectory

print("""
🔌 PluginContext
\(context)
🔌
""")

return try run(
tool,
workingDirectory: pluginWorkingDirectory,
Expand All @@ -64,4 +80,60 @@ extension Plug: XcodeBuildToolPlugin {
}
}

extension XcodePluginContext: CustomStringConvertible {
public var description: String {
return """
XcodePluginContext
\(xcodeProject)
pluginWorkDirectory:
\(pluginWorkDirectory)
"""
}
}

extension XcodeProjectPlugin.XcodeProject: CustomStringConvertible {
public var description: String {
return """
----
XcodeProjectPlugin.XcodeProject
\(displayName)
\(directory.string)
Filepaths:
\(filePaths.map { $0.string }.joined(separator: "\n"))
Targets:
\(targets.map { $0.description }.joined(separator: "\n"))
----
"""
}
}

extension XcodeProjectPlugin.XcodeTarget: CustomStringConvertible {
public var description: String {
return """
----
XcodeProjectPlugin.XcodeTarget
\(displayName)
Product
\(String(describing: product))
InputFiles:
\(inputFiles.map { "\($0.type) \($0.path.lastComponent)" }.joined(separator: "\n"))
Dependencies:
\(dependencies)
----
"""
}
}
#endif


27 changes: 26 additions & 1 deletion README.md
@@ -1,7 +1,7 @@
# SPMPlugin

[![swift-version](https://img.shields.io/badge/swift-5.6-brightgreen.svg)](https://github.com/apple/swift)
[![xcode-version](https://img.shields.io/badge/xcode-14%20beta3-brightgreen)](https://developer.apple.com/xcode/)
[![xcode-version](https://img.shields.io/badge/xcode-14%20beta4-brightgreen)](https://developer.apple.com/xcode/)

Contains a plugin conveniently called `Plug` that can be used on both Swift Package Manager targets as on
xcode project targets.
Expand All @@ -20,6 +20,31 @@ For this project output will be
- `~/DerivedData/SPMPluginXcode-<#uuid#>/SourcePackages/plugins/SPMPluginXcode.output/SPMPluginXcode/Plug/Output.swift`
- `~/DerivedData/SPMPlugin-<#uuid#>/SourcePackages/plugins/SPMPluginXcode.output/SPMPluginXcode/Plug/Output.swift`

## Found issues in xcode 14 Beta4

- The pre build command can work when you use a tool that is not build by xcode itself. When you do it like in code now with a tool that you get an error like below

```
/usr/bin/sandbox-exec -p "(version 1)
(deny default)
(import \"system.sb\")
(allow file-read*)
(allow process*)
(allow file-write*
(subpath \"/private/tmp\")
(subpath \"/private/var/folders/y4/c8rp4svn2xb2v780p6tmwvx80000gn/T\")
)
(deny file-write*
(subpath \"<#root#>/SPMPlugin/ExampleXcode/SPMPluginXcode\")
)
(allow file-write*
(subpath \"<#user#>/Library/Developer/Xcode/DerivedData/SPMPluginXcode-gekgfcqooheywrbyvaoyqkubzduv/SourcePackages/plugins/SPMPluginXcode.output/SPMPluginXcode/Plug\")
)
" "/${BUILD_DIR}/${CONFIGURATION}/PluginMain" <#user#>/Library/Developer/Xcode/DerivedData/SPMPluginXcode-gekgfcqooheywrbyvaoyqkubzduv/SourcePackages/plugins/SPMPluginXcode.output/SPMPluginXcode/Plug <#user#>/Developer/Mediahuis/DesignSystem/SPMPlugin/ExampleXcode/SPMPluginXcode/SPMPluginXcode/Input.swift <#user#>/Library/Developer/Xcode/DerivedData/SPMPluginXcode-gekgfcqooheywrbyvaoyqkubzduv/SourcePackages/plugins/SPMPluginXcode.output/SPMPluginXcode/Plug/Output.swift
The file “PluginMain” doesn’t exist.
```

## Setup

This is tested with [![xcode-version](https://img.shields.io/badge/xcode-14%20beta3-brightgreen)](https://developer.apple.com/xcode/) and might work better with
Expand Down
2 changes: 2 additions & 0 deletions Sources/PluginMain/main.swift
@@ -1,6 +1,8 @@

import Foundation

print("🔌 plug is running")

let input = URL(fileURLWithPath: ProcessInfo().arguments[1])
let output = URL(fileURLWithPath: ProcessInfo().arguments[2])

Expand Down

0 comments on commit 52b2ccf

Please sign in to comment.