forked from marguerite/golang-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolang.req
executable file
·152 lines (79 loc) · 2.72 KB
/
golang.req
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
55
56
57
58
59
60
61
62
63
64
65
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env ruby
def find_build_directory()
path = "/home/abuild/rpmbuild/SOURCES"
#path = `pwd`.gsub(/\n/,'')
specfile = Dir.glob(path + "/*.spec")[0]
pkgname = ""
File.open(specfile) do |f|
f.each_line do |l|
build_found = 0
if l.index(/Source(0)?:/) then
unless l.index("%{name}") then
pkgname = l.gsub(/Source(0)?:/,'').lstrip!.chomp!.gsub(/^.*\//,'').gsub(/-%.*$/,'')
build_found = 1
end
end
if (build_found == 0 && l.index("Name:")) then
pkgname = l.gsub(/Name:/,'').lstrip!.chomp!.gsub(/^(go|golang)-/,'')
end
end
end
build = Dir.glob("/home/abuild/rpmbuild/BUILD/*#{pkgname}*")[0]
#build = Dir.glob(path + "/*#{pkgname}*/")[0]
return build
end
def all_file(dir="",result=nil)
result = [] unless result
Dir.entries(dir).each do |d|
unless (d == "." || d == ".." || d.index("example") || d.index("test")) then
if File.directory?("#{dir}/#{d}") then
all_file("#{dir}/#{d}",result)
else
if ( d.index(".go") && ! d.index(/(test|example)/) ) then
result << "#{dir}/#{d}"
end
end
end
end
return result
end
def get_imports_list()
build = find_build_directory()
source = all_file(build)
list,importlist = [],[]
own = `/usr/lib/rpm/golang.prov`.split(/\n/)[0].gsub(/golang\(/,'').gsub(/\)[\s]+=.*/,'')
#own = `./golang.prov`.split(/\n/)[0].gsub(/golang\(/,'').gsub(/\)[\s]+=.*/,'')
source.each do |g|
File.open(g,:encoding => "UTF-8") do |f|
f.each_line do |l|
# import should be the first word in a line, or it could be comment
if l.index(/^import/) then
if l.index(/({|\()/)then
t = ""
f.each_line do |l1|
t = t + l1
# we don't need that much, just a few lines, not whole text
break if l1.index(/\)/)
end
imports = t.gsub(/(\n|\t)/,'').gsub(/(\)|}).*$/,'').split(/"/)
imports.each do |i|
# .com|.net|.org matches all URL, own strips its own url, [\s] (whitespace)
# guarantees it doens't match a sentence like comments
list << i if ( i.index(/(\.com|\.net|\.org|gopkg\.in)/) && ! i.index(own) && ! i.index(/[\s]/) )
end
else
list << l.gsub(/import/,'').gsub(/"/,'').lstrip!.chomp!.gsub(/.*[\s]+/,'') if ( l.index(/(\.com|\.net|\.org)/) && ! l.index(own) )
end
end
end
end
end
unless list == nil then
list.uniq.each do |l|
importlist << "golang(" + l + ")"
end
end
importlist << "golang(API) = 1.5"
return importlist
end
puts get_imports_list()