Class: Fastlane::Helper::ValidateXcframeworkHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/mobile_tools/helper/validate_xcframework_helper.rb

Class Method Summary collapse

Class Method Details

.build_xcode_project(xcodeproj_path) ⇒ Object



137
138
139
# File 'lib/fastlane/plugin/mobile_tools/helper/validate_xcframework_helper.rb', line 137

def self.build_xcode_project(xcodeproj_path)
  Actions.sh("xcodebuild -project #{xcodeproj_path} -scheme SampleApp -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' build")
end

.create_project_yml(framework_paths, sample_app_path) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/fastlane/plugin/mobile_tools/helper/validate_xcframework_helper.rb', line 83

def self.create_project_yml(framework_paths, sample_app_path)
  project_yml_content = {
    "name" => "SampleApp",
    "options" => {
      "bundleIdPrefix" => "com.intuit"
    },
    "targets" => {
      "SampleApp" => {
        "type" => "application",
        "platform" => "iOS",
        "deploymentTarget" => "13.0",
        "sources" => ["Sources"],
        "resources" => framework_paths.map { |path| "./#{File.basename(path)}" },
        "dependencies" => framework_paths.map { |path| { "framework" => "./#{File.basename(path)}", "embed" => true } },
        "settings" => {
          "base" => {
            "DEVELOPMENT_TEAM" => "F6DWWXWEX6",
            "GENERATE_INFOPLIST_FILE" => "YES",
            "CODE_SIGN_IDENTITY" => "iPhone Developer",
            "LD_RUNPATH_SEARCH_PATHS" => ["$(inherited)", "@executable_path/Frameworks"],
            "SDKROOT" => "iphoneos",
            "TARGETED_DEVICE_FAMILY" => "1,2",
            "VERSIONING_SYSTEM" => "apple-generic",
            "CURRENT_PROJECT_VERSION" => "1",
            "MARKETING_VERSION" => "1.0",
            "CFBundleVersion" => "$(CURRENT_PROJECT_VERSION)",
            "CFBundleShortVersionString" => "$(MARKETING_VERSION)"
          },
          "configs" => {
            "debug" => {
              "CODE_SIGN_STYLE" => "Manual",
              "PROVISIONING_PROFILE_SPECIFIER" => "com.intuit.*.InHouse",
              "CODE_SIGN_IDENTITY" => "iPhone Distribution: Intuit Inc.(Ent)"
            },
            "release" => {
              "CODE_SIGN_STYLE" => "Manual",
              "PROVISIONING_PROFILE_SPECIFIER" => "com.intuit.*.InHouse",
              "CODE_SIGN_IDENTITY" => "iPhone Distribution: Intuit Inc.(Ent)"
            }
          }
        }
      }
    }
  }
  
  project_yml_path = File.join(sample_app_path, 'project.yml')
  File.write(project_yml_path, project_yml_content.to_yaml)
  project_yml_path
end

.create_sample_app(framework_paths) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/mobile_tools/helper/validate_xcframework_helper.rb', line 4

def self.create_sample_app(framework_paths)
  tmpdir = Dir.mktmpdir
  sample_app_path = File.join(tmpdir, 'SampleApp')
  Dir.mkdir(sample_app_path)
  Dir.chdir(sample_app_path) do
    system("swift package init --type executable")
    tests_path = File.join(sample_app_path, 'Tests', 'SampleAppTests')
    FileUtils.mkdir_p(tests_path)
  
    # Copy frameworks to the temporary sample app folder
    framework_paths.each do |path|
      FileUtils.cp_r(path, sample_app_path)
    end
  
    package_swift_path = File.join(sample_app_path, 'Package.swift')
    # Extract names from framework paths and ensure paths are relative
    binary_targets = framework_paths.map do |path|
      name = File.basename(path, ".framework")
      relative_path = "./" + File.basename(path)
      ".binaryTarget(name: \"#{name}\", path: \"#{relative_path}\")"
    end.join(",\n        ")
  
    # Create dependencies for SampleApp target
    dependencies = framework_paths.map do |path|
      name = File.basename(path, ".framework")
      "\"#{name}\""
    end.join(", ")
  
    resources = framework_paths.map do |path|
      name = File.basename(path, ".framework")
      ".copy(\"./#{name}.framework\")"
    end.join(",\n                      ")
  
    # Add all framework names to the products target
    product_targets = framework_paths.map do |path|
      name = File.basename(path, ".framework")
      "\"#{name}\""
    end.join(", ")
  
    package_swift_content = "    // swift-tools-version:5.3\n    import PackageDescription\n  \n    let package = Package(\n        name: \"SampleApp\",\n        platforms: [\n            .macOS(.v10_15),\n            .iOS(.v13)\n        ],\n        products: [\n            .executable(name: \"SampleApp\", targets: [\"SampleApp\", \#{product_targets}]),\n        ],\n        dependencies: [\n            // Add dependencies here\n        ],\n        targets: [\n            \#{binary_targets},\n            .target(\n                name: \"SampleApp\",\n                dependencies: [\#{dependencies}],\n                path: \"Sources\",\n                resources: [\n                    \#{resources}\n                ]\n            ),\n            .testTarget(\n                name: \"SampleAppTests\",\n                dependencies: [\"SampleApp\"],\n                path: \"Tests/SampleAppTests\"\n            ),\n        ]\n    )\n    SWIFT\n  \n    File.write(package_swift_path, package_swift_content.strip)\n  end\n  sample_app_path\nend\n"

.generate_xcode_project(project_yml_path) ⇒ Object



133
134
135
# File 'lib/fastlane/plugin/mobile_tools/helper/validate_xcframework_helper.rb', line 133

def self.generate_xcode_project(project_yml_path)
  Actions.sh("xcodegen generate --spec #{project_yml_path}")
end