-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebuild2pisi.tcl
231 lines (196 loc) · 7.96 KB
/
ebuild2pisi.tcl
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 2.
# See the file http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# Functions related to parsing the ebuild file...
global xDescription xHomepage xDependency xRDependency xLicense xSourcePath xPatch xsetup xbuild xinstall xdodoc xkde xconfopt xbashvar xbashlocalvar xWorkDir
# Bash Function Return Value....
global gRet gByPassIf gByPassElse gIfNum
set gByPassIf 0
set gByPassElse 0
set gIfNum 0
set gRet 1
source cache.tcl
source function_util.tcl
namespace eval ::ebuild2pisi {
#Parse Ebuild to Actions.py
proc Parse {} {
global xsetup xbuild xinstall xkde xconfopt xbashvar xbashlocalvar xWorkDir
global xDescription xHomepage xDependency xRDependency xLicense xSourcePath xPatch
global gline gCommandLineList xFunctionDefinitions gPkgZipName gEbuildFile
set gPkgZipName ""; set Inherit ""; set xbashvar ""; set xbashlocalvar ""
::ebuild::OpenEbuildFile
while { [::ebuild::GetNewLine] >= 0 } {
::bash::ParseVariable
if {[::bash::Parse_Inherit $gline] != -1} {set Inherit [::bash::Parse_Inherit $gline]}
if {[::bash::Parse_PkgZipName $gline] != -1} {set gPkgZipName [::bash::Parse_PkgZipName $gline]}
}
::ebuild::CloseEbuildFile
::menu::SellectIUSEexception
# set initial values
set xsetup "";set xbuild "";set xinstall "";set xkde "";set xconfopt "";set xWorkDir "";set xbashvar ""
set xFunctionDefinitions "";set xDescription "";set xHomepage "";set xDependency "";set xRDependency ""
set xLicense "";set xSourcePath "";set xPatch "";set xbashvar "";set xbashlocalvar ""
::bash::GetGentooVariables
file mkdir "eclass"
cd "eclass"
#Interpret eclass files
foreach Eclass $Inherit {
if {[::ebuild::CopyAndOpenEclassFile $Eclass]} {
while { [::ebuild::GetNewLine] >= 0 } {
#get Variable Assignments
::bash::ParseVariable
#get function definitions
::bash::ParseFunctionDefinition
}
::ebuild::CloseEclassFile
}
}
cd ".."
#Intepret ebuild file
PutMessage [format "[uplevel #0 {set MSG_eclass_parsing}]" "$gEbuildFile"]
::ebuild::OpenEbuildFile
while { [::ebuild::GetNewLine] >= 0 } {
#get Variable Assignments
::bash::ParseVariable
#get function definitions
::bash::ParseFunctionDefinition
}
::ebuild::CloseEbuildFile
RunFunctionDefinition "pkg_setup"
::cache::Disable
RunFunctionDefinition "pkg_nofetch"
RunFunctionDefinition "src_unpack"
::cache::Enable
RunFunctionDefinition "src_compile"
RunFunctionDefinition "src_install"
#RunFunctionDefinition "src_test"
#RunFunctionDefinition "pkg_preinst"
#RunFunctionDefinition "pkg_postinst"
#RunFunctionDefinition "pkg_prerm"
#RunFunctionDefinition "pkg_postrm"
RunFunctionDefinition "pkg_config"
set xinstall [::cache::Get]
set Dodoc [::bash::GetValue DOCS]
if {$Dodoc != "" } {
regsub -all " " $Dodoc "\",\"" Dodoc
regsub -all "\"" $Dodoc "" Dodoc
set xinstall "$xinstall pisitools.dodoc(\"$Dodoc\")\n"
}
if {$xconfopt != ""} {set xsetup " autotools.configure($xconfopt)\n$xsetup"}
set xWorkDir [::bash::GetValue "S"]
regsub "/?$" $xWorkDir "/" xWorkDir
if {$xWorkDir == "/"} {set xWorkDir ""}
regsub -all "( |^)\[^ ]*/" [::bash::GetValue "PATCHES"] "\\1" xPatch
set xDescription [::bash::GetValue DESCRIPTION]
set xHomepage [::bash::GetValue HOMEPAGE]
set xLicense [::bash::GetValue LICENSE]
set xSourcePath [::bash::GetValue SRC_URI]
if { $xSourcePath != "" } {
foreach a $xSourcePath { if {[regexp "\.tar\." $a]} break }
set xSourcePath $a
regsub "^mirror:" $xSourcePath "mirrors:" xSourcePath
}
set xRDependency [::dependency::GetDependencies "[::bash::GetValue RDEPEND] [::bash::GetValue BOTH_DEPEND]"]
set xDependency [::dependency::GetDependencies "[::bash::GetValue DEPEND] [::bash::GetValue BOTH_DEPEND]"]
}
proc RunCodeBlock {Body} {
global xbashlocalvar gline gByPassIf gRet
set gRet 1
if {$Body == ""} {return ""}
set MyOutput ""
::cache::ResetUnknownCF
foreach {gline} $Body {
# CheckFunctionSeperators : function seperators && || ; ...
::bash::CheckFunctionSeperators $gline
::cache::StatusPut
while {[set flist [::bash::GetNextFunction]] != "~~-1~~"} {
if {[lindex $flist 0] == "return"} {
if {[lindex $flist 1] != "0"} {set gRet 0}
::cache::StatusPush
return $MyOutput
}
if {[ByPassIf $flist]} continue
if {[ByPassElse $flist]} continue
#Pilonga defined functions..
if {[::func::FunctionAvailable $flist]} {
set MyOutput "[::func::RunFunction $flist]$MyOutput"
continue
}
#Ebuild defined functions..
if {[::bash::IsFunctionDefined [lindex $flist 0]]} {
set my_local $xbashlocalvar
#prevent recursive callings
set fname [::bash::GetValue 0]
set fname2 [lindex $flist 0]
if {$fname == $fname2} continue
set MyOutput "[::ebuild2pisi::RunFunctionDefinition $flist]$MyOutput"
set xbashlocalvar $my_local
continue
}
::cache::SetUnknownCF
}
::cache::StatusPush
}
return $MyOutput
}
proc RunFunctionDefinition {FunctionList} {
global xbashlocalvar gRet
set gRet 1
set MyOutput ""
::profil::FuncNamePut $FunctionList
::profil::FuncNameListPrint
SetInitialLocalVariables $FunctionList
set Body [::bash::GetFunctionBody [lindex $FunctionList 0]]
set MyOutput [::ebuild2pisi::RunCodeBlock $Body]
PrintLocalVar [lindex $FunctionList 0]
set xbashlocalvar ""
::profil::FuncNamePush
::profil::FuncNameListPrint
return $MyOutput
}
proc SetInitialLocalVariables {FunctionList} {
global xbashlocalvar
set Num 0
set xbashlocalvar ""
foreach Param $FunctionList {
set xbashlocalvar [linsert $xbashlocalvar end $Num $Param]
incr Num
}
set Num [llength $FunctionList]
set xbashlocalvar [linsert $xbashlocalvar end "\\*" [lrange $FunctionList 1 end] "@" [lrange $FunctionList 1 end] "#" $Num]
}
proc ByPassIf {flist} {
global gRet gByPassIf gIfNum
if {[lindex $flist 0] == "then" && $gRet == 0 && $gByPassIf == 0} {
set gByPassIf 1
return 1
}
if {$gByPassIf == 0} {return 0}
if {[lindex $flist 0] == "if"} {incr gIfNum}
if {[lindex $flist 0] == "fi"} {incr gIfNum -1}
if {[lindex $flist 0] == "else" && $gIfNum == 0} {set gByPassIf 0}
if {$gIfNum == "-1"} {
set gByPassIf 0
set gIfNum 0
return 0
}
return 1
}
proc ByPassElse {flist} {
global gByPassElse gIfNum
if {[lindex $flist 0] == "else" && $gByPassElse == 0} {
set gByPassElse 1
return 1
}
if {$gByPassElse == 0} {return 0}
if {[lindex $flist 0] == "if"} {incr gIfNum}
if {[lindex $flist 0] == "fi"} {incr gIfNum -1}
if {$gIfNum == "-1"} {
set gByPassElse 0
set gIfNum 0
return 0
}
return 1
}
}