Class: Ocean::Build::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/swordfish/helpers/build_utils.rb

Class Method Summary collapse

Class Method Details

.is_framework(spec) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/swordfish/helpers/build_utils.rb', line 8

def self.is_framework(spec)
  if Utils.uses_frameworks?
    return true
  end

  Utils.is_swift_module(spec)
end

.is_swift_module(spec) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/swordfish/helpers/build_utils.rb', line 54

def self.is_swift_module(spec)

  is_framework = false
  dir = File.join(Ocean::Config::Builder.instance.gen_dir, Ocean::Config::Builder.instance.target_name)
  #auto 走这里
  if File.exist?(dir)
    Dir.chdir(dir) do
      spec_module_dir = Utils.spec_module_dir(spec)
      return false unless File.exist?(spec_module_dir)
      is_framework = File.exist?(File.join(spec_module_dir, "#{spec.name}-umbrella.h"))
    end
  end

  if $ARGV[1] == "local"
    is_framework = File.exist?(File.join(Ocean::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
    unless is_framework
      is_framework = File.exist?(File.join(Ocean::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
    end
  end

  is_framework
end

.spec_header_dir(spec) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/swordfish/helpers/build_utils.rb', line 16

def self.spec_header_dir(spec)

  header_dir = "./Headers/Public/#{spec.name}"
  header_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(header_dir)

  unless File.exist?(header_dir)
    # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
    module_name = spec.name.gsub("-", "_")
    header_dir = "./Pods/Headers/Public/#{module_name}"
  end

  # 暂时只支持:ios
  # 这段代码导致umbrella.h无法被copy到framework
  # consumer = Pod::Specification::Consumer.new(spec, :ios)
  # unless consumer.header_dir.nil?
  #   header_dir = File.join(header_dir, consumer.header_dir)
  # end

  header_dir
end

.spec_module_dir(spec) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/swordfish/helpers/build_utils.rb', line 37

def self.spec_module_dir(spec)
  if spec.module_name.nil?
    module_dir = "./Headers/Public/#{spec.name}"
    module_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(module_dir)
    unless File.exist?(module_dir)
      # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
      module_name = spec.name.gsub("-", "_")
      module_dir = "./Pods/Headers/Public/#{module_name}"
    end
  else
    module_dir = "./Headers/Public/#{spec.module_name}"
    module_dir = "./Pods/Headers/Public/#{spec.module_name}" unless File.exist?(module_dir)
  end

  module_dir
end

.uses_frameworks?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/swordfish/helpers/build_utils.rb', line 77

def self.uses_frameworks?
  uses_frameworks = false
  Pod::Config.instance.podfile.target_definitions.each do |key,value|
    if key != "Pods"
      uses_frameworks = value.uses_frameworks?
      if uses_frameworks
        break ;
      end
    end
  end

  uses_frameworks
end