forked from ctsf/Libxml2Module
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodule_parser.rb
More file actions
54 lines (41 loc) · 1.69 KB
/
module_parser.rb
File metadata and controls
54 lines (41 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
simulator_path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/libxml2/libxml"
device_path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml"
local_folder = "headers"
simulator_suffix = "simulator"
device_suffix = "device"
def light_process_contents(contents, suffix)
contents = contents.gsub(/\#include <libxml\/(.*?)\.h>/, "#import \"\\1-#{suffix}.h\"")
return contents
end
def process_contents(contents, suffix)
contents = light_process_contents(contents, suffix)
contents = contents.gsub(/\#include <(.*?)\.h>/, '@import Darwin.C.\1;')
return contents
end
def process_folder(headers_folder, local_folder, suffix)
imports = ""
Dir.foreach(headers_folder) do |fname|
if fname == "." or fname == ".." then next end
if fname == "DOCBparser.h" then next end #deprecated file
if fname == "module.modulemap" then next end #not a header
local = fname.sub(/\.h/, "-#{suffix}.h")
imports += " header \"#{local}\"\n"
contents = File.read(File.join(headers_folder, fname))
if fname == "xmlversion.h"
contents = light_process_contents(contents, suffix)
else
contents = process_contents(contents, suffix)
end
writer = File.open(File.join(local_folder, local), "w")
writer.write(contents)
end
return imports
end
Dir.mkdir(local_folder) unless File.exist?(local_folder)
puts "framework module Libxml2 {"
puts
puts process_folder(device_path, local_folder, device_suffix)
puts
puts " export *"
puts "}"
puts