Top Level Namespace

Defined Under Namespace

Modules: CheckAllDepencies

Instance Method Summary collapse

Instance Method Details

#analyze_podfile_lock(podfile_lock_content) ⇒ Object

Analyzes the Podfile.lock content to extract pod dependencies



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/check_all_depencies.rb', line 4

def analyze_podfile_lock(podfile_lock_content)
  unless podfile_lock_content.is_a?(String)
    raise ArgumentError, 'podfile_lock_content must be a string.'
  end

  pods_section_match = podfile_lock_content.match(/^PODS:\n(.*?)(?=\n\n|\z)/m)
  if pods_section_match
    pods_section_content = pods_section_match[1]
    pods_lines = pods_section_content.split("\n")
    pods_lines.map(&:strip)
  else
    raise 'PODS section not found in the provided Podfile.lock content.'
  end
end

#extract_unique_dependencies(pods) ⇒ Object

Extracts unique specs from dependencies



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/check_all_depencies.rb', line 30

def extract_unique_dependencies(pods)
  unless pods.is_a?(Array)
    raise ArgumentError, 'Input must be an array.'
  end

  return [] if pods.empty?

  unique_repositories = pods.each_with_object([]) do |dependency, unique|
    repo_name = dependency.split('(').first.strip
    cleaned_repo_name = repo_name.gsub(/- /, '')
    unique << cleaned_repo_name unless unique.include?(cleaned_repo_name)
  end

  unique_repositories
end

#find_shortest_paths(paths) ⇒ Object

Finds the shortest paths for dependencies

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/check_all_depencies.rb', line 47

def find_shortest_paths(paths)
  raise ArgumentError, 'Input must be an array' unless paths.is_a?(Array)
  return [] if paths.empty?
  raise ArgumentError, 'All elements in the array must be strings' unless paths.all? { |path| path.is_a?(String) }

  shortest_paths = []
  paths.each do |path|
    is_shortest = true
    paths.each do |other_path|
      if path != other_path && other_path.start_with?(path)
        is_shortest = false
        break
      end
    end
    shortest_paths << path if is_shortest
  end
  shortest_paths
end

#generate_branch_podfile_entry(lib, subspecs, git_url, branch) ⇒ Object

Generates Podfile entry for branch dependency



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/check_all_depencies.rb', line 95

def generate_branch_podfile_entry(lib,subspecs, git_url, branch)
  sub_specs = subspecs.map { |path| path.split('/', 2).last }.uniq
  return "pod '#{lib}', :git => '#{git_url}', :branch => '#{branch}'" if sub_specs.length <= 1
  podfile_entry = "pod '#{lib}', :git => '#{git_url}', :branch => '#{branch}', :subspecs => [\n"
  sub_specs.each_with_index do |path, index|
    subspec = path.gsub("#{lib}/", '')
    podfile_entry << "  '#{subspec}'"
    podfile_entry << "," unless index == sub_specs.length - 1
    podfile_entry << "\n"
  end
  podfile_entry << "]"
  podfile_entry
end

#generate_map_branch_podfiles(lockPath, repo_configs) ⇒ Object

Generates all branch dependencies

Raises:

  • (ArgumentError)


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/check_all_depencies.rb', line 110

def generate_map_branch_podfiles(lockPath, repo_configs)
  raise ArgumentError, 'lockPath must be a string.' unless lockPath.is_a?(String)
  raise ArgumentError, 'repo_configs must be a hash.' unless repo_configs.is_a?(Hash)

  dependencies = read_local_podfile_lock(lockPath)
  unique_dependencies = extract_unique_dependencies(dependencies)
  # Throws an exception if unique_dependencies is empty
  raise 'No unique dependencies found. Please check your Podfile.lock content and repo_configs.' if unique_dependencies.empty?

  puts "====branch dependencies===="
  podfile_entrys = []
  repo_configs.each do |key, value|
    next unless value.is_a?(Hash) && value.key?("git_url") && value.key?("branch")

    git_url = value["git_url"]
    branch = value["branch"]
    repo_subspecs = generate_repo_subspecs(key, unique_dependencies)
    repo_shortest_subspecs = find_shortest_paths(repo_subspecs[key])
    # Generates Podfile entry
    podfile_entry = generate_branch_podfile_entry(key, repo_shortest_subspecs, git_url, branch)
    podfile_entrys << podfile_entry
  end
  puts podfile_entrys.join("\n")
  podfile_entrys.join("\n")
