cocoapods-swordfish 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +35 -0
  3. data/lib/cocoapods_plugin.rb +86 -0
  4. data/lib/gem_version.rb +11 -0
  5. data/lib/swordfish/command/archive.rb +187 -0
  6. data/lib/swordfish/command/auto.rb +192 -0
  7. data/lib/swordfish/command/config.rb +70 -0
  8. data/lib/swordfish/command/repo/update.rb +42 -0
  9. data/lib/swordfish/command/spec/create.rb +78 -0
  10. data/lib/swordfish/command/spec/push.rb +114 -0
  11. data/lib/swordfish/command/swordfish.rb +41 -0
  12. data/lib/swordfish/command.rb +2 -0
  13. data/lib/swordfish/config/config.rb +137 -0
  14. data/lib/swordfish/config/config_asker.rb +57 -0
  15. data/lib/swordfish/config/config_builder.rb +216 -0
  16. data/lib/swordfish/helpers/build_helper.rb +160 -0
  17. data/lib/swordfish/helpers/build_utils.rb +94 -0
  18. data/lib/swordfish/helpers/framework.rb +85 -0
  19. data/lib/swordfish/helpers/framework_builder.rb +451 -0
  20. data/lib/swordfish/helpers/library.rb +54 -0
  21. data/lib/swordfish/helpers/library_builder.rb +90 -0
  22. data/lib/swordfish/helpers/sources_helper.rb +38 -0
  23. data/lib/swordfish/helpers/spec_creator.rb +167 -0
  24. data/lib/swordfish/helpers/spec_files_helper.rb +76 -0
  25. data/lib/swordfish/helpers/spec_source_creator.rb +266 -0
  26. data/lib/swordfish/helpers/upload_helper.rb +94 -0
  27. data/lib/swordfish/hmap/hmap_generator.rb +59 -0
  28. data/lib/swordfish/hmap/pod_target.rb +92 -0
  29. data/lib/swordfish/hmap/podfile_dsl.rb +36 -0
  30. data/lib/swordfish/hmap/post_install_hook_context.rb +41 -0
  31. data/lib/swordfish/hmap/xcconfig.rb +99 -0
  32. data/lib/swordfish/hmap.rb +4 -0
  33. data/lib/swordfish/native/acknowledgements.rb +27 -0
  34. data/lib/swordfish/native/analyzer.rb +55 -0
  35. data/lib/swordfish/native/file_accessor.rb +28 -0
  36. data/lib/swordfish/native/installation_options.rb +25 -0
  37. data/lib/swordfish/native/installer.rb +135 -0
  38. data/lib/swordfish/native/linter.rb +25 -0
  39. data/lib/swordfish/native/path_source.rb +33 -0
  40. data/lib/swordfish/native/pod_source_installer.rb +19 -0
  41. data/lib/swordfish/native/pod_target_installer.rb +94 -0
  42. data/lib/swordfish/native/podfile.rb +105 -0
  43. data/lib/swordfish/native/podfile_env.rb +36 -0
  44. data/lib/swordfish/native/podfile_generator.rb +195 -0
  45. data/lib/swordfish/native/podspec_finder.rb +24 -0
  46. data/lib/swordfish/native/resolver.rb +223 -0
  47. data/lib/swordfish/native/source.rb +35 -0
  48. data/lib/swordfish/native/sources_manager.rb +19 -0
  49. data/lib/swordfish/native/specification.rb +31 -0
  50. data/lib/swordfish/native/target_architectures.rb +79 -0
  51. data/lib/swordfish/native/target_validator.rb +41 -0
  52. data/lib/swordfish/native/validator.rb +39 -0
  53. data/lib/swordfish/native.rb +16 -0
  54. data/lib/swordfish.rb +2 -0
  55. metadata +167 -0
