Skip to content

Make hack files the default #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ jobs:
# Run tests on all OS's and HHVM versions, even if one fails
fail-fast: false
matrix:
os: [ ubuntu ]
os: [ ubuntu-20.04 ]
hhvm:
- '4.128'
- latest
- nightly
runs-on: ${{matrix.os}}-latest
- '4.153'
- '4.168'
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: hhvm/actions/hack-lint-test@master
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Hack Codegen is a library for programmatically generating Hack code",
"keywords": ["code generation", "Hack"],
"require": {
"hhvm": "^4.128"
"hhvm": "^4.153"
},
"bin": [ "bin/hh-codegen-verify-signatures", "bin/hh-codegen-verify-signatures.hack" ],
"authors": [
Expand Down
14 changes: 13 additions & 1 deletion src/CodegenFile.hack
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ enum CodegenFileType: int {
* depending on whether there are manual sections.
*/
final class CodegenFile {
const vec<string> LEGACY_FILE_SUFFIX_TRIGGERS = vec['.php', '.hh', '.hhi'];

private CodegenFileType $fileType = CodegenFileType::HACK_STRICT;
private CodegenFileType $fileType;
private ?string $docBlock;
private string $fileName;
private string $relativeFileName;
Expand Down Expand Up @@ -63,6 +64,13 @@ final class CodegenFile {
private IHackCodegenConfig $config,
string $file_name,
) {
$this->fileType = C\any(
static::LEGACY_FILE_SUFFIX_TRIGGERS,
$t ==> Str\ends_with($file_name, $t),
)
? CodegenFileType::HACK_STRICT
: CodegenFileType::DOT_HACK;

$root = $config->getRootDir();
if (!Str\starts_with($file_name, '/')) {
$this->relativeFileName = $file_name;
Expand Down Expand Up @@ -186,6 +194,10 @@ final class CodegenFile {
return $this->fileName;
}

public function getFileType()[]: CodegenFileType {
return $this->fileType;
}

public function getRelativeFileName(): string {
return $this->relativeFileName;
}
Expand Down
41 changes: 13 additions & 28 deletions tests/CodegenFileTest.codegen
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
@generated
!@#$%codegentest:testAutogenerated
<?hh // strict
// Codegen Tests
/**
* This file is generated. Do not modify it manually!
*
* Completely autogenerated!
*
* @-generated SignedSource<<e071d07d9cb3a77e37f24ecfc972a120>>
* @-generated SignedSource<<f8c58e9c529a492418b26efdeb95cd60>>
*/

class AllAutogenerated {
Expand All @@ -18,12 +17,11 @@ class AllAutogenerated {
}

!@#$%codegentest:testConstants
<?hh // strict
// Codegen Tests
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<3081d5c20598b6bd1aa52a8035ffd207>>
* @-generated SignedSource<<30f984475edc103094e561bce9e9fdf0>>
*/
namespace Foo\Bar;
use namespace Herp\Derp;
Expand Down Expand Up @@ -67,11 +65,10 @@ function main(): void {
main();

!@#$%codegentest:testFormattingFullyGeneratedFile
<?hh // strict
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<8873291d72dbb45b8a9e70890f7d2f0a>>
* @-generated SignedSource<<f78cdf7e9caaaaf7852fdf8330cf01e3>>
*/

function my_func(
Expand All @@ -85,11 +82,10 @@ function my_func(
}

!@#$%codegentest:testFormattingFullyGeneratedFileWithOptions
<?hh // strict
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<edb2ec6abbf7356621b98a5eac852996>>
* @-generated SignedSource<<f452b14a6164d435250f4c0088df8a86>>
*/

function my_func(
Expand All @@ -103,11 +99,10 @@ function my_func(
}

!@#$%codegentest:testFormattingFullyGeneratedFileWithTabs
<?hh // strict
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<763ad93f9a1a4caf70638a8de8786e49>>
* @-generated SignedSource<<f272aec490e6b17c15f61974e37838aa>>
*/

function my_func(
Expand All @@ -118,12 +113,11 @@ function my_func(
}

!@#$%codegentest:testFormattingPartiallyGeneratedFile
<?hh // strict
/**
* This file is partially generated. Only make modifications between BEGIN
* MANUAL SECTION and END MANUAL SECTION designators.
*
* @-partially-generated SignedSource<<a6295bf3f813f9420063cf2da7478571>>
* @-partially-generated SignedSource<<3a7ef07d733ea4f3aa8c9d947d64c28e>>
*/

function my_func(
Expand All @@ -139,7 +133,6 @@ function my_func(
}

!@#$%codegentest:testFormattingUnsignedFile
<?hh // strict

function my_func(
string $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
Expand All @@ -152,12 +145,11 @@ function my_func(
}

!@#$%codegentest:testGenerateEnums
<?hh // strict
// Codegen Tests
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<9627a8d7e6cf7a65a9bf2ad85d657e03>>
* @-generated SignedSource<<4c9d48e406a74cd17064ea2ebcd0492f>>
*/


Expand All @@ -167,25 +159,23 @@ enum TestEnum : int {
}

!@#$%codegentest:testGenerateTopLevelFunctions
<?hh // strict
// Codegen Tests
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<36d9f7267f98197421aa97d0c84ca8f5>>
* @-generated SignedSource<<e081255cf9acdc95f2d7546affae7685>>
*/

function fun(): int {
return 0;
}

!@#$%codegentest:testNamespace
<?hh // strict
// Codegen Tests
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<962f609e88de287eef0d9c8eb42c6fce>>
* @-generated SignedSource<<1e82f55cc7df937c367b4936f57d25b3>>
*/
namespace MyNamespace;
use namespace Another\Space;
Expand All @@ -197,7 +187,6 @@ class Foo {
}

!@#$%codegentest:testNoSignature
<?hh // strict
// Codegen Tests
/**
* Completely autogenerated!
Expand All @@ -211,13 +200,12 @@ class NoSignature {
}

!@#$%codegentest:testPartiallyGenerated
<?hh // strict
// Codegen Tests
/**
* This file is partially generated. Only make modifications between BEGIN
* MANUAL SECTION and END MANUAL SECTION designators.
*
* @-partially-generated SignedSource<<f45c8764e5eddd1d8ce7cb55633a7810>>
* @-partially-generated SignedSource<<4ac3ec3e124eaa6cf732ab42f6ecbc49>>
*/

class PartiallyGenerated {
Expand Down Expand Up @@ -248,14 +236,13 @@ class Foo {
}

!@#$%codegentest:testSaveAutogenerated
<?hh // strict
// Codegen Tests
/**
* This file is generated. Do not modify it manually!
*
* Testing CodegenFile with autogenerated files
*
* @-generated SignedSource<<6a105a3097cde1632d78096f693751c6>>
* @-generated SignedSource<<624100da9e208d6abeaa301bce015bfd>>
*/

class Demo {
Expand All @@ -266,15 +253,14 @@ class Demo {
}

!@#$%codegentest:testSavePartiallyGenerated
<?hh // strict
// Codegen Tests
/**
* This file is partially generated. Only make modifications between BEGIN
* MANUAL SECTION and END MANUAL SECTION designators.
*
* Testing CodegenFile with partially generated files
*
* @-partially-generated SignedSource<<500fa4945d39860935bb0c92a72477a0>>
* @-partially-generated SignedSource<<e0a4ec17c8e71c803d34407363ca8af6>>
*/

class Demo {
Expand All @@ -287,12 +273,11 @@ class Demo {
}

!@#$%codegentest:testStrictFile
<?hh // strict
// Codegen Tests
/**
* This file is generated. Do not modify it manually!
*
* @-generated SignedSource<<5c0182dcd097a22f08d4dfbcc555c52c>>
* @-generated SignedSource<<d1d6954e25b8c7fb2bf045bede5f356b>>
*/

class Foo {
Expand Down
Loading