Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Fixtures/Resources/Moved/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "Resources",
targets: [
.target(
name: "SwiftyResource",
resources: [
.copy("foo.txt"),
]
),

.target(
name: "SeaResource",
resources: [
.copy("foo.txt"),
]
),
]
)
1 change: 1 addition & 0 deletions Fixtures/Resources/Moved/Sources/SeaResource/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
12 changes: 12 additions & 0 deletions Fixtures/Resources/Moved/Sources/SeaResource/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
NSBundle *bundle = SWIFTPM_MODULE_BUNDLE;
NSString *foo = [bundle pathForResource:@"foo" ofType:@"txt"];
NSData *data = [NSFileManager.defaultManager contentsAtPath:foo];
NSString *contents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
printf("%s", contents.UTF8String);
}
return 0;
}
1 change: 1 addition & 0 deletions Fixtures/Resources/Moved/Sources/SwiftyResource/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
7 changes: 7 additions & 0 deletions Fixtures/Resources/Moved/Sources/SwiftyResource/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

let bundle = Bundle.module

let foo = bundle.path(forResource: "foo", ofType: "txt")!
let contents = FileManager.default.contents(atPath: foo)!
print(String(data: contents, encoding: .utf8)!, terminator: "")
5 changes: 0 additions & 5 deletions Fixtures/Resources/Simple/.gitignore

This file was deleted.

40 changes: 40 additions & 0 deletions Tests/FunctionalTests/ResourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,44 @@ class ResourcesTests: XCTestCase {
""")
}
}

func testMovedBinaryResources() {
fixture(name: "Resources/Moved") { prefix in
var executables = ["SwiftyResource"]

// Objective-C module requires macOS
#if os(macOS)
executables.append("SeaResource")
#endif

let binPath = try AbsolutePath(
executeSwiftBuild(prefix, configuration: .Release, extraArgs: ["--show-bin-path"]).stdout
.trimmingCharacters(in: .whitespacesAndNewlines)
)

for execName in executables {
_ = try executeSwiftBuild(prefix, configuration: .Release, extraArgs: ["--product", execName])

try withTemporaryDirectory(prefix: execName) { tmpDirPath in
defer {
// Unblock and remove the tmp dir on deinit.
try? localFileSystem.chmod(.userWritable, path: tmpDirPath, options: [.recursive])
try? localFileSystem.removeFileTree(tmpDirPath)
}

let destBinPath = tmpDirPath.appending(component: execName)
// Move the binary
try localFileSystem.move(from: binPath.appending(component: execName), to: destBinPath)
// Move the resources
try localFileSystem
.getDirectoryContents(binPath)
.filter { $0.contains(execName) && $0.hasSuffix(".bundle") || $0.hasSuffix(".resources") }
.forEach { try localFileSystem.move(from: binPath.appending(component: $0), to: tmpDirPath.appending(component: $0)) }
// Run the binary
let output = try Process.checkNonZeroExit(args: destBinPath.pathString)
XCTAssertTrue(output.contains("foo"))
}
}
}
}
}