Skip to content

Commit

Permalink
Extracted Mako compilation to separate .py files.
Browse files Browse the repository at this point in the history
This breaks out some of the parts on servo#10586, that should be easily mergeable. The idea would be to let you review & merge it first, and then I'll complete the other PR rebase off of this stuff.
  • Loading branch information
perlun committed Apr 14, 2016
1 parent 4807dad commit 5658212
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
14 changes: 1 addition & 13 deletions components/style/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,7 @@ fn main() {
.env("PYTHONPATH", &mako)
.env("TEMPLATE", &template)
.env("PRODUCT", product)
.arg("-c")
.arg(r#"
import os
import sys
from mako.template import Template
from mako import exceptions
try:
template = Template(open(os.environ['TEMPLATE'], 'rb').read(), input_encoding='utf8')
print(template.render(PRODUCT=os.environ['PRODUCT']).encode('utf8'))
except:
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
sys.exit(1)
"#)
.arg("generate_properties_rs.py")
.stderr(Stdio::inherit())
.output()
.unwrap();
Expand Down
14 changes: 14 additions & 0 deletions components/style/generate_properties_rs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys

from mako import exceptions
from mako.lookup import TemplateLookup
from mako.template import Template

try:
template = Template(open(os.environ['TEMPLATE'], 'rb').read(),
input_encoding='utf8')
print(template.render(PRODUCT=os.environ['PRODUCT']).encode('utf8'))
except:
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
sys.exit(1)
20 changes: 1 addition & 19 deletions ports/geckolib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,7 @@ fn main() {
.env("PYTHONPATH", &mako)
.env("STYLE_TEMPLATE", &style_template)
.env("GECKOLIB_TEMPLATE", &geckolib_template)
.arg("-c")
.arg(r#"
import json
import os
import sys
from mako.template import Template
from mako import exceptions
try:
style_template = Template(filename=os.environ['STYLE_TEMPLATE'], input_encoding='utf8')
style_template.render(PRODUCT='gecko')
geckolib_template = Template(filename=os.environ['GECKOLIB_TEMPLATE'], input_encoding='utf8')
output = geckolib_template.render(STYLE_STRUCTS = style_template.module.STYLE_STRUCTS,
to_rust_ident = style_template.module.to_rust_ident)
print(output.encode('utf8'))
except:
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
sys.exit(1)
"#)
.arg("ports/geckolib/generate_properties_rs.py")
.stderr(Stdio::inherit())
.output()
.unwrap();
Expand Down
20 changes: 20 additions & 0 deletions ports/geckolib/generate_properties_rs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json
import os
import sys

from mako import exceptions
from mako.lookup import TemplateLookup
from mako.template import Template

try:
style_template = Template(filename=os.environ['STYLE_TEMPLATE'],
input_encoding='utf8')
style_template.render(PRODUCT='gecko')

geckolib_template = Template(filename=os.environ['GECKOLIB_TEMPLATE'], input_encoding='utf8')
output = geckolib_template.render(STYLE_STRUCTS = style_template.module.STYLE_STRUCTS,
to_rust_ident = style_template.module.to_rust_ident)
print(output.encode('utf8'))
except:
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
sys.exit(1)

0 comments on commit 5658212

Please sign in to comment.