Skip to content

Commit

Permalink
Add check for whether the soy docs compile
Browse files Browse the repository at this point in the history
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
mkosiba authored and facebook-github-bot committed Jan 10, 2017
1 parent 13b9e5e commit 4c83fb7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
8 changes: 7 additions & 1 deletion build.xml
Expand Up @@ -986,7 +986,13 @@
</exec>
</target>

<target name="travis" depends="verify-javadoc, lint" />
<target name="verify-soydoc"
description="verify that soy docs can be generated without errors">
<exec executable="${basedir}/docs/soy_syntax_check.py" failonerror="true">
</exec>
</target>

<target name="travis" depends="verify-javadoc, verify-soydoc, lint" />

<target name="pre-checkin" depends="clean, default, compile-tests, lint"/>
<target name="all" depends="jar, test, javadoc" />
Expand Down
7 changes: 7 additions & 0 deletions docs/BUCK
@@ -0,0 +1,7 @@
python_test(
name='soy_docs_syntax',
srcs = [
'soy_syntax_check.py',
],
resources = glob(['**/*.soy', '*.jar']),
)
63 changes: 63 additions & 0 deletions docs/soy_syntax_check.py
@@ -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()

0 comments on commit 4c83fb7

Please sign in to comment.