forked from marguerite/golang-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolang.prov
executable file
·131 lines (67 loc) · 2.39 KB
/
golang.prov
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
#!/usr/bin/env ruby
def prepare()
specfile = Dir.glob("/home/abuild/rpmbuild/SOURCES/*.spec")[0]
#specfile = Dir.glob(`pwd`.gsub(/\n/,'') + "/*.spec")[0]
importpath,pkgname,version = "","",""
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
if l.index("Version:") then
version = l.gsub(/Version:/,'').lstrip!.chomp!
end
found = 0
if l.index(/%(define|global)[\s]+(import_path|importpath)/i) then
importpath = l.gsub(/%(define|global)[\s]+(import_path|importpath)/i,'').lstrip!.chomp!.gsub(/"/,'').gsub(/"/,'')
found = 1
end
if (found == 0 && l.index("%goprep")) then
importpath = l.gsub(/%goprep/,'').lstrip!.chomp!
found = 1
end
if (found == 0 && l.index("Url:")) then
importpath = l.gsub(/Url\:/,'').lstrip!.chomp!.gsub(/^(http|https)\:\/\//,'')
end
end
end
build = Dir.glob("/home/abuild/rpmbuild/BUILD/*#{pkgname}*")[0]
#build = Dir.glob(`pwd`.gsub(/\n/,'') + "/*#{pkgname}*/")[0]
importpath = importpath.gsub(/\/$/,'') if importpath.index(/\/$/)
return importpath,build,version
end
def all_dir(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
result << "#{dir}/#{d}" if ! Dir["#{dir}/#{d}/*.go"].empty?
all_dir("#{dir}/#{d}",result)
end
end
end
return result
end
def get_provides_list()
importpath = prepare()[0]
build = prepare()[1]
version = prepare()[2]
source,list = [],[]
# all_dir return strings containing build, replace w/ importpath
all_dir(build).each do |r|
source << importpath + r.gsub(build,'')
end
list << "golang(" + importpath + ") = " + version
source.each do |s|
list << "golang(" + s + ") = " + version
end
return list
end
puts get_provides_list()