@@ -0,0 +1,160 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+ #
3
+ require 'cocoapods/command/gen'
4
+ require 'cocoapods/generate'
5
+
6
+ require 'swordfish/native/podfile'
7
+ require 'swordfish/helpers/framework_builder'
8
+ require 'swordfish/helpers/library_builder'
9
+ require 'swordfish/config/config_builder'
10
+
11
+ module Ocean
12
+ class Build
13
+ class Helper
14
+ include Pod
15
+ #class var
16
+ @@build_defines = ''
17
+ #Debug下还待完成
18
+ def initialize(spec,
19
+ platform,
20
+ framework_output,
21
+ zip,
22
+ rootSpec,
23
+ skip_archive = false,
24
+ build_model='Release')
25
+ @spec = spec
26
+ @platform = platform
27
+ @build_model = build_model
28
+ @rootSpec = rootSpec
29
+ @isRootSpec = rootSpec.name == spec.name
30
+ @skip_archive = skip_archive
31
+ @framework_output = framework_output
32
+ @zip = zip
33
+
34
+ @framework_path
35
+ end
36
+
37
+ def build
38
+ UI.section("Building static framework #{@spec}") do
39
+
40
+ build_static_framework
41
+ unless @skip_archive
42
+ # if Ocean::Build::Utils.is_framework(@spec)
43
+ if @framework_output
44
+ zip_static_framework
45
+ else
46
+ build_static_library
47
+ zip_static_library
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ def build_static_framework
56
+ source_dir = Dir.pwd
57
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
58
+ Dir.chdir(workspace_directory) do
59
+ builder = Ocean::Framework::Builder.new(@spec, file_accessor, @platform, source_dir, @isRootSpec, @build_model )
60
+ @@build_defines = builder.build if @isRootSpec
61
+ begin
62
+ @framework_path = builder.lipo_build(@@build_defines) unless @skip_archive
63
+ rescue
64
+ @skip_archive = true
65
+ end
66
+ end
67
+ end
68
+
69
+ def build_static_library
70
+ source_dir = zip_dir
71
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
72
+ Dir.chdir(workspace_directory) do
73
+ builder = Ocean::Library::Builder.new(@spec, file_accessor, @platform, source_dir,@framework_path)
74
+ builder.build
75
+ end
76
+ end
77
+
78
+ def zip_static_framework
79
+ Dir.chdir(File.join(workspace_directory,@framework_path.root_path)) do
80
+ output_name = File.join(zip_dir, framework_name_zip)
81
+ unless File.exist?(framework_name)
82
+ UI.puts "没有需要压缩的 framework 文件:#{framework_name}"
83
+ return
84
+ end
85
+
86
+ UI.puts "Compressing #{framework_name} into #{output_name}"
87
+ `zip --symlinks -r #{output_name} #{framework_name}`
88
+ end
89
+ end
90
+
91
+ def zip_static_library
92
+ Dir.chdir(zip_dir) do
93
+ output_library = "#{library_name}.zip"
94
+ unless File.exist?(library_name)
95
+ raise Informative, "没有需要压缩的 library 文件:#{library_name}"
96
+ end
97
+
98
+ UI.puts "Compressing #{library_name} into #{output_library}"
99
+
100
+ `zip --symlinks -r #{output_library} #{library_name}`
101
+ end
102
+
103
+ end
104
+
105
+
106
+ def clean_workspace
107
+ UI.puts 'Cleaning workspace'
108
+
109
+ FileUtils.rm_rf(gen_name)
110
+ Dir.chdir(zip_dir) do
111
+ FileUtils.rm_rf(framework_name) if @zip
112
+ FileUtils.rm_rf(library_name)
113
+ FileUtils.rm_rf(framework_name) unless @framework_output
114
+ FileUtils.rm_rf("#{framework_name}.zip") unless @framework_output
115
+ end
116
+ end
117
+
118
+ def framework_name
119
+ Ocean::Config::Builder.instance.framework_name(@spec)
120
+ end
121
+
122
+ def framework_name_zip
123
+ Ocean::Config::Builder.instance.framework_name_version(@spec) + '.zip'
124
+ end
125
+
126
+ def library_name
127
+ Ocean::Config::Builder.instance.library_name(@spec)
128
+ end
129
+
130
+ def workspace_directory
131
+ File.expand_path("#{gen_name}/#{@rootSpec.name}")
132
+ end
133
+
134
+ def zip_dir
135
+ Ocean::Config::Builder.instance.zip_dir
136
+ end
137
+
138
+ def gen_name
139
+ Ocean::Config::Builder.instance.gen_dir
140
+ end
141
+
142
+
143
+ def spec_file
144
+ @spec_file ||= begin
145
+ if @podspec
146
+ find_spec_file(@podspec)
147
+ else
148
+ if code_spec_files.empty?
149
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
150
+ end
151
+
152
+ spec_file = code_spec_files.first
153
+ spec_file
154
+ end
155
+ end
156
+ end
157
+
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,94 @@
1
+ require 'yaml'
2
+ require 'swordfish/config/config'
3
+
4
+ module Ocean
5
+ class Build
6
+ class Utils
7
+
8
+ def self.is_framework(spec)
9
+ if Utils.uses_frameworks?
10
+ return true
11
+ end
12
+
13
+ Utils.is_swift_module(spec)
14
+ end
15
+
16
+ def self.spec_header_dir(spec)
17
+
18
+ header_dir = "./Headers/Public/#{spec.name}"
19
+ header_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(header_dir)
20
+
21
+ unless File.exist?(header_dir)
22
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
23
+ module_name = spec.name.gsub("-", "_")
24
+ header_dir = "./Pods/Headers/Public/#{module_name}"
25
+ end
26
+
27
+ # 暂时只支持:ios
28
+ # 这段代码导致umbrella.h无法被copy到framework
29
+ # consumer = Pod::Specification::Consumer.new(spec, :ios)
30
+ # unless consumer.header_dir.nil?
31
+ # header_dir = File.join(header_dir, consumer.header_dir)
32
+ # end
33
+
34
+ header_dir
35
+ end
36
+
37
+ def self.spec_module_dir(spec)
38
+ if spec.module_name.nil?
39
+ module_dir = "./Headers/Public/#{spec.name}"
40
+ module_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(module_dir)
41
+ unless File.exist?(module_dir)
42
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
43
+ module_name = spec.name.gsub("-", "_")
44
+ module_dir = "./Pods/Headers/Public/#{module_name}"
45
+ end
46
+ else
47
+ module_dir = "./Headers/Public/#{spec.module_name}"
48
+ module_dir = "./Pods/Headers/Public/#{spec.module_name}" unless File.exist?(module_dir)
49
+ end
50
+
51
+ module_dir
52
+ end
53
+
54
+ def self.is_swift_module(spec)
55
+
56
+ is_framework = false
57
+ dir = File.join(Ocean::Config::Builder.instance.gen_dir, Ocean::Config::Builder.instance.target_name)
58
+ #auto 走这里
59
+ if File.exist?(dir)
60
+ Dir.chdir(dir) do
61
+ spec_module_dir = Utils.spec_module_dir(spec)
62
+ return false unless File.exist?(spec_module_dir)
63
+ is_framework = File.exist?(File.join(spec_module_dir, "#{spec.name}-umbrella.h"))
64
+ end
65
+ end
66
+
67
+ if $ARGV[1] == "local"
68
+ is_framework = File.exist?(File.join(Ocean::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
69
+ unless is_framework
70
+ is_framework = File.exist?(File.join(Ocean::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
71
+ end
72
+ end
73
+
74
+ is_framework
75
+ end
76
+
77
+ def self.uses_frameworks?
78
+ uses_frameworks = false
79
+ Pod::Config.instance.podfile.target_definitions.each do |key,value|
80
+ if key != "Pods"
81
+ uses_frameworks = value.uses_frameworks?
82
+ if uses_frameworks
83
+ break ;
84
+ end
85
+ end
86
+ end
87
+
88
+ uses_frameworks
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,85 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ module Ocean
4
+ class Framework
5
+ attr_reader :headers_path
6
+ attr_reader :module_map_path
7
+ attr_reader :resources_path
8
+ attr_reader :root_path
9
+ attr_reader :versions_path
10
+ attr_reader :swift_module_path
11
+ attr_reader :fwk_path
12
+
13
+ def initialize(name, platform)
14
+ @name = name
15
+ @platform = platform
16
+ end
17
+
18
+ def make
19
+ make_root
20
+ make_framework
21
+ make_headers
22
+ make_resources
23
+ make_current_version
24
+ end
25
+
26
+ def delete_resources
27
+ Pathname.new(@resources_path).rmtree if File.exist? (@resources_path)
28
+ (Pathname.new(@fwk_path) + Pathname.new('Resources')).delete if File.exist?(Pathname.new(@fwk_path) + Pathname.new('Resources'))
29
+ end
30
+
31
+ def remove_current_version
32
+ FileUtils.rm_f(File.join(@fwk_path,@name))
33
+ FileUtils.rm_f(File.join(@fwk_path,"Headers"))
34
+ FileUtils.rm_f(File.join(@fwk_path,"Resources"))
35
+
36
+ FileUtils.cp_r("#{@versions_path}/.", @fwk_path)
37
+ # FileUtils.remove_dir(@versions_path)
38
+ FileUtils.remove_dir("#{@fwk_path}/Versions")
39
+
40
+ # current_version_path = @versions_path + Pathname.new('../Current')
41
+ # `ln -sf A #{current_version_path}`
42
+ # `ln -sf Versions/Current/Headers #{@fwk_path}/`
43
+ # `ln -sf Versions/Current/Resources #{@fwk_path}/`
44
+ # `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
45
+ end
46
+
47
+ private
48
+
49
+ def make_current_version
50
+ current_version_path = @versions_path + Pathname.new('../Current')
51
+ `ln -sf A #{current_version_path}`
52
+ `ln -sf Versions/Current/Headers #{@fwk_path}/`
53
+ `ln -sf Versions/Current/Resources #{@fwk_path}/`
54
+ `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
55
+ end
56
+
57
+
58
+
59
+ def make_framework
60
+ @fwk_path = @root_path + Pathname.new(@name + '.framework')
61
+ @fwk_path.mkdir unless @fwk_path.exist?
62
+
63
+ @module_map_path = @fwk_path + Pathname.new('Modules')
64
+ @swift_module_path = @module_map_path + Pathname.new(@name + '.swiftmodule')
65
+
66
+
67
+ @versions_path = @fwk_path + Pathname.new('Versions/A')
68
+ end
69
+
70
+ def make_headers
71
+ @headers_path = @versions_path + Pathname.new('Headers')
72
+ @headers_path.mkpath unless @headers_path.exist?
73
+ end
74
+
75
+ def make_resources
76
+ @resources_path = @versions_path + Pathname.new('Resources')
77
+ @resources_path.mkpath unless @resources_path.exist?
78
+ end
79
+
80
+ def make_root
81
+ @root_path = Pathname.new(@platform)
82
+ @root_path.mkpath unless @root_path.exist?
83
+ end
84
+ end
85
+ end