Class: CBin::Build::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-tdf-bin/helpers/build_utils.rb

Class Method Summary collapse

Class Method Details

.is_framework(spec) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/cocoapods-tdf-bin/helpers/build_utils.rb', line 9

def Utils.is_framework(spec)
  # 目前全部打包成 静态 framework
  return true
  # if Utils.uses_frameworks?
  #   return true
  # end
  #
  # return Utils.is_swift_module(spec)
end

.is_swift_module(spec) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cocoapods-tdf-bin/helpers/build_utils.rb', line 56

def Utils.is_swift_module(spec)

  is_framework = false
  dir = File.join(CBin::Config::Builder.instance.gen_dir, CBin::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(CBin::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
    unless is_framework
      is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
    end
  end

  is_framework
end

.spec_header_dir(spec) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cocoapods-tdf-bin/helpers/build_utils.rb', line 19

def Utils.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
  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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cocoapods-tdf-bin/helpers/build_utils.rb', line 39

def Utils.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)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cocoapods-tdf-bin/helpers/build_utils.rb', line 79

def Utils.uses_frameworks?
  uses_frameworks = false
  # podfile_path = Pod::Config.instance.installation_root.to_s + "/Example/podfile"
  # begin
  #   podfile = Pod::Podfile.from_file(podfile_path)
  # rescue
  #   podfile = Pod::Config.instance.podfile
  # end
  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

  return uses_frameworks
end