sbbuild 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 14bc45c4d2f6f64cdee5505d9fce883aab2650eaccbab14c00cf5cbf1cccb4ed
4
+ data.tar.gz: 9429c3fcc728f2f3d1d187d447337eb3ea37aa6cf13741bb9695fc388a4ad204
5
+ SHA512:
6
+ metadata.gz: 100d6bd93b9308a5c671f04e96138b6c9bf32ce8404390bea5c37004ede810a84582084e65428839b6aca40220f990ccb458c6968cd939f052e341ff2a610827
7
+ data.tar.gz: 733380e50d2603f8170dd31a1292eb87d1ad07d72089f0b333fc8dc5671ebfaaca79e3d6d2e95ea945930fad0ed7ad77227ddab3d66bb0d8da8c937d9a945c57
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - 2.7.5
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run the default task
27
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-03-29
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at yusheng@akulaku.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in sbuild.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sbuild (1.0.0)
5
+ xcodeproj (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ CFPropertyList (3.0.5)
11
+ rexml
12
+ ast (2.4.2)
13
+ atomos (0.1.3)
14
+ claide (1.1.0)
15
+ colored2 (3.1.2)
16
+ nanaimo (0.3.0)
17
+ parallel (1.21.0)
18
+ parser (3.0.3.2)
19
+ ast (~> 2.4.1)
20
+ rainbow (3.0.0)
21
+ rake (13.0.6)
22
+ regexp_parser (2.2.0)
23
+ rexml (3.2.5)
24
+ rubocop (1.24.0)
25
+ parallel (~> 1.10)
26
+ parser (>= 3.0.0.0)
27
+ rainbow (>= 2.2.2, < 4.0)
28
+ regexp_parser (>= 1.8, < 3.0)
29
+ rexml
30
+ rubocop-ast (>= 1.15.0, < 2.0)
31
+ ruby-progressbar (~> 1.7)
32
+ unicode-display_width (>= 1.4.0, < 3.0)
33
+ rubocop-ast (1.15.1)
34
+ parser (>= 3.0.1.1)
35
+ ruby-progressbar (1.11.0)
36
+ unicode-display_width (2.1.0)
37
+ xcodeproj (1.21.0)
38
+ CFPropertyList (>= 2.3.3, < 4.0)
39
+ atomos (~> 0.1.3)
40
+ claide (>= 1.0.2, < 2.0)
41
+ colored2 (~> 3.1)
42
+ nanaimo (~> 0.3.0)
43
+ rexml (~> 3.2.4)
44
+
45
+ PLATFORMS
46
+ x86_64-darwin-21
47
+
48
+ DEPENDENCIES
49
+ rake (~> 13.0)
50
+ rubocop (~> 1.21)
51
+ sbuild!
52
+
53
+ BUNDLED WITH
54
+ 2.2.32
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 yusheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Sbuild
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sbuild`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sbuild'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sbuild
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sbuild. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sbuild/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Sbuild project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sbuild/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "sbuild"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/sbuild ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sbuild'
4
+
5
+ manager = CacheManager.new
6
+
7
+ if ARGV[0] == "begin"
8
+ manager.project_task_begin(ARGV)
9
+ elsif ARGV[0] == "finish"
10
+ manager.project_task_end
11
+ elsif ARGV[0] == "cache"
12
+ manager.add_cache_flag
13
+ elsif ARGV[0] == "copy"
14
+ manager.copy_cache
15
+ elsif ARGV[0] == "target_env"
16
+ manager.set_target_env
17
+ elsif ARGV[0] == "project_env"
18
+ manager.set_project_env
19
+ else
20
+ puts "<ERROR> please input prama such as (begin, finish, inject, copy) "
21
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sbuild
4
+ VERSION = "1.0.0"
5
+ end
data/lib/sbuild.rb ADDED
@@ -0,0 +1,618 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'json/ext'
4
+ require 'xcodeproj'
5
+ require 'pathname'
6
+ require "find"
7
+ require 'set'
8
+
9
+ #配置
10
+
11
+ TARGET_CACHE_CONFIG = "target_cache_config.yml"
12
+
13
+ CACHE_STATUS_MISS = "miss"
14
+ CACHE_STATUS_READY = "ready"
15
+ CACHE_STATUS_HIT = "hit"
16
+
17
+ FILE_NAME_PRODUCT = "product.tar"
18
+ FILE_NAME_CONTEXT = "context.yml"
19
+ FILE_NAME_TARGET_CONTEXT = "target_context.yml"
20
+
21
+ #Xcode编译相关常量
22
+ FULL_PRODUCT_NAME = "FULL_PRODUCT_NAME"
23
+ CONFIGURATION_BUILD_DIR = "CONFIGURATION_BUILD_DIR"
24
+ TARGET_TEMP_DIR = "TARGET_TEMP_DIR"
25
+ TARGET_BUILD_DIR = "TARGET_BUILD_DIR"
26
+
27
+ SYMROOT = "SYMROOT"
28
+ SRCROOT = "SRCROOT"
29
+ OBJROOT = "OBJROOT"
30
+
31
+
32
+ #变量
33
+ $target_build_configuration = "Debug"
34
+ $project_build_branch = "master"
35
+ $podfile_spec_checksums = nil
36
+ $file_md5_hash = {}
37
+ $exclude_target = []
38
+
39
+ class CacheManager
40
+
41
+ def get_branch_cache_folder
42
+ return Dir.home + "/sbBuild" +"/#{$project_build_branch.gsub("/", ".")}"
43
+ end
44
+
45
+ def get_cache_root
46
+ return Dir.home + "/sbBuild"
47
+ end
48
+
49
+ def get_default_cache_folder
50
+ return Dir.home + "/sbBuild/master"
51
+ end
52
+
53
+ def is_private_target(target)
54
+ if target.name.start_with? "AK" or target.name.start_with? "EUR" or target.name.start_with? "A4K"
55
+ return true
56
+ else
57
+ return false
58
+ end
59
+ end
60
+
61
+ def get_content_without_pwd(content)
62
+ content = content.gsub("#{Dir.pwd}/", "").gsub(/#{Dir.pwd}(\W|$)/, '\1')
63
+ return content
64
+ end
65
+
66
+ def get_file_md5(file)
67
+ if $file_md5_hash.has_key? file
68
+ return $file_md5_hash[file]
69
+ end
70
+ md5 = Digest::MD5.hexdigest(File.read(file))
71
+ $file_md5_hash[file] = md5
72
+ return md5
73
+ end
74
+
75
+
76
+ def get_projects
77
+ # project_path = ""
78
+ # if File.exist? "#{get_cache_root}/#{project_name}.yml"
79
+ # project_context = YAML.load(File.read("#{get_cache_root}/#{project_name}.yml"))
80
+ # project_path = project_context[:project_path]
81
+ # end
82
+ # raise unless project_path.length > 0
83
+ project_path = "Pods/Pods.xcodeproj"
84
+ pods_project = Xcodeproj::Project.open(project_path)
85
+ super_project_paths = get_super_project(pods_project)
86
+ super_projects = []
87
+ super_project_paths.each do | path |
88
+ next if path.end_with? project_path
89
+ project = Xcodeproj::Project.open(path)
90
+ super_projects.push project
91
+ end
92
+ return (super_projects + [pods_project])
93
+ end
94
+
95
+ def get_super_project(project)
96
+ wrapper_projects = project.files.select{|file|file.last_known_file_type=="wrapper.pb-project"}
97
+ wrapper_project_paths = []
98
+ wrapper_projects.each do | wrapper_project_file |
99
+ wrapper_project_file_path = wrapper_project_file.real_path.to_s
100
+ wrapper_project_paths.push wrapper_project_file_path
101
+ end
102
+ return wrapper_project_paths.uniq
103
+ end
104
+
105
+
106
+ def backup_project(project)
107
+ command = "cp \"#{project.path}/project.pbxproj\" \"#{project.path}/ysTest_backup.pbxproj\""
108
+ raise unless system command
109
+ end
110
+
111
+ def clean_temp_files
112
+
113
+ command = "rm -rf Pods/*.xcodeproj/*.#{FILE_NAME_TARGET_CONTEXT}"
114
+ raise unless system command
115
+ end
116
+
117
+ def restore_project(project)
118
+ if File.exist? "#{project.path}/ysTest_backup.pbxproj"
119
+ command = "mv \"#{project.path}/ysTest_backup.pbxproj\" \"#{project.path}/project.pbxproj\""
120
+ raise unless system command
121
+ end
122
+ end
123
+
124
+
125
+ def can_cache_target(target)
126
+ if target.product_type == "com.apple.product-type.bundle" or
127
+ target.product_type == "com.apple.product-type.library.static" or
128
+ target.product_type == "com.apple.product-type.framework"
129
+ return true
130
+ end
131
+ return false
132
+ end
133
+
134
+
135
+ def get_target_source_files(target)
136
+ files = []
137
+ #获取所有可执行文件(.m .swift .cpp .mm)
138
+ target.source_build_phase.files.each do | file |
139
+ file_path = file.file_ref.real_path.to_s
140
+ files.push file_path
141
+ end
142
+
143
+ #获取所有头文件(.h)
144
+ target.headers_build_phase.files.each do | file |
145
+ file_path = file.file_ref.real_path.to_s
146
+ files.push file_path
147
+ end
148
+ #获取所有资源文件(.png,.strings .json .html)
149
+ target.resources_build_phase.files.each do | file |
150
+ file_path = file.file_ref.real_path.to_s
151
+ files.push file_path
152
+ end
153
+ expand_files = []
154
+ files.uniq.each do | file |
155
+ next unless File.exist? file
156
+ if File.file? file
157
+ expand_files.push file
158
+ else
159
+ Find.find(file).each do | file_in_dir |
160
+ if File.file? file_in_dir
161
+ expand_files.push file_in_dir
162
+ end
163
+ end
164
+ end
165
+ end
166
+ return expand_files.uniq
167
+ end
168
+
169
+
170
+ def generate_target_all_infomation(project, target, source_files)
171
+ if $podfile_spec_checksums == nil and File.exist? "#{project.path}/Podfile.lock"
172
+ podfile_lock = YAML.load(File.read("#{project.path}/Podfile.lock"))
173
+ $podfile_spec_checksums = podfile_lock["SPEC CHECKSUMS"]
174
+ end
175
+
176
+ project_configuration = project.build_configurations.detect { | config | config.name == $target_build_configuration}
177
+ project_configuration_content = project_configuration.pretty_print.to_yaml
178
+
179
+ project_xcconfig = ""
180
+ if project_configuration.base_configuration_reference
181
+ config_file_path = project_configuration.base_configuration_reference.real_path
182
+ if File.exist? config_file_path
183
+ project_xcconfig = File.read(config_file_path).lines.reject{|line|line.include? "_SEARCH_PATHS"}.sort.join("")
184
+ end
185
+ end
186
+
187
+ target_configuration = target.build_configurations.detect { | config | config.name == $target_build_configuration}
188
+ target_configuration_content = target_configuration.pretty_print.to_yaml
189
+
190
+ target_xcconfig = ""
191
+ if target_configuration.base_configuration_reference
192
+ config_file_path = target_configuration.base_configuration_reference.real_path
193
+ if File.exist? config_file_path
194
+ target_xcconfig = File.read(config_file_path).lines.reject{|line|line.include? "_SEARCH_PATHS"}.sort.join("")
195
+ end
196
+ end
197
+
198
+
199
+ files_configuration = []
200
+ build_phases = []
201
+ build_phases.push target.source_build_phase if target.methods.include? :source_build_phase
202
+ build_phases.push target.resources_build_phase if target.methods.include? :resources_build_phase
203
+ build_phases.each do | build_phase |
204
+ target.source_build_phase.files_references.each do | files_reference |
205
+ if files_reference.class == Xcodeproj::Project::Object::PBXVariantGroup
206
+ files_reference.files.each do |file_ref_in_group|
207
+ file_ref_in_group.build_files.each do |build_file|
208
+ if build_file.settings and build_file.settings.class == Hash
209
+ first_configuration.push File.basename(build_file.file_ref.real_path.to_s) + "\n" + build_file.settings.to_yaml
210
+ end
211
+ end
212
+ end
213
+ else
214
+ files_reference.build_files.each do |build_file|
215
+ if build_file.settings and build_file.settings.class == Hash
216
+ files_configuration.push File.basename(build_file.file_ref.real_path.to_s) + "\n" + build_file.settings.to_yaml
217
+ end
218
+ end
219
+ end
220
+ end
221
+ files_configuration = files_configuration.sort.uniq.join("\n")
222
+
223
+
224
+ source_md5_list = []
225
+ has_found_checksum = false
226
+ split_parts = target.name.split("-")
227
+ split_parts.each_with_index do | part, index |
228
+ spec_name = split_parts[0..index].join("-")
229
+ if $podfile_spec_checksums.has_key? spec_name
230
+ source_md5_list.push "SPEC CHECKSUM : #{spec_name} #{$podfile_spec_checksums[spec_name]}"
231
+ has_found_checksum = true
232
+ end
233
+ end
234
+
235
+ if has_found_checksum
236
+ if target.name.start_with? "AK" or target.name.start_with? "EUR"
237
+
238
+ source_md5_list.push "Project : #{File.basename(project.path)}"
239
+ source_md5_list.push "Project configuration : "
240
+ source_md5_list.push project_configuration_content.strip
241
+ source_md5_list.push "Project xcconfig : "
242
+ source_md5_list.push project_xcconfig.strip
243
+
244
+ source_md5_list.push "Target : #{target.name}, #{target.product_type}"
245
+ source_md5_list.push "Target configuration : "
246
+ source_md5_list.push target_configuration_content.strip
247
+ source_md5_list.push "Target xcconfig : "
248
+ source_md5_list.push target_xcconfig.strip
249
+ source_md5_list.push "Files settings : "
250
+ source_md5_list.push files_configuration.strip
251
+
252
+ source_md5_list.push "Files MD5 : "
253
+ source_files.uniq.sort.each do | file |
254
+ path = file
255
+ if target.name == "AKULocalizedStrings" or target.name == "EURLocalizedStrings"
256
+ if file.include? ".swift"
257
+ source_md5_list.push path + " : " + get_file_md5(path)
258
+ end
259
+ else
260
+ source_md5_list.push path + " : " + get_file_md5(path)
261
+ end
262
+ end
263
+ else
264
+ source_md5_list.push "Target configuration: #{$target_build_configuration}"
265
+ end
266
+
267
+ source_md5_content = source_md5_list.join("\n")
268
+ return source_md5_content
269
+
270
+ end
271
+ end
272
+
273
+
274
+
275
+ def get_target_cache(target, target_md5)
276
+
277
+ dependency_start_time = Time.now
278
+
279
+ if is_private_target(target)
280
+ target_cache_dirs = Dir.glob(get_branch_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
281
+ else
282
+ target_cache_dirs = Dir.glob(get_default_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
283
+ end
284
+
285
+ hit_results = []
286
+
287
+ target_cache_dirs.each do |target_cache_dir|
288
+ unless File.exist? target_cache_dir + "/" + FILE_NAME_PRODUCT
289
+ puts "<ERROR> #{target.name} target cache dir missed files: #{target_cache_dir}"
290
+ next
291
+ end
292
+ unless File.exist? target_cache_dir + "/" + FILE_NAME_CONTEXT
293
+ puts "<ERROR> #{target.name} target cache dir missed files: #{target_cache_dir}"
294
+ next
295
+ end
296
+
297
+ target_context = YAML.load(File.read(target_cache_dir + "/" + FILE_NAME_CONTEXT))
298
+
299
+ if target_context[:target_md5] != target_md5 or target_context[:product_md5] != get_file_md5(target_cache_dir + "/" + FILE_NAME_PRODUCT)
300
+ command = "rm -rf \"#{target_cache_dir}\""
301
+ raise unless system command
302
+ puts "<ERROR> #{target.name} target md5 does not match: #{target_cache_dir}"
303
+ end
304
+
305
+ hit_results.push target_cache_dir
306
+
307
+ end
308
+
309
+ return hit_results
310
+
311
+ end
312
+
313
+ def set_project_env
314
+ project_name = ARGV[1]
315
+ project_path = ARGV[2]
316
+
317
+ project_context = {}
318
+ project_context[:project_name] = project_name
319
+ project_context[:project_path] = project_path
320
+ File.write("#{get_cache_root}/#{project_name}.yml", project_context.to_yaml)
321
+ end
322
+
323
+ def set_target_env
324
+ target_name = ARGV[1]
325
+ project_path = ARGV[2]
326
+ branch_name = ARGV[3]
327
+
328
+ target_context = {}
329
+ target_context[:branch_name] = branch_name
330
+ [SYMROOT, OBJROOT, SRCROOT, CONFIGURATION_BUILD_DIR, TARGET_BUILD_DIR, TARGET_TEMP_DIR, FULL_PRODUCT_NAME].sort.each do | key |
331
+ if ENV[key]
332
+ target_context[key] = ENV[key]
333
+ end
334
+ end
335
+ target_context[:target_status] = CACHE_STATUS_READY
336
+ File.write("#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}", target_context.to_yaml)
337
+ end
338
+
339
+ def add_cache_flag
340
+ target_name = ARGV[1]
341
+ project_path = ARGV[2]
342
+ if File.exist? "#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}"
343
+ target_context = YAML.load(File.read("#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}"))
344
+ [SYMROOT, OBJROOT, SRCROOT, CONFIGURATION_BUILD_DIR, TARGET_BUILD_DIR, TARGET_TEMP_DIR, FULL_PRODUCT_NAME].sort.each do | key |
345
+ if ENV[key]
346
+ target_context[key] = ENV[key]
347
+ end
348
+ end
349
+ target_context[:target_status] = CACHE_STATUS_READY
350
+ File.write("#{project_path}/#{target_name}.#{FILE_NAME_TARGET_CONTEXT}", target_context.to_yaml)
351
+ end
352
+ end
353
+
354
+ def inject_cache_action(project, target)
355
+ command_exec = "\"#{$0}\""
356
+ inject_phase = target.new_shell_script_build_phase("ys_cache_#{target.name}")
357
+ inject_phase.shell_script = "#{command_exec} #{"cache"} #{target.name} \"#{project.path}\""
358
+ inject_phase.show_env_vars_in_log = '1'
359
+ end
360
+
361
+ def inject_copy_action(project, target, target_context)
362
+ target_cache_dir = target_context[:hit_target_cache_dir]
363
+
364
+ target.build_phases.delete_if { | build_phase |
365
+ build_phase.class == Xcodeproj::Project::Object::PBXHeadersBuildPhase or
366
+ build_phase.class == Xcodeproj::Project::Object::PBXSourcesBuildPhase or
367
+ build_phase.class == Xcodeproj::Project::Object::PBXResourcesBuildPhase
368
+ }
369
+
370
+ command_exec = "\"#{$0}\""
371
+ inject_phase = target.new_shell_script_build_phase("ys_copy_#{target.name}")
372
+ inject_phase.shell_script = "#{command_exec} #{"copy"} \"#{target_cache_dir}\""
373
+ inject_phase.show_env_vars_in_log = '1'
374
+ end
375
+
376
+ def copy_cache
377
+
378
+ puts "<INFO> #{Time.now.to_f.to_s}"
379
+ start_time = Time.now
380
+ target_cache_dir = ARGV[1]
381
+ cache_product_path = target_cache_dir + "/#{FILE_NAME_PRODUCT}"
382
+
383
+ [SYMROOT, CONFIGURATION_BUILD_DIR, OBJROOT, TARGET_BUILD_DIR, TARGET_TEMP_DIR, SRCROOT, FULL_PRODUCT_NAME].sort.each do | key |
384
+ unless ENV.has_key? key and ENV[key] and ENV[key].size > 0
385
+ raise "<INFO> #{$0} should have #{key}"
386
+ break
387
+ end
388
+ end
389
+
390
+ command = "mkdir -p \"#{ENV[CONFIGURATION_BUILD_DIR]}\" && cd \"#{File.dirname(ENV[CONFIGURATION_BUILD_DIR])}/\" && tar -xf \"#{cache_product_path}\""
391
+ raise unless system command
392
+
393
+ if ENV[CONFIGURATION_BUILD_DIR] != ENV[TARGET_BUILD_DIR]
394
+
395
+ command = "rm -rf \"#{ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\""
396
+ raise unless system command
397
+
398
+ command = "mkdir -p \"#{File.dirname(ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME])}\""
399
+ raise unless system command
400
+
401
+ command = "mv \"#{ENV[CONFIGURATION_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\" \"#{ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\""
402
+ raise unless system command
403
+
404
+ command = "/bin/ln -sfh \"#{ENV[TARGET_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\" \"#{ENV[CONFIGURATION_BUILD_DIR]+"/"+ENV[FULL_PRODUCT_NAME]}\""
405
+ raise unless system command
406
+ end
407
+
408
+ puts "<INFO> duration = #{((Time.now - start_time)*1000).to_i} ms in copy cache action"
409
+ puts "<INFO> #{Time.now.to_f.to_s}"
410
+ end
411
+
412
+
413
+ def add_cache(target, target_info)
414
+
415
+ target_md5 = target_info[:target_md5]
416
+ product_dir = target_info[CONFIGURATION_BUILD_DIR]
417
+ full_product_name = target_info[FULL_PRODUCT_NAME]
418
+ $project_build_branch = target_info[:branch_name]
419
+
420
+
421
+ unless product_dir.length > 0 and full_product_name.length > 0
422
+ [SYMROOT, OBJROOT, SRCROOT, CONFIGURATION_BUILD_DIR, TARGET_BUILD_DIR, TARGET_TEMP_DIR, FULL_PRODUCT_NAME].sort.each do | key |
423
+ if CONFIGURATION_BUILD_DIR and ENV[CONFIGURATION_BUILD_DIR]
424
+ product_dir = ENV[CONFIGURATION_BUILD_DIR]
425
+ end
426
+
427
+ if FULL_PRODUCT_NAME and ENV[FULL_PRODUCT_NAME]
428
+ full_product_name = ENV[FULL_PRODUCT_NAME]
429
+ end
430
+ end
431
+ end
432
+
433
+ Dir.glob("#{product_dir}/**/*.modulemap").each do | modulemap |
434
+ modulemap_content = File.read(modulemap)
435
+ if modulemap_content.include? File.dirname(modulemap) + "/"
436
+ modulemap_content = modulemap_content.gsub(File.dirname(modulemap) + "/", "")
437
+ File.write(modulemap, modulemap_content)
438
+ end
439
+ end
440
+
441
+ unless full_product_name and full_product_name.size > 0 and File.exist? "#{product_dir}/#{full_product_name}"
442
+ puts "<ERROR> #{target.name} #{product_dir}/#{full_product_name} should exist"
443
+ return false
444
+ end
445
+
446
+ zip_start_time = Time.now
447
+
448
+ command = "cd \"#{File.dirname(product_dir)}\" && tar -L -c -f #{target.name}.#{FILE_NAME_PRODUCT} #{File.basename(product_dir)}/#{full_product_name}"
449
+ if target.product_type == "com.apple.product-type.library.static"
450
+ command = "cd \"#{File.dirname(product_dir)}\" && tar --exclude=*.bundle --exclude=*.framework -L -c -f #{target.name}.#{FILE_NAME_PRODUCT} #{File.basename(product_dir)}"
451
+ end
452
+
453
+ unless system command
454
+ puts "<INFO> #{command} should succeed"
455
+ return false
456
+ end
457
+
458
+
459
+ if is_private_target(target)
460
+ already_target_cache_dirs = Dir.glob(get_branch_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
461
+ else
462
+ already_target_cache_dirs = Dir.glob(get_default_cache_folder + "/" + target.name + "-" + target_md5 + "-*")
463
+ end
464
+
465
+ already_target_cache_dirs.each do |path|
466
+ if File.exist? path
467
+ raise unless system "rm -rf \"#{path}\""
468
+ end
469
+ end
470
+
471
+
472
+ if is_private_target(target)
473
+ target_cache_dir = get_branch_cache_folder + "/" + target.name + "-" + target_md5 + "-" + (Time.now.to_f * 1000).to_i.to_s
474
+ else
475
+ target_cache_dir = get_default_cache_folder + "/" + target.name + "-" + target_md5 + "-" + (Time.now.to_f * 1000).to_i.to_s
476
+ end
477
+
478
+ if File.exist? target_cache_dir
479
+ puts "<INFO> #{target_cache_dir} should not exist"
480
+ raise unless system "rm -rf \"#{target_cache_dir}\""
481
+ return false
482
+ end
483
+
484
+ command = "mkdir -p \"#{target_cache_dir}\""
485
+ unless system command
486
+ puts "<INFO> #{command} should succeed"
487
+ return false
488
+ end
489
+
490
+ cache_product_path = target_cache_dir + "/#{FILE_NAME_PRODUCT}"
491
+ command = "mv \"#{File.dirname(product_dir)}/#{target.name}.#{FILE_NAME_PRODUCT}\" \"#{cache_product_path}\""
492
+ unless system command
493
+ puts "<INFO> #{command} should succeed"
494
+ return false
495
+ end
496
+ unless File.exist? cache_product_path
497
+ puts "<INFO> #{cache_product_path} should exist after mv"
498
+ return false
499
+ end
500
+
501
+ target_info[:product_md5] = get_file_md5(cache_product_path)
502
+ target_info[:build_product_dir] = target_info[CONFIGURATION_BUILD_DIR].gsub(target_info[SYMROOT] + "/", "")
503
+ target_info[:build_intermediate_dir] = target_info[TARGET_TEMP_DIR].gsub(target_info[OBJROOT] + "/", "")
504
+
505
+ target_info.delete(:target_status)
506
+ target_info.delete(:hit_target_cache_dir)
507
+ target_info.delete(:target_md5_content)
508
+
509
+ File.write(target_cache_dir + "/" + FILE_NAME_CONTEXT, target_info.to_yaml)
510
+
511
+ return true
512
+
513
+ end
514
+
515
+
516
+ def project_task_begin(argv)
517
+
518
+ projects = get_projects
519
+ total_count = 0
520
+ hit_count = 0
521
+ miss_count = 0
522
+ error_count = 0
523
+ hit_target_md5_cache_set = Set.new
524
+ miss_target_cache_set = Set.new
525
+
526
+ pre_targets_info = {}
527
+
528
+ projects.each do |project|
529
+ # restore_project(project)
530
+ backup_project(project)
531
+ end
532
+
533
+ clean_temp_files
534
+
535
+ # projects = get_projects
536
+
537
+ projects.each do |project|
538
+ project.native_targets.each do |target|
539
+ if can_cache_target(target)
540
+ total_count = total_count + 1
541
+ source_files = get_target_source_files(target)
542
+ target_md5_content = generate_target_all_infomation(project, target, source_files)
543
+ unless target_md5_content
544
+ puts "<ERROR> target md5 content can not generate: #{target.name}"
545
+ error_count = error_count + 1
546
+ next
547
+ end
548
+
549
+ target_md5 = Digest::MD5.hexdigest(target_md5_content)
550
+ hit_target_cache_dirs = get_target_cache(target, target_md5)
551
+ target_info = {}
552
+
553
+ if hit_target_cache_dirs.count == 0
554
+ puts "<INFO> #{target.name} #{target_md5} does not hit any cache"
555
+ target_info[:target_status] = CACHE_STATUS_MISS
556
+ inject_cache_action(project, target)
557
+ miss_count = miss_count + 1
558
+ else
559
+ target_info[:hit_target_cache_dir] = hit_target_cache_dirs
560
+ hit_target_md5_cache_set.add "#{target.name}-#{target_md5}"
561
+
562
+ if hit_target_cache_dirs.count > 0
563
+ puts "<INFO> #{target.name} #{target_md5} hit cache"
564
+ hit_count = hit_count + 1
565
+ target_really_hit_dir = hit_target_cache_dirs[0]
566
+ hit_target_info = YAML.load(File.read(target_really_hit_dir + "/" + FILE_NAME_CONTEXT))
567
+ target_info = target_info.merge!(hit_target_info)
568
+ target_info[:target_status] = CACHE_STATUS_HIT
569
+ target_info[:hit_target_cache_dir] = target_really_hit_dir
570
+ inject_copy_action(project, target, target_info)
571
+ end
572
+ end
573
+ File.write("#{project.path}/#{target.name}.#{FILE_NAME_TARGET_CONTEXT}", target_info.to_yaml)
574
+ end
575
+ end
576
+ project.save
577
+ end
578
+ puts "<INFO> total count: #{total_count}, hit count: #{hit_count}, miss_count: #{miss_count}, error_count: #{error_count}"
579
+ end
580
+
581
+
582
+ def project_task_end
583
+
584
+ projects = get_projects
585
+ post_targets_context = {}
586
+ total_add_count = 0
587
+
588
+ projects.each do |project|
589
+ project.native_targets.each do | target |
590
+ target_context_file = "#{project.path}/#{target.name}.#{FILE_NAME_TARGET_CONTEXT}"
591
+ if can_cache_target(target)
592
+ if File.exist? target_context_file
593
+ post_targets_context = YAML.load(File.read(target_context_file))
594
+ end
595
+ next unless post_targets_context[:target_status] != CACHE_STATUS_HIT
596
+
597
+ source_files = get_target_source_files(target)
598
+ target_md5_content = generate_target_all_infomation(project, target, source_files)
599
+ next unless target_md5_content && target_md5_content.length > 0
600
+
601
+ cur_target_md5 = Digest::MD5.hexdigest(target_md5_content)
602
+
603
+ post_targets_context[:target_md5] = cur_target_md5
604
+
605
+ if add_cache(target, post_targets_context)
606
+ puts "<INFO> #{target} is being added to cache dir"
607
+ total_add_count = total_add_count + 1
608
+ target.build_phases.delete_if { |phase|
609
+ phase.class == Xcodeproj::Project::Object::PBXShellScriptBuildPhase and phase.name.include? "ys_"
610
+ }
611
+ end
612
+ end
613
+ end
614
+ restore_project(project)
615
+ end
616
+ puts "<INFO> total add cache count: #{total_add_count}"
617
+ end
618
+ end
data/sbuild.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require_relative "lib/sbuild/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sbbuild"
7
+ spec.version = Sbuild::VERSION
8
+ spec.authors = ["yusheng"]
9
+ spec.email = ["yusheng@akulaku.com"]
10
+
11
+ spec.summary = "a tool for xcode project"
12
+ spec.description = "it can use xcode cache to reduce xcode build time"
13
+ spec.homepage = "https://github.com/yusheng00"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+
27
+ spec.bindir = "bin"
28
+ spec.executables = "sbuild"
29
+ spec.require_paths = ["lib"]
30
+
31
+
32
+ spec.add_dependency "xcodeproj", "~> 1.0"
33
+ spec.add_development_dependency "bundler", "~> 1.17"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ # spec.add_dependency "example-gem", "~> 1.0"
38
+
39
+ # For more information and examples about making a new gem, checkout our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbbuild
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - yusheng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xcodeproj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: it can use xcode cache to reduce xcode build time
56
+ email:
57
+ - yusheng@akulaku.com
58
+ executables:
59
+ - sbuild
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".github/workflows/main.yml"
64
+ - ".gitignore"
65
+ - ".rubocop.yml"
66
+ - CHANGELOG.md
67
+ - CODE_OF_CONDUCT.md
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/sbuild
75
+ - bin/setup
76
+ - lib/sbuild.rb
77
+ - lib/sbuild/version.rb
78
+ - sbuild.gemspec
79
+ homepage: https://github.com/yusheng00
80
+ licenses:
81
+ - MIT
82
+ metadata:
83
+ homepage_uri: https://github.com/yusheng00
84
+ source_code_uri: https://github.com/yusheng00
85
+ changelog_uri: https://github.com/yusheng00
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.6.0
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.1.6
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: a tool for xcode project
105
+ test_files: []