end

#generate_map_path_podfiles(lockPath, repo_configs) ⇒ Object

Generates all path dependencies

Raises:

  • (ArgumentError)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/check_all_depencies.rb', line 137

def generate_map_path_podfiles(lockPath, repo_configs)
  raise ArgumentError, 'lockPath must be a string.' unless lockPath.is_a?(String)
  raise ArgumentError, 'repo_configs must be a hash.' unless repo_configs.is_a?(Hash)

  pods = read_local_podfile_lock(lockPath)
  unique_dependencies = extract_unique_dependencies(pods)

  # Throws an exception if unique_dependencies is empty
  raise 'No unique dependencies found. Please check your Podfile.lock content and repo_configs.' if unique_dependencies.empty?

  puts "====path dependencies===="
  podfile_entrys = []
  repo_configs.each do |key, value|
    next unless value.is_a?(Hash) && value.key?("path")

    path = value["path"]
    repo_subspecs = generate_repo_subspecs(key, unique_dependencies)
    repo_shortest_subspecs = find_shortest_paths(repo_subspecs[key])
    # Generates Podfile entry
    podfile_entry = generate_path_podfile_entry(key, repo_shortest_subspecs, path)
    podfile_entrys << podfile_entry
  end
  puts podfile_entrys.join("\n")
  podfile_entrys.join("\n")
end

#generate_path_podfile_entry(lib, subspecs, base_path) ⇒ Object

Generates Podfile entry for path dependency



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/check_all_depencies.rb', line 80

def generate_path_podfile_entry(lib,subspecs, base_path)
  sub_specs = subspecs.map { |path| path.split('/', 2).last }.uniq
  return "pod '#{lib}', :path => '#{base_path}'" if sub_specs.length <= 1
  podfile_entry = "pod '#{lib}', :path => '#{base_path}', :subspecs => [\n"
  sub_specs.each_with_index do |path, index|
    subspec = path.gsub("#{lib}/", '')
    podfile_entry << "  '#{subspec}'"
    podfile_entry << "," unless index == sub_specs.length - 1
    podfile_entry << "\n"
  end
  podfile_entry << "]"
  podfile_entry
end

#generate_repo_subspecs(repo, unique_repositories) ⇒ Object

Builds all subspecs dependencies for a repo



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/check_all_depencies.rb', line 67

def generate_repo_subspecs(repo,unique_repositories)
    repo_subspecs = {}
    unique_repositories.select { |dependency| dependency.start_with?(repo) }.each do |dependency|
        if repo_subspecs.key?(repo)
          repo_subspecs[repo] << dependency
        else
          repo_subspecs[repo] = [dependency]
        end
    end
    return repo_subspecs
end

#read_local_podfile_lock(file_path) ⇒ Object

Reads the local Podfile.lock content



20
21
22
23
24
25
26
27
# File 'lib/check_all_depencies.rb', line 20

def read_local_podfile_lock(file_path)
  unless File.exist?(file_path)
    raise "File not found: #{file_path}"
  end
  
  podfile_lock_content = File.read(file_path)
  analyze_podfile_lock(podfile_lock_content)
end

#read_repo_configs(config_path) ⇒ Object

Function to read and parse the repo_configs.txt file



211
212
213
214
215
216
217
# File 'lib/check_all_depencies.rb', line 211

def read_repo_configs(config_path)
  content = File.read(config_path)
  eval(content) # Using eval to parse the Ruby hash from the file, be cautious with its use!
rescue
  puts "Failed to read or parse the repo_configs from #{config_path}"
  exit
end