-
Notifications
You must be signed in to change notification settings - Fork 1
/
processor.vala
122 lines (104 loc) · 3.84 KB
/
processor.vala
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
/*
* processor.vala
*
* Copyright 2014 Jott <das.jott at gmail com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
public class Processor : GLib.Object
{
public bool run(CmdArgs c)
{
bool ok = false;
try {
if (c.Verbose) { verbose("Getting vala class..."); }
Class oClass = null;
ValaFile oValaFile = null;
foreach (string sVFile in c.VFiles) {
ValaFile oTmpFile = new ValaFile(sVFile);
if (!oTmpFile.isVapi()) {
Class oTmpClass = oTmpFile.parse(c.VClass);
if (oTmpClass != null) {
oClass = oTmpClass;
oValaFile = oTmpFile;
break;
}
}
}
if (oClass != null) {
if (c.Verbose) { verbose("ok :)\nCreating Java file..."); }
var oJavaFile = new JavaFile(c.LibName);
ok = oJavaFile.create(oClass, c.Package, c.PkgDir);
if (ok && c.Verbose) { verbose("ok :)\n"); }
JNIFiles oJniFiles = null;
if (ok) {
if (c.Verbose) { verbose("Creating JNI header..."); }
oJniFiles = new JNIFiles(oClass, c.Package);
ok = oJniFiles.createHeader(oValaFile.getPath());
if (ok && c.Verbose) { verbose("ok :)\n"); }
}
if (ok) {
if (c.Verbose) { verbose("Creating JNI implementation..."); }
ok = oJniFiles.createImplementation(oValaFile.getPath());
if (ok && c.Verbose) { verbose("ok :)\n"); }
}
if (ok) {
if (c.Verbose) { verbose("Make C code from Vala code..."); }
ok = ValaFile.compile2Ccode(oValaFile.getPath(), c.VFiles, c.VPackages, c.ValaCmds, oValaFile.getHeaderName());
if (ok && c.Verbose) { verbose("ok :)\n"); }
}
if (ok && c.Compile) {
if (c.Verbose) { verbose("Compiling sources..."); }
var oGcc = new Compiler(c.Compler, oValaFile.getPath());
ok = oGcc.compile(c.VPackages, c.CompCmds);
if (ok && c.Verbose) { verbose("ok :)\n"); }
if (!c.NotLink) {
if (c.Verbose) { verbose("Link objects to \"lib%s.so\"...", c.LibName); }
ok = oGcc.link(c.LibName, c.VPackages, c.ExtLibs);
if (ok && c.Verbose) { verbose("ok :)\n"); }
}
}
if (ok && c.UseTmp && c.Compile && !c.NotLink) {
if (c.Verbose) { verbose("Copying results from tmp..."); }
string sLibName = "lib%s.so".printf(c.LibName);
var oLibSrc = File.new_for_path( Path.build_filename(oValaFile.getPath(), sLibName) );
var oLibDst = File.new_for_path( Path.build_filename(".", sLibName) );
oLibSrc.copy(oLibDst, FileCopyFlags.OVERWRITE);
if (ok && c.Verbose) { verbose("ok :)\n"); }
}
c.cleanUp(true);
if (!ok) {
if (c.Verbose) { verbose("not ok :(\n"); }
} else {
verbose("\nFinished successfully :)\n");
}
} else {
stderr.printf("Error retrieving class information\n");
}
} catch (Error e) {
stderr.printf("%s\n", e.message);
ok = false;
}
return ok;
}
public static void verbose(string sText, ...)
{
string sPrint = sText.vprintf(va_list());
print(sPrint);
}
}