Prevent embedding static frameworks (#490)

Resolves https://github.com/tuist/tuist/issues/454

- All `FrameworkNodes` (i.e. prebuilt frameworks) were being embedded regardless of their linkage
- This check was redundant as there was a more general check for `PrecompiledNode` which happens to be the super class of `FrameworkNode` which took into account the framework linkage
- To resolve this issue it was suffice to remove the redundant check

Test Plan:

- Generate `fixtures/ios_app_with_static_frameworks` via running `tuist generate`
- Verify the generated project doesn't embed `PrebuiltStaticFramework`
- Verify the generated project builds successfully
This commit is contained in:
Kas 2019-08-30 11:11:19 +01:00 committed by GitHub
parent bc1fb58380
commit c778fedc52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 341 additions and 25 deletions

View File

@ -6,6 +6,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
### Fixed
- Transitively link static dependency's dynamic dependencies correctly https://github.com/tuist/tuist/pull/484 by @adamkhazi
- Prevent embedding static frameworks https://github.com/tuist/tuist/pull/490 by @kwridan
## 0.17.0

View File

@ -309,15 +309,6 @@ class Graph: Graphing {
references.append(contentsOf: otherTargetFrameworks)
/// Pre-built frameworks
let transitiveFrameworks = findAll(targetNode: targetNode)
.lazy
.filter(FrameworkNode.self)
.map(\.path)
.map(DependencyReference.absolute)
references.append(contentsOf: transitiveFrameworks)
return Set(references).sorted()
}
@ -424,10 +415,8 @@ extension Graph {
visited.insert(node)
// swiftlint:disable:next force_cast
if node != targetNode, node is T, test(node as! T) {
// swiftlint:disable:next force_cast
references.insert(node as! T)
if node != targetNode, let matchingNode = node as? T, test(matchingNode) {
references.insert(matchingNode)
}
if node != targetNode, let node = node as? T, skip(node) {

View File

@ -483,6 +483,35 @@ final class GraphTests: XCTestCase {
])
}
func test_embeddableFrameworks_when_precompiledStaticFramework() throws {
// Given
let target = Target.test(name: "Main")
let project = Project.test(targets: [target])
let frameworkNode = FrameworkNode(path: "/test/StaticFramework.framework")
let targetNode = TargetNode(
project: project,
target: target,
dependencies: [frameworkNode]
)
let cache = GraphLoaderCache()
cache.add(targetNode: targetNode)
let graph = Graph.test(cache: cache)
system.succeedCommand("/usr/bin/file", "/test/StaticFramework.framework/StaticFramework",
output: "current ar archive random library")
// When
let result = try graph.embeddableFrameworks(
path: project.path,
name: target.name,
system: system
)
// Then
XCTAssertTrue(result.isEmpty)
}
func test_embeddableFrameworks_ordered() throws {
// Given
let dependencyNames = (0 ..< 10).shuffled().map { "Dependency\($0)" }

View File

@ -160,6 +160,7 @@ Workspace:
- App:
- MainApp (iOS app)
- MainAppTests (iOS unit tests)
- Modules
- A:
- A (static framework iOS)
- ATests (iOS unit tests)
@ -173,14 +174,24 @@ Workspace:
- D (dynamic framework iOS)
```
A standalone `Prebuilt` project is used to generate a prebuilt static framework:
```
- Prebuilt
- PrebuiltStaticFramework (static framework iOS)
```
Dependencies:
- App -> A
- App -> C
- App -> PrebuiltStaticFramework
- A -> B
- A -> C
- C -> D
Note: to re-create `PrebuiltStaticFramework.framework` run `fixtures/ios_app_with_static_frameworks/Prebuilt//build.sh`
## ios_app_with_tests
Simple app with tests.

View File

@ -0,0 +1,24 @@
<?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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright Tuist©. All rights reserved.</string>
</dict>
</plist>

View File

@ -0,0 +1,14 @@
import ProjectDescription
let project = Project(
name: "Prebuilt",
targets: [
Target(name: "PrebuiltStaticFramework",
platform: .iOS,
product: .staticFramework,
bundleId: "io.tuist.PrebuiltStaticFramework",
infoPlist: "Config/Info.plist",
sources: "Sources/**",
dependencies: [])
]
)

View File

@ -0,0 +1,9 @@
import Foundation
public class StaticFrameworkClass {
public init() {}
public func hello() -> String {
return "StaticFrameworkClass.hello()"
}
}

View File

@ -0,0 +1,41 @@
#!/bin/sh
tuist generate
WORKSPACE_NAME="Prebuilt"
FRAMEWORK_NAME="PrebuiltStaticFramework"
TEMP_DIR="/tmp/tuist-$FRAMEWORK_NAME-fixture"
IPHONE_SIM_DIR="$TEMP_DIR/Build/Products/Debug-iphoneos"
IPHONE_OS_DIR="$TEMP_DIR/Build/Products/Debug-iphonesimulator"
mkdir -p $TEMP_DIR
xcrun xcodebuild build -scheme "$FRAMEWORK_NAME" -workspace "$WORKSPACE_NAME.xcworkspace" -sdk iphoneos -destination "generic/platform=iOS" -derivedDataPath $TEMP_DIR
xcrun xcodebuild build -scheme "$FRAMEWORK_NAME" -workspace "$WORKSPACE_NAME.xcworkspace" -sdk iphonesimulator -derivedDataPath $TEMP_DIR
mkdir -p "prebuilt/$FRAMEWORK_NAME.framework"
lipo -create \
"$IPHONE_OS_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME" \
"$IPHONE_SIM_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME" \
-output "$(pwd)/prebuilt/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME"
cp \
"$IPHONE_OS_DIR/$FRAMEWORK_NAME.framework/Info.plist" \
"$(pwd)/prebuilt/$FRAMEWORK_NAME.framework/Info.plist"
mkdir -p "prebuilt/$FRAMEWORK_NAME.framework/Headers"
cp -r \
"$IPHONE_OS_DIR/$FRAMEWORK_NAME.framework/Headers/"* \
"$(pwd)/prebuilt/$FRAMEWORK_NAME.framework/Headers/"
mkdir -p "prebuilt/$FRAMEWORK_NAME.framework/Modules"
cp \
"$IPHONE_OS_DIR/$FRAMEWORK_NAME.framework/Modules/module.modulemap" \
"$(pwd)/prebuilt/$FRAMEWORK_NAME.framework/Modules/module.modulemap"
mkdir -p "prebuilt/$FRAMEWORK_NAME.framework/Modules/$FRAMEWORK_NAME.swiftmodule"
cp -r \
"$IPHONE_OS_DIR/$FRAMEWORK_NAME.framework/Modules/$FRAMEWORK_NAME.swiftmodule/"* \
"$IPHONE_SIM_DIR/$FRAMEWORK_NAME.framework/Modules/$FRAMEWORK_NAME.swiftmodule/"* \
"$(pwd)/prebuilt/$FRAMEWORK_NAME.framework/Modules/$FRAMEWORK_NAME.swiftmodule/"

View File

@ -0,0 +1,189 @@
// Generated by Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgcc-compat"
#if !defined(__has_include)
# define __has_include(x) 0
#endif
#if !defined(__has_attribute)
# define __has_attribute(x) 0
#endif
#if !defined(__has_feature)
# define __has_feature(x) 0
#endif
#if !defined(__has_warning)
# define __has_warning(x) 0
#endif
#if __has_include(<swift/objc-prologue.h>)
# include <swift/objc-prologue.h>
#endif
#pragma clang diagnostic ignored "-Wauto-import"
#include <Foundation/Foundation.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#if !defined(SWIFT_TYPEDEFS)
# define SWIFT_TYPEDEFS 1
# if __has_include(<uchar.h>)
# include <uchar.h>
# elif !defined(__cplusplus)
typedef uint_least16_t char16_t;
typedef uint_least32_t char32_t;
# endif
typedef float swift_float2 __attribute__((__ext_vector_type__(2)));
typedef float swift_float3 __attribute__((__ext_vector_type__(3)));
typedef float swift_float4 __attribute__((__ext_vector_type__(4)));
typedef double swift_double2 __attribute__((__ext_vector_type__(2)));
typedef double swift_double3 __attribute__((__ext_vector_type__(3)));
typedef double swift_double4 __attribute__((__ext_vector_type__(4)));
typedef int swift_int2 __attribute__((__ext_vector_type__(2)));
typedef int swift_int3 __attribute__((__ext_vector_type__(3)));
typedef int swift_int4 __attribute__((__ext_vector_type__(4)));
typedef unsigned int swift_uint2 __attribute__((__ext_vector_type__(2)));
typedef unsigned int swift_uint3 __attribute__((__ext_vector_type__(3)));
typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
#endif
#if !defined(SWIFT_PASTE)
# define SWIFT_PASTE_HELPER(x, y) x##y
# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y)
#endif
#if !defined(SWIFT_METATYPE)
# define SWIFT_METATYPE(X) Class
#endif
#if !defined(SWIFT_CLASS_PROPERTY)
# if __has_feature(objc_class_property)
# define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__
# else
# define SWIFT_CLASS_PROPERTY(...)
# endif
#endif
#if __has_attribute(objc_runtime_name)
# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X)))
#else
# define SWIFT_RUNTIME_NAME(X)
#endif
#if __has_attribute(swift_name)
# define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X)))
#else
# define SWIFT_COMPILE_NAME(X)
#endif
#if __has_attribute(objc_method_family)
# define SWIFT_METHOD_FAMILY(X) __attribute__((objc_method_family(X)))
#else
# define SWIFT_METHOD_FAMILY(X)
#endif
#if __has_attribute(noescape)
# define SWIFT_NOESCAPE __attribute__((noescape))
#else
# define SWIFT_NOESCAPE
#endif
#if __has_attribute(warn_unused_result)
# define SWIFT_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
# define SWIFT_WARN_UNUSED_RESULT
#endif
#if __has_attribute(noreturn)
# define SWIFT_NORETURN __attribute__((noreturn))
#else
# define SWIFT_NORETURN
#endif
#if !defined(SWIFT_CLASS_EXTRA)
# define SWIFT_CLASS_EXTRA
#endif
#if !defined(SWIFT_PROTOCOL_EXTRA)
# define SWIFT_PROTOCOL_EXTRA
#endif
#if !defined(SWIFT_ENUM_EXTRA)
# define SWIFT_ENUM_EXTRA
#endif
#if !defined(SWIFT_CLASS)
# if __has_attribute(objc_subclassing_restricted)
# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA
# define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
# else
# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
# define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
# endif
#endif
#if !defined(SWIFT_PROTOCOL)
# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
#endif
#if !defined(SWIFT_EXTENSION)
# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__)
#endif
#if !defined(OBJC_DESIGNATED_INITIALIZER)
# if __has_attribute(objc_designated_initializer)
# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
# else
# define OBJC_DESIGNATED_INITIALIZER
# endif
#endif
#if !defined(SWIFT_ENUM_ATTR)
# if defined(__has_attribute) && __has_attribute(enum_extensibility)
# define SWIFT_ENUM_ATTR(_extensibility) __attribute__((enum_extensibility(_extensibility)))
# else
# define SWIFT_ENUM_ATTR(_extensibility)
# endif
#endif
#if !defined(SWIFT_ENUM)
# define SWIFT_ENUM(_type, _name, _extensibility) enum _name : _type _name; enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type
# if __has_feature(generalized_swift_name)
# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type
# else
# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) SWIFT_ENUM(_type, _name, _extensibility)
# endif
#endif
#if !defined(SWIFT_UNAVAILABLE)
# define SWIFT_UNAVAILABLE __attribute__((unavailable))
#endif
#if !defined(SWIFT_UNAVAILABLE_MSG)
# define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg)))
#endif
#if !defined(SWIFT_AVAILABILITY)
# define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__)))
#endif
#if !defined(SWIFT_DEPRECATED)
# define SWIFT_DEPRECATED __attribute__((deprecated))
#endif
#if !defined(SWIFT_DEPRECATED_MSG)
# define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__)))
#endif
#if __has_feature(attribute_diagnose_if_objc)
# define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, Msg, "warning")))
#else
# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg)
#endif
#if __has_feature(modules)
#if __has_warning("-Watimport-in-framework-header")
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
#endif
#endif
#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"
#if __has_warning("-Wpragma-clang-attribute")
# pragma clang diagnostic ignored "-Wpragma-clang-attribute"
#endif
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wnullability"
#if __has_attribute(external_source_symbol)
# pragma push_macro("any")
# undef any
# pragma clang attribute push(__attribute__((external_source_symbol(language="Swift", defined_in="PrebuiltStaticFramework",generated_declaration))), apply_to=any(function,enum,objc_interface,objc_category,objc_protocol))
# pragma pop_macro("any")
#endif
#if __has_attribute(external_source_symbol)
# pragma clang attribute pop
#endif
#pragma clang diagnostic pop

View File

@ -0,0 +1,4 @@
framework module PrebuiltStaticFramework {
header "PrebuiltStaticFramework-Swift.h"
requires objc
}

View File

@ -1,6 +1,6 @@
import ProjectDescription
let project = Project(name: "iOSAppWithTransistiveStaticFrameworks",
let project = Project(name: "App",
targets: [
Target(name: "App",
platform: .iOS,
@ -11,6 +11,7 @@ let project = Project(name: "iOSAppWithTransistiveStaticFrameworks",
dependencies: [
.project(target: "A", path: "Modules/A"),
.project(target: "C", path: "Modules/C"),
.framework(path: "Prebuilt/prebuilt/PrebuiltStaticFramework.framework")
]),
Target(name: "AppTests",
platform: .iOS,

View File

@ -1,6 +1,7 @@
import A
import C
import UIKit
import PrebuiltStaticFramework
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
@ -16,6 +17,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
A.printFromA()
C.printFromC()
let staticFrameworkClass = StaticFrameworkClass()
print(staticFrameworkClass.hello())
return true
}
}