Skip to content
This repository has been archived by the owner on Jul 3, 2018. It is now read-only.

Commit

Permalink
Bug 1304125 - Perform WebIDL code generation in the tup backend; r=gps
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: Fnw8380zyGU

--HG--
extra : rebase_source : 4cad1fc9699260ce2dd25530060596de51212deb
  • Loading branch information
mshal committed Sep 19, 2016
1 parent 8e6635d commit 366bb17
Showing 1 changed file with 70 additions and 5 deletions.
75 changes: 70 additions & 5 deletions python/mozbuild/mozbuild/backend/tup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from .common import CommonBackend
from ..frontend.data import (
ContextDerived,
Defines,
GeneratedFile,
HostDefines,
)
from ..util import (
FileAvoidWrite,
Expand All @@ -35,6 +37,8 @@ def __init__(self, srcdir, objdir, environment, topsrcdir, topobjdir):
self.name = mozpath.join(objdir, 'Tupfile')
self.rules_included = False
self.shell_exported = False
self.defines = []
self.host_defines = []

self.fh = FileAvoidWrite(self.name, capture_diff=True)
self.fh.write('# THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT.\n')
Expand All @@ -48,13 +52,26 @@ def include_rules(self):
self.write('include_rules\n')
self.rules_included = True

def rule(self, cmd, inputs=None, outputs=None, display=None, extra_outputs=None):
def rule(self, cmd, inputs=None, outputs=None, display=None, extra_outputs=None, check_unchanged=False):
inputs = inputs or []
outputs = outputs or []
display = display or ""
self.include_rules()
flags = ""
if check_unchanged:
# This flag causes tup to compare the outputs with the previous run
# of the command, and skip the rest of the DAG for any that are the
# same.
flags += "o"

if display:
caret_text = flags + ' ' + display
else:
caret_text = flags

self.write(': %(inputs)s |> %(display)s%(cmd)s |> %(outputs)s%(extra_outputs)s\n' % {
'inputs': ' '.join(inputs),
'display': '^ %s^ ' % display if display else '',
'display': '^%s^ ' % caret_text if caret_text else '',
'cmd': ' '.join(cmd),
'outputs': ' '.join(outputs),
'extra_outputs': ' | ' + ' '.join(extra_outputs) if extra_outputs else '',
Expand Down Expand Up @@ -151,6 +168,10 @@ def consume_object(self, obj):
inputs=full_inputs,
outputs=outputs,
)
elif isinstance(obj, Defines):
self._process_defines(backend_file, obj)
elif isinstance(obj, HostDefines):
self._process_defines(backend_file, obj, host=True)

return True

Expand Down Expand Up @@ -184,6 +205,14 @@ def consume_finished(self):
tup = self.environment.substs.get('TUP', 'tup')
self._cmd.run_process(cwd=self.environment.topsrcdir, log_name='tup', args=[tup, 'init'])

def _process_defines(self, backend_file, obj, host=False):
defines = list(obj.get_defines())
if defines:
if host:
backend_file.host_defines = defines
else:
backend_file.defines = defines

def _handle_idl_manager(self, manager):
backend_file = self._get_backend_file('xpcom/xpidl')
backend_file.export_shell()
Expand Down Expand Up @@ -216,6 +245,18 @@ def _handle_idl_manager(self, manager):
outputs=outputs,
)

def _preprocess(self, backend_file, input_file):
cmd = self._py_action('preprocessor')
cmd.extend(backend_file.defines)
cmd.extend(['$(ACDEFINES)', '%f', '-o', '%o'])

backend_file.rule(
inputs=[input_file],
display='Preprocess %o',
cmd=cmd,
outputs=[mozpath.basename(input_file)],
)

def _handle_ipdl_sources(self, ipdl_dir, sorted_ipdl_sources,
unified_ipdl_cppsrcs_mapping):
# TODO: This isn't implemented yet in the tup backend, but it is called
Expand All @@ -225,9 +266,33 @@ def _handle_ipdl_sources(self, ipdl_dir, sorted_ipdl_sources,
def _handle_webidl_build(self, bindings_dir, unified_source_mapping,
webidls, expected_build_output_files,
global_define_files):
# TODO: This isn't implemented yet in the tup backend, but it is called
# by the CommonBackend.
pass
backend_file = self._get_backend_file('dom/bindings')
backend_file.export_shell()

for source in sorted(webidls.all_preprocessed_sources()):
self._preprocess(backend_file, source)

cmd = self._py_action('webidl')
cmd.append(mozpath.join(self.environment.topsrcdir, 'dom', 'bindings'))

# The WebIDLCodegenManager knows all of the .cpp and .h files that will
# be created (expected_build_output_files), but there are a few
# additional files that are also created by the webidl py_action.
outputs = [
'_cache/webidlyacc.py',
'codegen.json',
'codegen.pp',
'parser.out',
]
outputs.extend(expected_build_output_files)

backend_file.rule(
display='WebIDL code generation',
cmd=cmd,
inputs=webidls.all_non_static_basenames(),
outputs=outputs,
check_unchanged=True,
)


class TupBackend(HybridBackend(TupOnly, RecursiveMakeBackend)):
Expand Down

0 comments on commit 366bb17

Please sign in to comment.