Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 609ddb1

Browse files
committed
.hack-ify, fix, and test hh-codegen-verify-signatures
1 parent 1226a67 commit 609ddb1

File tree

4 files changed

+116
-110
lines changed

4 files changed

+116
-110
lines changed

.travis.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ if !(hhvm --version | grep -q -- -dev); then
2121
vendor/bin/hhast-lint
2222
fi
2323

24+
bin/hh-codegen-verify-signatures \
25+
examples/dorm/demo/{DormUser.php,DormUserMutator.php}
2426
hhvm examples/dorm/codegen.hack examples/dorm/demo/DormUserSchema.php
2527
if ! git diff --exit-code examples/; then
2628
echo "Demo codegen not up to date."

bin/hh-codegen-verify-signatures

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,2 @@
1-
#!/usr/bin/env hhvm
2-
<?hh
3-
/*
4-
* Copyright (c) 2015-present, Facebook, Inc.
5-
* All rights reserved.
6-
*
7-
* This source code is licensed under the MIT license found in the
8-
* LICENSE file in the root directory of this source tree.
9-
*
10-
*/
11-
12-
namespace Facebook\HackCodegen;
13-
14-
use namespace HH\Lib\{C, Vec};
15-
16-
$dir = __DIR__;
17-
while (true) {
18-
if (file_exists($dir.'/hh_autoload.php')) {
19-
require_once($dir.'/hh_autoload.php');
20-
break;
21-
}
22-
if (file_exists($dir.'/vendor/hh_autoload.php')) {
23-
require_once($dir.'/vendor/hh_autoload.php');
24-
break;
25-
}
26-
27-
if ($dir === '') {
28-
fwrite(STDERR, "Failed to find autoloader\n");
29-
exit(1);
30-
}
31-
32-
$pos = strrpos($dir, '/');
33-
if ($pos === false) {
34-
$dir = '';
35-
continue;
36-
}
37-
38-
$dir = substr($dir, 0, $pos);
39-
}
40-
41-
final class CLIVerifier {
42-
private vec<string> $targets;
43-
44-
public function __construct(
45-
private vec<string> $argv,
46-
) {
47-
$this->targets = Vec\drop($argv, 1);
48-
}
49-
50-
private function verifyFile(string $path): bool {
51-
$code = file_get_contents($path);
52-
if (!SignedSourceBase::isSignedByAnySigner($code)) {
53-
return true;
54-
}
55-
$ok = SignedSourceBase::hasValidSignatureFromAnySigner($code);
56-
if ($ok) {
57-
printf("OK: %s\n", $path);
58-
} else {
59-
fprintf(STDERR, "MODIFIED: %s\n", $path);
60-
}
61-
return $ok;
62-
}
63-
64-
private function verifyDirectory(string $path): bool {
65-
$it = new \RecursiveIteratorIterator(
66-
new \RecursiveDirectoryIterator($path),
67-
);
68-
$good = true;
69-
foreach ($it as $info) {
70-
if (!$info->isFile()) {
71-
continue;
72-
}
73-
$good_file = $this->verifyFile($info->getPathname());
74-
$good = $good && $good_file;
75-
}
76-
return $good;
77-
}
78-
79-
public function main(): void {
80-
if (C\is_empty($this->targets)) {
81-
fprintf(STDERR, "Usage: %s path [path ...]\n", $this->argv[0]);
82-
}
83-
$files = vec[];
84-
$dirs = vec[];
85-
foreach ($this->targets as $target) {
86-
if (is_file($target)) {
87-
$files[] = $target;
88-
} else if (is_dir($target)) {
89-
$dirs[] = $target;
90-
} else {
91-
fprintf(STDERR, "Don't know how to handler arg '%s'\n", $target);
92-
exit(1);
93-
}
94-
}
95-
96-
$good = true;
97-
foreach ($files as $file) {
98-
$good_file = $this->verifyFile($file);
99-
$good = $good && $good_file;
100-
}
101-
foreach ($dirs as $dir) {
102-
$good_dir = $this->verifyDirectory($dir);
103-
$good = $good && $good_dir;
104-
}
105-
exit($good ? 0 : 1);
106-
}
107-
}
108-
109-
(new CLIVerifier(vec($argv)))->main();
1+
#!/bin/sh
2+
exec "$0.hack" "$@"
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env hhvm
2+
/*
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
* All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*
9+
*/
10+
11+
namespace Facebook\HackCodegen;
12+
13+
use namespace HH\Lib\{C, Vec};
14+
15+
final class CLIVerifier {
16+
private vec<string> $targets;
17+
18+
public function __construct(
19+
private vec<string> $argv,
20+
) {
21+
$this->targets = Vec\drop($argv, 1);
22+
}
23+
24+
private function verifyFile(string $path): bool {
25+
$code = \file_get_contents($path);
26+
if (!SignedSourceBase::isSignedByAnySigner($code)) {
27+
return true;
28+
}
29+
$ok = SignedSourceBase::hasValidSignatureFromAnySigner($code);
30+
if ($ok) {
31+
\printf("OK: %s\n", $path);
32+
} else {
33+
\fprintf(\STDERR, "MODIFIED: %s\n", $path);
34+
}
35+
return $ok;
36+
}
37+
38+
private function verifyDirectory(string $path): bool {
39+
$it = new \RecursiveIteratorIterator(
40+
new \RecursiveDirectoryIterator($path),
41+
);
42+
$good = true;
43+
foreach ($it as $info) {
44+
if (!$info->isFile()) {
45+
continue;
46+
}
47+
$good_file = $this->verifyFile($info->getPathname());
48+
$good = $good && $good_file;
49+
}
50+
return $good;
51+
}
52+
53+
public function main(): noreturn {
54+
if (C\is_empty($this->targets)) {
55+
\fprintf(\STDERR, "Usage: %s path [path ...]\n", $this->argv[0]);
56+
}
57+
$files = vec[];
58+
$dirs = vec[];
59+
foreach ($this->targets as $target) {
60+
if (\is_file($target)) {
61+
$files[] = $target;
62+
} else if (\is_dir($target)) {
63+
$dirs[] = $target;
64+
} else {
65+
\fprintf(\STDERR, "Don't know how to handle arg '%s'\n", $target);
66+
exit(1);
67+
}
68+
}
69+
70+
$good = true;
71+
foreach ($files as $file) {
72+
$good_file = $this->verifyFile($file);
73+
$good = $good && $good_file;
74+
}
75+
foreach ($dirs as $dir) {
76+
$good_dir = $this->verifyDirectory($dir);
77+
$good = $good && $good_dir;
78+
}
79+
exit($good ? 0 : 1);
80+
}
81+
}
82+
83+
<<__EntryPoint>>
84+
function verify_signatures_main(): noreturn {
85+
$dir = __DIR__;
86+
while (true) {
87+
if (\file_exists($dir.'/hh_autoload.php')) {
88+
require_once($dir.'/hh_autoload.php');
89+
break;
90+
}
91+
if (\file_exists($dir.'/vendor/hh_autoload.php')) {
92+
require_once($dir.'/vendor/hh_autoload.php');
93+
break;
94+
}
95+
96+
if ($dir === '') {
97+
\fwrite(\STDERR, "Failed to find autoloader\n");
98+
exit(1);
99+
}
100+
101+
$pos = \strrpos($dir, '/');
102+
if ($pos === false) {
103+
$dir = '';
104+
continue;
105+
}
106+
107+
$dir = \substr($dir, 0, $pos);
108+
}
109+
(new CLIVerifier(vec(/* HH_IGNORE_ERROR[2050] */ $GLOBALS['argv'])))->main();
110+
exit(0);
111+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"hhvm/hhvm-autoload": "^2.0",
88
"hhvm/hsl": "^4.0"
99
},
10-
"bin": [ "bin/hh-codegen-verify-signatures" ],
10+
"bin": [ "bin/hh-codegen-verify-signatures", "bin/hh-codegen-verify-signatures.hack" ],
1111
"authors": [
1212
{
1313
"name": "Fred Emmott",

0 commit comments

Comments
 (0)