forked from facebook/buck
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for whether the soy docs compile
Summary: This adds a script which runs the plovr build to check soy doc syntax. Test Plan: 1. Make sure `ant verify-soydoc; buck test //docs:` succeed, 2. Introduce syntax error into rust_binary.soy 3. Make sure commands from 1. fail Reviewed By: mjpieters fbshipit-source-id: a969c40
- Loading branch information
1 parent
13b9e5e
commit 4c83fb7
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
python_test( | ||
name='soy_docs_syntax', | ||
srcs = [ | ||
'soy_syntax_check.py', | ||
], | ||
resources = glob(['**/*.soy', '*.jar']), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
# | ||
# This script runs the plovr build to make sure none of the soy files | ||
# have syntax errors. | ||
|
||
import json | ||
import os | ||
import subprocess | ||
import tempfile | ||
import unittest | ||
|
||
PLOVR_JAR = 'plovr-81ed862.jar' | ||
|
||
|
||
def find_docs_dir(): | ||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
prev_cwd = None | ||
while cwd != prev_cwd: | ||
if os.path.exists(os.path.join(cwd, 'docs', PLOVR_JAR)): | ||
return os.path.join(cwd, 'docs') | ||
prev_cwd = cwd | ||
cwd = os.path.dirname(cwd) | ||
raise Exception('Could not find plovr jar') | ||
|
||
|
||
def main(): | ||
docs_dir = find_docs_dir() | ||
input_files = [] | ||
for root, dirs, files in os.walk(docs_dir): | ||
for file_name in files: | ||
if file_name.endswith('.soy') and not file_name.startswith('__'): | ||
input_files.append(os.path.join(root, file_name)) | ||
print('Building %s soy files.' % len(input_files)) | ||
config_data = { | ||
'id': 'buck', | ||
# This removes the warning about param being a reserved JS keyword. | ||
'experimental-compiler-options': { | ||
'languageIn': 'ECMASCRIPT5', | ||
}, | ||
'paths': docs_dir, | ||
'inputs': input_files, | ||
} | ||
|
||
plovr_abspath = os.path.join(docs_dir, PLOVR_JAR) | ||
fd, config_path = tempfile.mkstemp(suffix='.json', prefix='plovr_config') | ||
try: | ||
with open(config_path, 'w') as config_file: | ||
json.dump(config_data, config_file) | ||
subprocess.check_output([ | ||
'java', '-jar', plovr_abspath, 'build', config_path | ||
]) | ||
finally: | ||
os.close(fd) | ||
os.unlink(config_path) | ||
|
||
|
||
class TestBuckPackage(unittest.TestCase): | ||
def test_no_soy_doc_syntax_error(self): | ||
main() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |