Skip to content

Commit

Permalink
Build and commit a copy of lessc so we can do archive builds again (#…
Browse files Browse the repository at this point in the history
…1184)

Apparently Xcode doesn't know how to build and use executables for build plugins when doing an archive?
  • Loading branch information
nolanw authored Mar 3, 2024
1 parent bc7b6d9 commit 38e8b4d
Show file tree
Hide file tree
Showing 7 changed files with 11,585 additions and 14 deletions.
16 changes: 9 additions & 7 deletions LessStylesheet/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ import PackageDescription
let package = Package(
name: "LessStylesheet",
products: [
.executable(name: "lessc", targets: ["lessc"]),
.plugin(name: "LessStylesheet", targets: ["LessStylesheet"]),
],
targets: [
.plugin(
name: "LessStylesheet",
capability: .buildTool(),
dependencies: [
"lessc",
]
),
.executableTarget(
name: "lessc",
resources: [
.copy("less.js"),
]
),
.plugin(
name: "LessStylesheet",
capability: .buildTool(),
dependencies: [
// No point; doesn't work in archive builds. See read me for more info.
// "lessc",
]
),
]
)
11 changes: 7 additions & 4 deletions LessStylesheet/Plugins/LessStylesheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ struct LessStylesheet {
func createBuildCommands(
sourceFiles: FileList,
workDirectory: Path,
with tool: PluginContext.Tool
with toolPath: Path
) -> [Command] {
let importables = findImportables(sourceFiles)
let includePaths = findIncludePaths(importables)
let outputDirectory = workDirectory.appending(subpath: "LessStylesheet/")
return Array(sourceFiles
.lazy.map(\.path)
.filter { $0.isLessFile && !$0.isImportable }
.map { createBuildCommand(for: $0, in: outputDirectory, with: tool.path, include: includePaths, otherSources: importables) }
.map { createBuildCommand(for: $0, in: outputDirectory, with: toolPath, include: includePaths, otherSources: importables) }
)
}

Expand Down Expand Up @@ -74,7 +74,7 @@ extension LessStylesheet: BuildToolPlugin {
target: Target
) async throws -> [Command] {
guard let sourceFiles = target.sourceModule?.sourceFiles else { return [] }
let lessc = try context.tool(named: "lessc")
let lessc = context.package.directory.removingLastComponent().appending(subpath: prebuiltSubpath)
return createBuildCommands(sourceFiles: sourceFiles, workDirectory: context.pluginWorkDirectory, with: lessc)
}
}
Expand All @@ -87,9 +87,12 @@ extension LessStylesheet: XcodeBuildToolPlugin {
context: XcodePluginContext,
target: XcodeTarget
) throws -> [Command] {
let lessc = try context.tool(named: "lessc")
let lessc = context.xcodeProject.directory.appending(subpath: prebuiltSubpath)
return createBuildCommands(sourceFiles: target.inputFiles, workDirectory: context.pluginWorkDirectory, with: lessc)
}
}

#endif

/// See read me for an explanation.
let prebuiltSubpath = "LessStylesheet/Prebuilt/lessc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>23D60</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>LessStylesheet_lessc</string>
<key>CFBundleIdentifier</key>
<string>LessStylesheet.lessc.resources</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>LessStylesheet_lessc</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string></string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>14.2</string>
<key>DTSDKBuild</key>
<string>23C53</string>
<key>DTSDKName</key>
<string>macosx14.2</string>
<key>DTXcode</key>
<string>1520</string>
<key>DTXcodeBuild</key>
<string>15C500b</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
</dict>
</plist>
Loading

0 comments on commit 38e8b4d

Please sign in to comment.