Class: TYCiCore::ConfigModules

Inherits:
Object
  • Object
show all
Defined in:
lib/tuya/ci/core/config/config_modules.rb

Direct Known Subclasses

ODMConfigModules

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = "./config_modules.json", advance_fields = "{}", pod_path = "./Pods/") ⇒ ConfigModules

Returns a new instance of ConfigModules.



7
8
9
10
11
# File 'lib/tuya/ci/core/config/config_modules.rb', line 7

def initialize(config_path="./config_modules.json", advance_fields="{}", pod_path="./Pods/")
	@config_path = config_path
	@advance_fields = advance_fields
	@pod_path = pod_path
end

Instance Attribute Details

#advance_fieldsObject

Returns the value of attribute advance_fields.



5
6
7
# File 'lib/tuya/ci/core/config/config_modules.rb', line 5

def advance_fields
  @advance_fields
end

#config_pathObject

Returns the value of attribute config_path.



5
6
7
# File 'lib/tuya/ci/core/config/config_modules.rb', line 5

def config_path
  @config_path
end

#pod_pathObject

Returns the value of attribute pod_path.



5
6
7
# File 'lib/tuya/ci/core/config/config_modules.rb', line 5

def pod_path
  @pod_path
end

Instance Method Details

#config_hashObject



13
14
15
16
17
# File 'lib/tuya/ci/core/config/config_modules.rb', line 13

def config_hash
	content = File.read @config_path
	hash = JSON content
	hash
end

#module?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tuya/ci/core/config/config_modules.rb', line 46

def module?(name)
	# find_command = "find #{pod_path} -iname #{name}Impl.h"
	# # puts("find_command is #{find_command}")
	# find_command_result = Action.sh find_command
	# # puts("find_command_result is #{find_command_result}")
	# if find_command_result.length > 0
	# 	return true
	# else
	# 	return module_lib?(name)
	# end
	commands = %W(#{pod_path} -iname #{name}Impl.h)
	result = EXE.exe('find', commands)

	if result.length > 0
		true
	else
		module_lib?(name)
	end
end

#module_lib?(name) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/tuya/ci/core/config/config_modules.rb', line 66

def module_lib?(name)

	puts "Name is #{name}".green

	lib_path =  "#{@pod_path}#{name}/#{name}*/lib#{name}.a"

	puts "File_path is #{lib_path}".yellow

	libs_path_result = Dir.glob(lib_path)

	puts("The path is#{libs_path_result}")

	if libs_path_result.length > 0

		file_path = libs_path_result[0]
		# find_command = "nm -gU #{file_path} | grep '_OBJC_CLASS_\\$_#{name}Impl'"
		#
		exists_impl = true
		# find_command_result = Action.sh(
		# 	find_command,
		# 	error_callback: ->(result) {
		# 		exists_impl = false
		# 	}
		# )

		# TODO exist?
		commands = %W(-gU #{file_path} | grep '_OBJC_CLASS_\\$_#{name}Impl')

		find_result = EXE.exe('nm', commands)

		if exists_impl && !find_result.empty?
			puts "Static lib #{name} has #{name}mpl".green
			true
		else
			puts "Static lib #{name} can not find #{name}mpl".red
			false
		end
	end

	false
end

#modules_in_podsObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tuya/ci/core/config/config_modules.rb', line 19

def modules_in_pods
	result = []
	pod_directories = Dir["#{@pod_path}*"].reject{|o| not File.directory?(o)}
	pod_directories.each do |folder|
		name = folder.gsub(/\s+/,'').split('/')[-1]
		if module?(name) && name!="Target Support Files"
			result.push(name)
		end
	end
	result
end

#setup_modulesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tuya/ci/core/config/config_modules.rb', line 31

def setup_modules

	puts "Setup #{@config_path} at #{@pod_path}".green

	modules = modules_in_pods

	advance_json = JSON.parse(@advance_fields)
	advance_json["modules"] = modules

	advance_json_pretty = JSON.pretty_generate(advance_json)
	fh = File.new(@config_path, "w")
	fh.puts advance_json_pretty
	fh.close
end