-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.php
executable file
·56 lines (49 loc) · 1.15 KB
/
gen.php
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
<?php
/**
* generates the classes from 'proto_def' to 'proto_gen'
* @author Galen Lin
*/
require_once("parser/pb_parser.php");
function parseAll() {
$in = "proto_def";
$out = "proto_gen";
$dir = dir($in);
if (!is_dir($out)) {
if (!mkdir($out)) {
echo("Failed to create ouput directory.\n");
return;
}
}
$parser = new PBParser();
while (($file = $dir->read()) != false) {
$pathInfo = pathInfo($file);
$ext = $pathInfo['extension'];
if ($ext == 'proto') {
// Parse '*.proto' files in `proto_def` directory.
$inFile = $in . '/' . $file;
$types = array('php', 'java', 'objc');
echo("Parsing \"" . $file . "\"...\n");
foreach ($types as $type) {
$outDir = $out . '/' . $type;
if (!is_dir($outDir)) {
if (!mkdir($outDir)) {
echo("[FAILED] (mkdir error)\n");
return;
}
}
echo " - " . $type;
if ($type === 'php') {
// Generate source by `pb_parser`
$parser->parse($inFile, $outDir);
} else {
// Generate source by `protoc`
shell_exec('./gen.sh ' . $inFile . ' ' . $type . ' ' . $outDir);
}
echo("\t[ OK ]\n");
}
}
}
$dir->close();
}
parseAll();
?>