carthage_remote_cache 0.0.8 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/version_file.rb CHANGED
@@ -1,13 +1,14 @@
1
- require 'json'
2
- require 'fileutils'
1
+ require "json"
2
+ require "fileutils"
3
3
 
4
4
  # .version file representation, see Carthage documentation on them:
5
5
  # https://github.com/Carthage/Carthage/blob/master/Documentation/VersionFile.md
6
6
  class VersionFile
7
- attr_reader :path, :version, :frameworks_by_platform
7
+ attr_reader :path, :platforms, :json, :version, :frameworks_by_platform
8
8
 
9
- def initialize(path)
9
+ def initialize(path, platforms = PLATFORMS)
10
10
  @path = path
11
+ @platforms = platforms
11
12
  parse
12
13
  end
13
14
 
@@ -21,7 +22,7 @@ class VersionFile
21
22
  def platforms_by_framework
22
23
  result = Hash.new { |h, k| h[k] = [] }
23
24
  for framework_name in framework_names
24
- @frameworks_by_platform.each do |platform, framework_names_in_platform|
25
+ framework_names_by_platform.each do |platform, framework_names_in_platform|
25
26
  if framework_names_in_platform.include?(framework_name)
26
27
  result[framework_name] << platform
27
28
  end
@@ -30,14 +31,18 @@ class VersionFile
30
31
  result
31
32
  end
32
33
 
34
+ def framework_names_by_platform
35
+ @frameworks_by_platform.map { |platform, framework| [platform, framework.map { |f| f.name }] }.to_h
36
+ end
37
+
33
38
  # Unique array of framework names.
34
39
  def framework_names
35
- @frameworks_by_platform.values.flatten.uniq.sort
40
+ framework_names_by_platform.values.flatten.uniq.sort
36
41
  end
37
42
 
38
43
  # Total number of frameworks accross all platforms.
39
44
  def number_of_frameworks
40
- @frameworks_by_platform.values.flatten.count
45
+ framework_names_by_platform.values.flatten.count
41
46
  end
42
47
 
43
48
  def move_to_build_dir
@@ -55,7 +60,7 @@ class VersionFile
55
60
  if other_version_file.nil?
56
61
  false
57
62
  else
58
- FileUtils.compare_file(@path, other_version_file.path)
63
+ @json == other_version_file.json
59
64
  end
60
65
  end
61
66
 
@@ -64,25 +69,66 @@ class VersionFile
64
69
  def parse
65
70
  raise VersionFileDoesNotExistError.new, "File #{path} doesn't exist, has carthage been bootstrapped?" unless File.exist?(@path)
66
71
 
72
+ @json = read_json
73
+
74
+ @version = @json["commitish"]
75
+ raise AppError.new, "Version is missing in #{@path}:\n\n#{@json}" if @version.nil? || @version.empty?
76
+
77
+ @frameworks_by_platform = PLATFORMS.to_h { |platform| [platform, parse_platform(platform)] }
78
+ end
79
+
80
+ # Reads json from `@path` and cleans up entries, tha are not defined in `@platforms`.
81
+ def read_json
67
82
  file = File.read(@path)
68
83
  json = JSON.parse(file)
84
+ stripped_json = strip_platforms(json)
85
+ stripped_json
86
+ end
69
87
 
70
- @version = json['commitish']
71
- raise AppError.new, "Version is missing in #{@path}" if @version.nil? || @version.empty?
72
-
73
- @frameworks_by_platform = {
74
- :iOS => parse_platform_array(json['iOS']),
75
- :macOS => parse_platform_array(json['Mac']),
76
- :tvOS => parse_platform_array(json['tvOS']),
77
- :watchOS => parse_platform_array(json['watchOS']),
78
- }
88
+ def strip_platforms(json)
89
+ for platform in PLATFORMS
90
+ if !@platforms.include?(platform)
91
+ json[platform_to_carthage_dir_string(platform)] = []
92
+ end
93
+ end
94
+ json
79
95
  end
80
96
 
81
- def parse_platform_array(array)
82
- if array.kind_of?(Array)
83
- array.map { |entry| entry['name'] }
97
+ def parse_platform(platform)
98
+ carthage_platform_name = platform_to_carthage_dir_string(platform)
99
+ array = @json[carthage_platform_name]
100
+ if array.kind_of?(Array) and array.count > 0
101
+ if array.first["linking"]
102
+ parse_frameworks(array)
103
+ elsif array.first["container"]
104
+ parse_xcframeworks(array)
105
+ else
106
+ raise AppError.new "Failed to parse framework #{json}"
107
+ end
84
108
  else
85
109
  []
86
110
  end
87
111
  end
112
+
113
+ def parse_frameworks(array)
114
+ array.map { |json| Framework.parse(json) }
115
+ end
116
+
117
+ def parse_xcframeworks(array)
118
+ # Parse the array of XCFrameworks
119
+ xcframeworks = array.map { |json| XCFramework.parse(json) }
120
+
121
+ # Merge entries with same name, but different identifiers into one.
122
+ by_name = xcframeworks.reduce({}) do |hash, xcframework|
123
+ if found = hash[xcframework.name]
124
+ hash[found.name] = found.new_xcframework_by_adding_identifiers(xcframework.identifiers)
125
+ else
126
+ hash[xcframework.name] = xcframework
127
+ end
128
+ hash
129
+ end
130
+
131
+ # Turn back into a simple array
132
+ by_name.values
133
+ end
88
134
  end
