From 496a7cc4b005fe980bbef3097b8ba35c73d5c223 Mon Sep 17 00:00:00 2001 From: Brandon Kase Date: Tue, 7 Nov 2017 17:01:11 -0800 Subject: [PATCH] Support paths directly to xcassets Pretend xcassets are files to allow top-level xcassets in the spec. --- .../AppIcon.appiconset/Contents.json | 5 + .../Project.xcodeproj/project.pbxproj | 6 +- .../AppIcon.appiconset/Contents.json | 98 +++++++++++++++++++ Fixtures/TestProject/spec.yml | 1 + Sources/XcodeGenKit/PBXProjGenerator.swift | 3 +- .../ProjectGeneratorTests.swift | 3 + 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 Fixtures/TestProject/StandaloneFiles/StandaloneAssets.xcassets/AppIcon.appiconset/Contents.json diff --git a/Fixtures/TestProject/App_iOS/Assets.xcassets/AppIcon.appiconset/Contents.json b/Fixtures/TestProject/App_iOS/Assets.xcassets/AppIcon.appiconset/Contents.json index 1d060ed2..d8db8d65 100644 --- a/Fixtures/TestProject/App_iOS/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Fixtures/TestProject/App_iOS/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -84,6 +84,11 @@ "idiom" : "ipad", "size" : "83.5x83.5", "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Fixtures/TestProject/Project.xcodeproj/project.pbxproj b/Fixtures/TestProject/Project.xcodeproj/project.pbxproj index 0a048bee..03460010 100644 --- a/Fixtures/TestProject/Project.xcodeproj/project.pbxproj +++ b/Fixtures/TestProject/Project.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ BF2445564001 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = VG2858723001 /* LaunchScreen.storyboard */; }; BF2513089601 /* LocalizedStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = VG3182922801 /* LocalizedStoryboard.storyboard */; }; BF2535278401 = {isa = PBXBuildFile; fileRef = FR4387045301 /* Framework_watchOS.framework */; }; + BF2754797601 /* StandaloneAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FR5557707101 /* StandaloneAssets.xcassets */; }; BF3008399601 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR3032072503 /* Alamofire.framework */; }; BF3154421201 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FR5980633301 /* Assets.xcassets */; settings = {COMPILER_FLAGS = "-Werror"; }; }; BF3314441201 = {isa = PBXBuildFile; fileRef = FR5251191201 /* Framework_macOS.framework */; }; @@ -86,6 +87,7 @@ FR4722960401 /* Framework_iOS.framework */ = {isa = PBXFileReference; explicitFileType = framework; includeInIndex = 0; lastKnownFileType = wrapper.framework; path = Framework_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; FR4822987701 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LocalizedStoryboard.storyboard; sourceTree = ""; }; FR5251191201 /* Framework_macOS.framework */ = {isa = PBXFileReference; explicitFileType = framework; includeInIndex = 0; lastKnownFileType = wrapper.framework; path = Framework_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + FR5557707101 /* StandaloneAssets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = StandaloneAssets.xcassets; sourceTree = ""; }; FR5980633301 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; FR6218091901 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; FR6334256101 /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = config.xcconfig; sourceTree = ""; }; @@ -236,6 +238,7 @@ G66512504301 /* StandaloneFiles */ = { isa = PBXGroup; children = ( + FR5557707101 /* StandaloneAssets.xcassets */, FR2554453101 /* Standalone.swift */, ); name = StandaloneFiles; @@ -293,8 +296,8 @@ children = ( G83406189501 /* Configs */, G32346300301 /* FileGroup */, - G82523211001 /* App_iOS */, G66512504301 /* StandaloneFiles */, + G82523211001 /* App_iOS */, G78312289901 /* App_iOS_Tests */, G46615002701 /* Framework */, G86202385201 /* Products */, @@ -526,6 +529,7 @@ BF4414242001 /* Localizable.stringsdict in Resources */, BF2513089601 /* LocalizedStoryboard.storyboard in Resources */, BF2250910101 /* Main.storyboard in Resources */, + BF2754797601 /* StandaloneAssets.xcassets in Resources */, ); }; /* End PBXResourcesBuildPhase section */ diff --git a/Fixtures/TestProject/StandaloneFiles/StandaloneAssets.xcassets/AppIcon.appiconset/Contents.json b/Fixtures/TestProject/StandaloneFiles/StandaloneAssets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..d8db8d65 --- /dev/null +++ b/Fixtures/TestProject/StandaloneFiles/StandaloneAssets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Fixtures/TestProject/spec.yml b/Fixtures/TestProject/spec.yml index b4857cdd..eedd03d0 100644 --- a/Fixtures/TestProject/spec.yml +++ b/Fixtures/TestProject/spec.yml @@ -12,6 +12,7 @@ targets: type: application platform: iOS sources: + - StandaloneFiles/StandaloneAssets.xcassets - path: App_iOS compilerFlags: - "-Werror" diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 9967a1df..5b803420 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -563,7 +563,8 @@ public class PBXProjGenerator { func getSources(sourceMetadata source: Source, path: Path, depth: Int = 0) throws -> (sourceFiles: [SourceFile], groups: [PBXGroup]) { // if we have a file, move it to children and use the parent as the path - let (children, path) = path.isFile ? + // pretend xcassets are files + let (children, path) = path.isFile || path.extension == "xcassets" ? ([path], path.parent()) : (try path.children().sorted(), path) diff --git a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift index 582d7498..d8414a9d 100644 --- a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift @@ -304,6 +304,7 @@ func projectGeneratorTests() { Sources: A: - a.swift + - Assets.xcassets - B: - b.swift - c.jpg @@ -313,6 +314,7 @@ func projectGeneratorTests() { target.sources = [ "Sources/A/a.swift", "Sources/A/B/b.swift", + "Sources/A/Assets.xcassets", "Sources/A/B/c.jpg", ] spec.targets = [target] @@ -321,6 +323,7 @@ func projectGeneratorTests() { try project.expectFile(paths: ["Sources/A", "a.swift"], names: ["A", "a.swift"], buildPhase: .sources) try project.expectFile(paths: ["Sources/A/B", "b.swift"], names: ["B", "b.swift"], buildPhase: .sources) try project.expectFile(paths: ["Sources/A/B", "c.jpg"], names: ["B", "c.jpg"], buildPhase: .resources) + try project.expectFile(paths: ["Sources/A", "Assets.xcassets"], names: ["A", "Assets.xcassets"], buildPhase: .resources) } } }