Class: Luna::Binary::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/luna/binary/build.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuild

Returns a new instance of Build.



16
17
18
# File 'lib/luna/binary/build.rb', line 16

def initialize
    needPodInstall = true
end

Instance Attribute Details

#needPodInstallObject

Returns the value of attribute needPodInstall.



15
16
17
# File 'lib/luna/binary/build.rb', line 15

def needPodInstall
  @needPodInstall
end

#schemeObject

Returns the value of attribute scheme.



14
15
16
# File 'lib/luna/binary/build.rb', line 14

def scheme
  @scheme
end

#workspaceObject

Returns the value of attribute workspace.



13
14
15
# File 'lib/luna/binary/build.rb', line 13

def workspace
  @workspace
end

Instance Method Details

#binary_path_armObject



119
120
121
# File 'lib/luna/binary/build.rb', line 119

def binary_path_arm
    return Common.instance.binary_path_arm
end

#binary_path_mergedObject



115
116
117
# File 'lib/luna/binary/build.rb', line 115

def binary_path_merged
    return Common.instance.binary_path_merged
end

#binary_path_x86Object



123
124
125
# File 'lib/luna/binary/build.rb', line 123

def binary_path_x86
    return Common.instance.binary_path_x86
end

#command(c) ⇒ Object



24
25
26
# File 'lib/luna/binary/build.rb', line 24

def command(c)
    return Common.instance.command(c)
end

#createFrameworksObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/luna/binary/build.rb', line 28

def createFrameworks
    isNext = true
    if needPodInstall
        puts "强制使用源码重新pod install".yellow
        Install.new(false)
    else
        puts "跳过重新pod install的步骤".yellow
    end
    Common.instance.deleteDirectory(binary_path_arm)
    tempLunaUploaderPath = Common.instance.tempLunaUploaderPath
    isNext = command("xcodebuild -workspace #{workspace} -scheme #{scheme} -configuration Debug -derivedDataPath '#{tempLunaUploaderPath}/build/arm/temp'") if isNext == true
    isNext = command("cp -r #{tempLunaUploaderPath}/build/arm/temp/Build/Products/Debug-iphoneos #{binary_path_arm}") if isNext == true #本可以用CONFIGURATION_BUILD_DIR直接指定结果文件夹,结果经常性的编译报错
    Common.instance.deleteDirectory(binary_path_x86)
    isNext = command("xcodebuild -workspace #{workspace} -scheme #{scheme} -configuration Debug -derivedDataPath '#{tempLunaUploaderPath}/build/x86/temp' -destination 'platform=iOS Simulator,name=iPhone 11'") if isNext == true
    isNext = command("cp -r #{tempLunaUploaderPath}/build/x86/temp/Build/Products/Debug-iphonesimulator #{binary_path_x86}") if isNext == true
    mergeFrameWorks(binary_path_arm, binary_path_x86) if isNext == true
    return isNext
end

#findFramework(moduleName, binary_path) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/luna/binary/build.rb', line 105

def findFramework(moduleName, binary_path)
    pathArr = Dir.glob("#{binary_path}/**/#{moduleName.sub('-', '_')}.framework")
    if pathArr != nil
        return pathArr.first
    else
        return nil
    end
end

#lockfileObject



81
82
83
# File 'lib/luna/binary/build.rb', line 81

def lockfile
    return Common.instance.lockfile
end

#mergeFrameWork(moduleName, path1, path2) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/luna/binary/build.rb', line 90

def mergeFrameWork(moduleName, path1, path2)
    command("mkdir -p #{binary_path_merged}; cp -r #{File.dirname(path1)} #{binary_path_merged}; cp -r #{File.dirname(path2)} #{binary_path_merged}; mv #{binary_path_merged}/#{File.basename(File.dirname(path1))} #{binary_path_merged}/#{moduleName};")
    framework_name = moduleName.gsub("-", "_")

    # 修复Xcode14编译出来的framework里的header写死了x86判断的问题
    FileProcesserManager.new("#{binary_path_merged}/#{moduleName}/#{framework_name}.framework/Headers/*", 
    [
        FileProcesser.new(-> (fileContent) {
            return fileContent.sub( "#elif defined(__x86_64__) && __x86_64__", "#elif (defined(__x86_64__) && __x86_64__) || (defined(__arm64__) && __arm64__)" )
        })
    ]).process()

    return command("lipo -create #{path2}/#{framework_name} #{path1}/#{framework_name} -output #{binary_path_merged}/#{moduleName}/#{framework_name}.framework/#{framework_name}")
end

#mergeFrameWorks(binary_path_arm, binary_path_x86) ⇒ Object



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
# File 'lib/luna/binary/build.rb', line 47

def mergeFrameWorks(binary_path_arm, binary_path_x86)
    Common.instance.deleteDirectory(binary_path_merged)
    dedupingMapper = {}
    failList = []
    p lockfile.pod_names
    lockfile.pod_names.each { |i|
        item = i.split("/").first
        if dedupingMapper[item] == nil
            begin
                puts item.yellow
                armPath = findFramework(item,binary_path_arm)
                x86Path = findFramework(item,binary_path_x86)

                is_merge = mergeFrameWork(item, armPath, x86Path) if armPath != nil && x86Path != nil
                trasher_path = "#{Common.instance.tempLunaUploaderPath}/trasher"
                failList << "#{item} 存在问题,已搬到#{trasher_path}" if is_merge == false
                command("mkdir #{trasher_path}; mv #{binary_path_merged}/#{item} #{trasher_path}") if is_merge == false
                dedupingMapper[item] = item
            rescue => exception
                failList << "#{item} exception : #{exception}"
            ensure
                
            end
           
        end 
    }
    
    puts "合并后的framework的路径为:#{binary_path_merged}".green
    puts "-=-=-=-=-=-=-=-=merge 失败名单-=-=-=-=-=-=-=-=-=-=" if failList.length > 0
    failList.each { |item|
        puts item.red
    }
end

#runObject



20
21
22
# File 'lib/luna/binary/build.rb', line 20

def run 
    return createFrameworks
end

#xcodeSimulatorsObject



85
86
87
88
# File 'lib/luna/binary/build.rb', line 85

def xcodeSimulators
    # simulators = JSON.parse(%x("xcodebuild -workspace #{workspace} -scheme #{scheme} -showdestinations"))  
    
end