carthage_cache 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/exe/carthage_cache +17 -3
- data/lib/carthage_cache.rb +2 -0
- data/lib/carthage_cache/application.rb +23 -3
- data/lib/carthage_cache/build_collector.rb +50 -0
- data/lib/carthage_cache/carthage_resolved_file.rb +24 -3
- data/lib/carthage_cache/configuration.rb +3 -9
- data/lib/carthage_cache/configuration_validator.rb +116 -0
- data/lib/carthage_cache/configurator.rb +20 -3
- data/lib/carthage_cache/project.rb +5 -1
- data/lib/carthage_cache/terminal.rb +4 -0
- data/lib/carthage_cache/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d298e36ed76a7ba934367dd437ccd25f370bb66e
|
4
|
+
data.tar.gz: e21ad383a1a9ce54a9faf6271e495def4cdc9a4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8deda74fee8bcdc4e87814419324c575d3af920abca7861a7125af4a0d27df255b474a09dd42d4569f7b1becac0639077e111738205bd431875068cc1481be35
|
7
|
+
data.tar.gz: 5911f2d074383b5cf017b3812dde21427977613f14900f7c97ae09bc9847c0a858685667928fe0b3140c5d6c1ad35923c5d187b37cf459a8ee11f1e1b60a2853
|
data/README.md
CHANGED
@@ -107,6 +107,38 @@ If you want to check whether a cache exists for the current `Carfile.resolved`
|
|
107
107
|
carthage_cache exist
|
108
108
|
```
|
109
109
|
|
110
|
+
If you want to publish an archive that already exists
|
111
|
+
|
112
|
+
```
|
113
|
+
carthage_cache publish --force
|
114
|
+
```
|
115
|
+
|
116
|
+
If you want to delete unused libraries from build directory for all targets
|
117
|
+
|
118
|
+
```
|
119
|
+
carthage_cache prune
|
120
|
+
```
|
121
|
+
|
122
|
+
You can also prune the build directory before publishing a new archive
|
123
|
+
|
124
|
+
```
|
125
|
+
carthage_cache publish --prune-build-directory
|
126
|
+
```
|
127
|
+
|
128
|
+
Both `prune` and `publish` accept `--prune-white-list` to configure frameworks that don't appear in the `Cartfile.resolved` and should not be pruned by associating them with a framework that does appear in `Cartfile.resolved`. Like `CocoaLumberjackSwift`:
|
129
|
+
|
130
|
+
```
|
131
|
+
carthage_cache publish -p -w .white-list.yml
|
132
|
+
```
|
133
|
+
* *`-p` is the short version of `--prune-build-directory`*
|
134
|
+
* *`-w` is the short version of `--prune-white-list`*
|
135
|
+
|
136
|
+
where `.white-list.yml` is
|
137
|
+
|
138
|
+
```yaml
|
139
|
+
"CocoaLumberjackSwift": "CocoaLumberjack"
|
140
|
+
```
|
141
|
+
|
110
142
|
For more information run the help command
|
111
143
|
|
112
144
|
```
|
data/exe/carthage_cache
CHANGED
@@ -53,10 +53,12 @@ command :publish do |c|
|
|
53
53
|
c.syntax = "#{PROGRAM_NAME} publish [PROJECT_PATH]"
|
54
54
|
c.description = 'Generates and uploads the cache archive for the current Cartfile.resolved.'
|
55
55
|
c.option '-f', '--force', 'Forces to create a new archive even if an archive already exist.'
|
56
|
+
c.option '-p', '--prune-build-directory', 'Removes unused frameworks from build directory.'
|
57
|
+
c.option '-w', '--prune-white-list PRUNE_WHITE_LIST', String, 'Path to a YAML file containing the prune white list.'
|
56
58
|
c.action do |args, options|
|
57
|
-
options.default force: false
|
59
|
+
options.default force: false, prune: false
|
58
60
|
app = CarthageCache::Application.new(args.first || ".", verbose, config)
|
59
|
-
app.create_archive(options.force)
|
61
|
+
app.create_archive(options.force, options.prune, options.prune_white_list)
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
@@ -64,9 +66,21 @@ command :config do |c|
|
|
64
66
|
c.syntax = "#{PROGRAM_NAME} config [PROJECT_PATH]"
|
65
67
|
c.description = "Generates a '#{CarthageCache::Configurator::CONFIG_FILE_NAME}' config file."
|
66
68
|
c.action do |args, options|
|
67
|
-
|
69
|
+
terminal = CarthageCache::Terminal.new(verbose)
|
70
|
+
configurator = CarthageCache::Configurator.new(terminal, args.first || ".")
|
68
71
|
wizard = CarthageCache::ConfiguratorWizard.new(method(:ask), method(:password))
|
69
72
|
config = wizard.start
|
70
73
|
configurator.save_config(config)
|
71
74
|
end
|
72
75
|
end
|
76
|
+
|
77
|
+
command :prune do |c|
|
78
|
+
c.syntax = "#{PROGRAM_NAME} prune [PROJECT_PATH]"
|
79
|
+
c.description = 'Removes unused frameworks from build directory.'
|
80
|
+
c.option '-w', '--prune-white-list PRUNE_WHITE_LIST', String, 'Path to a YAML file containing the prune white list.'
|
81
|
+
c.action do |args, options|
|
82
|
+
options.default force: false, prune: false
|
83
|
+
app = CarthageCache::Application.new(args.first || ".", verbose, config)
|
84
|
+
app.prune_build_directory(options.prune_white_list)
|
85
|
+
end
|
86
|
+
end
|
data/lib/carthage_cache.rb
CHANGED
@@ -7,12 +7,14 @@ require "carthage_cache/carthage_resolved_file"
|
|
7
7
|
require "carthage_cache/project"
|
8
8
|
require "carthage_cache/repository"
|
9
9
|
require "carthage_cache/terminal"
|
10
|
+
require "carthage_cache/configuration_validator"
|
10
11
|
require "carthage_cache/configuration"
|
11
12
|
require "carthage_cache/configurator"
|
12
13
|
require "carthage_cache/configurator_wizard"
|
13
14
|
require "carthage_cache/shell_command_executor.rb"
|
14
15
|
require "carthage_cache/application.rb"
|
15
16
|
require "carthage_cache/swift_version_resolver.rb"
|
17
|
+
require "carthage_cache/build_collector.rb"
|
16
18
|
|
17
19
|
module CarthageCache
|
18
20
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module CarthageCache
|
2
4
|
|
3
5
|
class Application
|
@@ -13,7 +15,7 @@ module CarthageCache
|
|
13
15
|
def initialize(project_path, verbose, config, repository: Repository, terminal: Terminal, swift_version_resolver: SwiftVersionResolver)
|
14
16
|
@terminal = terminal.new(verbose)
|
15
17
|
@archiver = Archiver.new
|
16
|
-
@config = Configurator.new(project_path, config).config
|
18
|
+
@config = Configurator.new(@terminal, project_path, config).config
|
17
19
|
@repository = repository.new(@config.bucket_name, @config.hash_object[:aws_s3_client_options])
|
18
20
|
@project = Project.new(project_path, CACHE_DIR_NAME, @terminal, @config.tmpdir, swift_version_resolver.new)
|
19
21
|
end
|
@@ -32,8 +34,22 @@ module CarthageCache
|
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
|
-
def create_archive(force = false)
|
36
|
-
|
37
|
+
def create_archive(force = false, prune = false, prune_white_list = nil)
|
38
|
+
if force || !archive_exist?
|
39
|
+
prune_build_directory(prune_white_list) if prune
|
40
|
+
archive_builder.build
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def prune_build_directory(white_list)
|
45
|
+
if white_list && File.exist?(white_list)
|
46
|
+
terminal.vputs "Prunning build directory with white list '#{white_list}' ..."
|
47
|
+
white_list = YAML.load(File.read(white_list))
|
48
|
+
else
|
49
|
+
white_list = {}
|
50
|
+
terminal.vputs "Prunning build directory ..."
|
51
|
+
end
|
52
|
+
build_collector.delete_unused_frameworks(white_list)
|
37
53
|
end
|
38
54
|
|
39
55
|
private
|
@@ -46,6 +62,10 @@ module CarthageCache
|
|
46
62
|
@archive_builder ||= ArchiveBuilder.new(terminal, repository, archiver, project)
|
47
63
|
end
|
48
64
|
|
65
|
+
def build_collector
|
66
|
+
@build_collector ||= BuildCollector.new(terminal, project.carthage_build_directory, project.all_frameworks)
|
67
|
+
end
|
68
|
+
|
49
69
|
end
|
50
70
|
|
51
71
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module CarthageCache
|
4
|
+
|
5
|
+
class BuildCollector
|
6
|
+
|
7
|
+
attr_reader :terminal
|
8
|
+
attr_reader :build_directory
|
9
|
+
attr_reader :required_frameworks
|
10
|
+
|
11
|
+
def initialize(terminal, build_directory, required_frameworks)
|
12
|
+
@terminal = terminal
|
13
|
+
@build_directory = build_directory
|
14
|
+
@required_frameworks = Set.new(required_frameworks)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_unused_frameworks(white_list = {})
|
18
|
+
terminal.vputs "Deleting unused frameworks from '#{build_directory}' ..."
|
19
|
+
list_built_frameworks.each do |framework_path|
|
20
|
+
if delete_framework?(framework_path, white_list)
|
21
|
+
terminal.vputs "Deleting '#{framework_path}' because is not longer needed."
|
22
|
+
FileUtils.rm_r(framework_path)
|
23
|
+
FileUtils.rm_r("#{framework_path}.dSYM")
|
24
|
+
# TODO delete corresponding .bcsymbolmap file
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def delete_framework?(framework_path, white_list)
|
32
|
+
framework = framework_name(framework_path)
|
33
|
+
if required_frameworks.include?(white_list[framework])
|
34
|
+
false
|
35
|
+
else
|
36
|
+
! required_frameworks.include?(framework)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def list_built_frameworks
|
41
|
+
Dir[File.join(build_directory, "/**/*.framework")]
|
42
|
+
end
|
43
|
+
|
44
|
+
def framework_name(framework_path)
|
45
|
+
Pathname.new(framework_path).basename(".framework").to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -5,14 +5,17 @@ module CarthageCache
|
|
5
5
|
class CartfileResolvedFile
|
6
6
|
|
7
7
|
attr_reader :file_path
|
8
|
+
attr_reader :terminal
|
9
|
+
attr_reader :swift_version_resolver
|
8
10
|
|
9
|
-
def initialize(file_path, swift_version_resolver = SwiftVersionResolver.new)
|
11
|
+
def initialize(file_path, terminal, swift_version_resolver = SwiftVersionResolver.new)
|
10
12
|
@file_path = file_path
|
11
13
|
@swift_version_resolver = swift_version_resolver
|
14
|
+
@terminal = terminal
|
12
15
|
end
|
13
16
|
|
14
17
|
def digest
|
15
|
-
@digest ||=
|
18
|
+
@digest ||= generate_digest
|
16
19
|
end
|
17
20
|
|
18
21
|
def content
|
@@ -20,9 +23,27 @@ module CarthageCache
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def swift_version
|
23
|
-
@swift_version ||=
|
26
|
+
@swift_version ||= swift_version_resolver.swift_version
|
24
27
|
end
|
25
28
|
|
29
|
+
def frameworks
|
30
|
+
@frameworks ||= content.each_line.map { |line| extract_framework_name(line) }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def generate_digest
|
36
|
+
terminal.vputs "Generating carthage_cache archive digest using swift version '#{swift_version}' and " \
|
37
|
+
"the content of '#{file_path}'"
|
38
|
+
generated_digest = Digest::SHA256.hexdigest(content + "#{swift_version}")
|
39
|
+
terminal.vputs "Generated digest: #{generated_digest}"
|
40
|
+
generated_digest
|
41
|
+
end
|
42
|
+
|
43
|
+
def extract_framework_name(cartfile_line)
|
44
|
+
cartfile_line.split(" ")[1].split("/").last.gsub('"', "")
|
45
|
+
end
|
46
|
+
|
26
47
|
end
|
27
48
|
|
28
49
|
end
|
@@ -13,17 +13,11 @@ module CarthageCache
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.valid?(config)
|
16
|
-
config
|
17
|
-
config.has_key?(:aws_s3_client_options) &&
|
18
|
-
config[:aws_s3_client_options][:region] &&
|
19
|
-
config[:aws_s3_client_options][:access_key_id] &&
|
20
|
-
config[:aws_s3_client_options][:secret_access_key]
|
16
|
+
ConfigurationValidator.new(config).valid?
|
21
17
|
end
|
22
18
|
|
23
19
|
def self.parse(str)
|
24
|
-
|
25
|
-
raise "Invalid configuration" unless valid?(config)
|
26
|
-
new(config)
|
20
|
+
new(YAML.load(str))
|
27
21
|
end
|
28
22
|
|
29
23
|
def self.default
|
@@ -54,7 +48,7 @@ module CarthageCache
|
|
54
48
|
end
|
55
49
|
|
56
50
|
def valid?
|
57
|
-
self.class.valid?(
|
51
|
+
self.class.valid?(self)
|
58
52
|
end
|
59
53
|
|
60
54
|
def merge(c)
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module CarthageCache
|
2
|
+
|
3
|
+
class MissingConfigurationKey < Struct.new(:keyname, :solution)
|
4
|
+
|
5
|
+
def self.missing_bucket_name
|
6
|
+
solution = "You need to specify the AWS S3 bucket to be used.\n" \
|
7
|
+
"You can either pass the '--bucket-name' option or " \
|
8
|
+
" add ':bucket_name: YOUR_BUCKET_NAME' to " \
|
9
|
+
".carthage_cache.yml file.\nYou can also run " \
|
10
|
+
"'carthage_cache config' to generate the config file."
|
11
|
+
self.new(:bucket_name, solution)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.missing_aws_key(keyname, name)
|
15
|
+
solution = "You need to specify the AWS #{name} to be used.\n" \
|
16
|
+
"You can either define a enviromental variable " \
|
17
|
+
"AWS_REGION or add ':#{keyname}: YOUR_KEY_VALUE' " \
|
18
|
+
"under the :aws_s3_client_options: key in the " \
|
19
|
+
".carthage_cache.yml file.\nYou can also run " \
|
20
|
+
"'carthage_cache config' to generate the config file."
|
21
|
+
self.new("aws_s3_client_options.#{keyname}", solution)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.missing_aws_region
|
25
|
+
missing_aws_key("region", "region")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.missing_aws_access_key_id
|
29
|
+
missing_aws_key("access_key_id", "access key ID")
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.missing_aws_secret_access_key
|
33
|
+
missing_aws_key("secret_access_key", "secret access key")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class ValidationResult
|
39
|
+
|
40
|
+
def self.valid
|
41
|
+
self.new(nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.invalid(error)
|
45
|
+
self.new(error)
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_reader :error
|
49
|
+
|
50
|
+
def initialize(error)
|
51
|
+
@error = error
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid?
|
55
|
+
@error == nil
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class ConfigurationValidator
|
61
|
+
|
62
|
+
attr_reader :config
|
63
|
+
|
64
|
+
def initialize(config)
|
65
|
+
@config = config
|
66
|
+
end
|
67
|
+
|
68
|
+
def valid?
|
69
|
+
validate.valid?
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate
|
73
|
+
return missing_bucket_name unless has_bucket_name?
|
74
|
+
return missing_aws_region unless has_aws_region?
|
75
|
+
return missing_aws_access_key_id unless has_aws_access_key_id?
|
76
|
+
return missing_aws_secret_access_key unless has_aws_secret_access_key?
|
77
|
+
ValidationResult.valid
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def has_bucket_name?
|
83
|
+
config.bucket_name
|
84
|
+
end
|
85
|
+
|
86
|
+
def has_aws_region?
|
87
|
+
config.aws_region
|
88
|
+
end
|
89
|
+
|
90
|
+
def has_aws_access_key_id?
|
91
|
+
config.aws_access_key_id
|
92
|
+
end
|
93
|
+
|
94
|
+
def has_aws_secret_access_key?
|
95
|
+
config.aws_secret_access_key
|
96
|
+
end
|
97
|
+
|
98
|
+
def missing_bucket_name
|
99
|
+
ValidationResult.invalid(MissingConfigurationKey.missing_bucket_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
def missing_aws_region
|
103
|
+
ValidationResult.invalid(MissingConfigurationKey.missing_aws_region)
|
104
|
+
end
|
105
|
+
|
106
|
+
def missing_aws_access_key_id
|
107
|
+
ValidationResult.invalid(MissingConfigurationKey.missing_aws_access_key_id)
|
108
|
+
end
|
109
|
+
|
110
|
+
def missing_aws_secret_access_key
|
111
|
+
ValidationResult.invalid(MissingConfigurationKey.missing_aws_secret_access_key)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -8,14 +8,16 @@ module CarthageCache
|
|
8
8
|
|
9
9
|
attr_reader :config_file_path
|
10
10
|
attr_reader :base_config
|
11
|
+
attr_reader :terminal
|
11
12
|
|
12
|
-
def initialize(project_path, base_config = {})
|
13
|
+
def initialize(terminal, project_path, base_config = {})
|
13
14
|
@config_file_path = File.join(project_path, CONFIG_FILE_NAME)
|
14
15
|
@base_config = merge_config(base_config)
|
16
|
+
@terminal = terminal
|
15
17
|
end
|
16
18
|
|
17
19
|
def config
|
18
|
-
@config ||= load_config
|
20
|
+
@config ||= load_config!
|
19
21
|
end
|
20
22
|
|
21
23
|
def save_config(config)
|
@@ -29,15 +31,30 @@ module CarthageCache
|
|
29
31
|
File.exist?(config_file_path)
|
30
32
|
end
|
31
33
|
|
34
|
+
def load_config!
|
35
|
+
config = load_config
|
36
|
+
validate!(config)
|
37
|
+
config
|
38
|
+
end
|
39
|
+
|
32
40
|
def load_config
|
33
41
|
if config_file_exist?
|
34
42
|
config = Configuration.parse(File.read(config_file_path))
|
35
|
-
config.merge(base_config)
|
43
|
+
config = config.merge(base_config)
|
36
44
|
else
|
37
45
|
base_config
|
38
46
|
end
|
39
47
|
end
|
40
48
|
|
49
|
+
def validate!(config)
|
50
|
+
validator = ConfigurationValidator.new(config)
|
51
|
+
result = validator.validate
|
52
|
+
unless result.valid?
|
53
|
+
terminal.error "error: #{result.error.solution}"
|
54
|
+
exit 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
41
58
|
def remove_nil_keys(hash)
|
42
59
|
hash.inject({}) do |new_hash, (k,v)|
|
43
60
|
unless v.nil? || (v.respond_to?(:empty?) && v.empty?)
|
@@ -13,7 +13,7 @@ module CarthageCache
|
|
13
13
|
@cache_dir_name = cache_dir_name
|
14
14
|
@terminal = terminal
|
15
15
|
@tmpdir_base_path = tmpdir
|
16
|
-
@cartfile = CartfileResolvedFile.new(cartfile_resolved_path, swift_version_resolver)
|
16
|
+
@cartfile = CartfileResolvedFile.new(cartfile_resolved_path, terminal, swift_version_resolver)
|
17
17
|
end
|
18
18
|
|
19
19
|
def archive_filename
|
@@ -32,6 +32,10 @@ module CarthageCache
|
|
32
32
|
@carthage_build_directory ||= File.join(project_path, "Carthage", "Build")
|
33
33
|
end
|
34
34
|
|
35
|
+
def all_frameworks
|
36
|
+
cartfile.frameworks
|
37
|
+
end
|
38
|
+
|
35
39
|
private
|
36
40
|
|
37
41
|
def cartfile_resolved_path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carthage_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guido Marucci Blas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03
|
11
|
+
date: 2016-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -137,8 +137,10 @@ files:
|
|
137
137
|
- lib/carthage_cache/archive_builder.rb
|
138
138
|
- lib/carthage_cache/archive_installer.rb
|
139
139
|
- lib/carthage_cache/archiver.rb
|
140
|
+
- lib/carthage_cache/build_collector.rb
|
140
141
|
- lib/carthage_cache/carthage_resolved_file.rb
|
141
142
|
- lib/carthage_cache/configuration.rb
|
143
|
+
- lib/carthage_cache/configuration_validator.rb
|
142
144
|
- lib/carthage_cache/configurator.rb
|
143
145
|
- lib/carthage_cache/configurator_wizard.rb
|
144
146
|
- lib/carthage_cache/description.rb
|