@@ -0,0 +1,29 @@
1
+ # Example data:
2
+ # - "name" : "GoogleSignIn",
3
+ # - "container" : "GoogleSignIn.xcframework",
4
+ # - "identifiers" : ["ios-arm64_i386_x86_64-simulator", "ios-arm64_armv7"]
5
+ class XCFramework
6
+ attr_reader :name, :container, :identifiers
7
+
8
+ def self.parse(json)
9
+ XCFramework.new(json["name"], json["container"], [json["identifier"]])
10
+ end
11
+
12
+ def initialize(name, container, identifiers)
13
+ @name = name
14
+ @container = container
15
+ @identifiers = identifiers
16
+ end
17
+
18
+ def ==(other)
19
+ @name == other.name && @container == other.container && @identifiers == other.identifiers
20
+ end
21
+
22
+ def make_archive(platform)
23
+ XCFrameworkCarthageArchive.new(name, platform)
24
+ end
25
+
26
+ def new_xcframework_by_adding_identifiers(identifiers_to_add)
27
+ XCFramework.new(name, container, identifiers + identifiers_to_add)
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ require "fileutils"
2
+
3
+ class XCFrameworkCarthageArchive < CarthageArchive
4
+
5
+ # Compresses `Carthage/Build/GoogleSignIn.xcframework``
6
+ # into `GoogleSignIn-iOS.zip`.`
7
+ def compress_archive(shell, carthage_build_dir = CARTHAGE_BUILD_DIR)
8
+ $LOG.debug("Archiving #{@framework_name} for #{@platform}")
9
+
10
+ framework_path = File.join(carthage_build_dir, "#{@framework_name}.xcframework")
11
+ raise MissingFrameworkDirectoryError.new, "Archive can't be created, no xcframework directory at #{framework_path}" unless Dir.exist?(framework_path)
12
+
13
+ delete_archive
14
+ shell.archive([framework_path], @archive_path)
15
+ $LOG.debug("Created #{@archive_path} archive, file size: #{formatted_archive_size}")
16
+ end
17
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carthage_remote_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juraj Blahunka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-01 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: guard
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rerun
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +140,22 @@ dependencies:
140
140
  name: rack
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 2.0.4
145
+ version: 2.0.6
146
+ - - "<"
147
+ - !ruby/object:Gem::Version
148
+ version: 2.3.0
146
149
  type: :runtime
147
150
  prerelease: false
148
151
  version_requirements: !ruby/object:Gem::Requirement
149
152
  requirements:
150
- - - "~>"
153
+ - - ">="
151
154
  - !ruby/object:Gem::Version
152
- version: 2.0.4
155
+ version: 2.0.6
156
+ - - "<"
157
+ - !ruby/object:Gem::Version
158
+ version: 2.3.0
153
159
  - !ruby/object:Gem::Dependency
154
160
  name: rest-client
155
161
  requirement: !ruby/object:Gem::Requirement
@@ -168,16 +174,22 @@ dependencies:
168
174
  name: sinatra
169
175
  requirement: !ruby/object:Gem::Requirement
170
176
  requirements:
171
- - - "~>"
177
+ - - ">="
172
178
  - !ruby/object:Gem::Version
173
- version: 2.0.1
179
+ version: 2.0.4
180
+ - - "<"
181
+ - !ruby/object:Gem::Version
182
+ version: 2.3.0
174
183
  type: :runtime
175
184
  prerelease: false
176
185
  version_requirements: !ruby/object:Gem::Requirement
177
186
  requirements:
178
- - - "~>"
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: 2.0.4
190
+ - - "<"
179
191
  - !ruby/object:Gem::Version
180
- version: 2.0.1
192
+ version: 2.3.0
181
193
  description: Centralized cache to serve carthage frameworks. Useful for distributed
182
194
  CI setup with several build machines.
183
195
  email:
@@ -187,8 +199,11 @@ executables:
187
199
  extensions: []
188
200
  extra_rdoc_files: []
189
201
  files:
202
+ - ".github/workflows/ruby.yml"
190
203
  - ".gitignore"
204
+ - ".ruby-version"
191
205
  - ".travis.yml"
206
+ - Dockerfile
192
207
  - Gemfile
193
208
  - Gemfile.lock
194
209
  - Guardfile
@@ -214,6 +229,8 @@ files:
214
229
  - lib/constants.rb
215
230
  - lib/crc32.rb
216
231
  - lib/errors.rb
232
+ - lib/framework.rb
233
+ - lib/framework_carthage_archive.rb
217
234
  - lib/log.rb
218
235
  - lib/networking.rb
219
236
  - lib/server/config.ru
@@ -223,6 +240,8 @@ files:
223
240
  - lib/utils.rb
224
241
  - lib/version.rb
225
242
  - lib/version_file.rb
243
+ - lib/xcframework.rb
244
+ - lib/xcframework_carthage_archive.rb
226
245
  homepage: https://github.com/kayak/carthage_remote_cache
227
246
  licenses:
228
247
  - Apache-2.0
@@ -242,8 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
261
  - !ruby/object:Gem::Version
243
262
  version: '0'
244
263
  requirements: []
245
- rubyforge_project:
246
- rubygems_version: 2.6.14
264
+ rubygems_version: 3.3.5
247
265
  signing_key:
248
266
  specification_version: 4
249
267
  summary: Centralized cache to serve carthage frameworks. Useful for distributed CI