Skip to content

Commit

Permalink
Merge pull request mozilla#1530 from zombie/1032275-ignore-missing
Browse files Browse the repository at this point in the history
bug 1032275 - cfx to ignore missing modules by default, r=@Gozala
  • Loading branch information
zombie committed Jul 8, 2014
2 parents 47eac11 + 0c597e6 commit c5177e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
14 changes: 10 additions & 4 deletions python-lib/cuddlefish/__init__.py
Expand Up @@ -234,6 +234,11 @@
help="JSON file to overload package.json properties",
default=None,
cmds=['xpi'])),
(("", "--abort-on-missing-module",), dict(dest="abort_on_missing",
help="Abort if required module is missing",
action="store_true",
default=False,
cmds=['test', 'run', 'xpi', 'testpkgs'])),
]
),

Expand Down Expand Up @@ -651,7 +656,8 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
# a Mozilla application (which includes running tests).

use_main = False
inherited_options = ['verbose', 'enable_e10s', 'parseable', 'check_memory']
inherited_options = ['verbose', 'enable_e10s', 'parseable', 'check_memory',
'abort_on_missing']
enforce_timeouts = False

if command == "xpi":
Expand Down Expand Up @@ -746,9 +752,9 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
if ":" in options.filter:
test_filter_re = options.filter.split(":")[0]
try:
manifest = build_manifest(target_cfg, pkg_cfg, deps,
scan_tests, test_filter_re,
loader_modules)
manifest = build_manifest(target_cfg, pkg_cfg, deps, scan_tests,
test_filter_re, loader_modules,
abort_on_missing=options.abort_on_missing)
except ModuleNotFoundError, e:
print str(e)
sys.exit(1)
Expand Down
14 changes: 11 additions & 3 deletions python-lib/cuddlefish/manifest.py
Expand Up @@ -181,7 +181,7 @@ def __repr__(self):

class ManifestBuilder:
def __init__(self, target_cfg, pkg_cfg, deps, extra_modules,
stderr=sys.stderr):
stderr=sys.stderr, abort_on_missing=False):
self.manifest = {} # maps (package,section,module) to ManifestEntry
self.target_cfg = target_cfg # the entry point
self.pkg_cfg = pkg_cfg # all known packages
Expand All @@ -193,6 +193,7 @@ def __init__(self, target_cfg, pkg_cfg, deps, extra_modules,
self.datamaps = {} # maps package name to DataMap instance
self.files = [] # maps manifest index to (absfn,absfn) js/docs pair
self.test_modules = [] # for runtime
self.abort_on_missing = abort_on_missing # cfx eol

def build(self, scan_tests, test_filter_re):
"""
Expand Down Expand Up @@ -416,6 +417,12 @@ def process_module(self, mi):
# test-securable-module.js, and the modules/red.js
# that it imports, both do that intentionally
continue
if not self.abort_on_missing:
# print a warning, but tolerate missing modules
# unless cfx --abort-on-missing-module flag was set
print >>self.stderr, "Warning: missing module: %s" % reqname
me.add_requirement(reqname, reqname)
continue
lineno = locations.get(reqname) # None means define()
if lineno is None:
reqtype = "define"
Expand Down Expand Up @@ -633,7 +640,7 @@ def _find_module_in_package(self, pkgname, sections, name, looked_in):
return None

def build_manifest(target_cfg, pkg_cfg, deps, scan_tests,
test_filter_re=None, extra_modules=[]):
test_filter_re=None, extra_modules=[], abort_on_missing=False):
"""
Perform recursive dependency analysis starting from entry_point,
building up a manifest of modules that need to be included in the XPI.
Expand All @@ -659,7 +666,8 @@ def build_manifest(target_cfg, pkg_cfg, deps, scan_tests,
code which does, so it knows what to copy into the XPI.
"""

mxt = ManifestBuilder(target_cfg, pkg_cfg, deps, extra_modules)
mxt = ManifestBuilder(target_cfg, pkg_cfg, deps, extra_modules,
abort_on_missing=abort_on_missing)
mxt.build(scan_tests, test_filter_re)
return mxt

Expand Down
20 changes: 18 additions & 2 deletions python-lib/cuddlefish/tests/test_linker.py
Expand Up @@ -48,6 +48,7 @@ def test_manifest(self):
def assertReqIs(modname, reqname, path):
reqs = m["one/%s" % modname]["requirements"]
self.failUnlessEqual(reqs[reqname], path)

assertReqIs("main", "sdk/panel", "sdk/panel")
assertReqIs("main", "two.js", "one/two")
assertReqIs("main", "./two", "one/two")
Expand All @@ -57,11 +58,26 @@ def assertReqIs(modname, reqname, path):
assertReqIs("subdir/three", "../main", "one/main")

target_cfg.dependencies = []

try:
# this should now work, as we ignore missing modules by default
m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False)
m = m.get_harness_options_manifest(False)

assertReqIs("main", "sdk/panel", "sdk/panel")
# note that with "addon-sdk" dependency present,
# "sdk/tabs.js" mapped to "sdk/tabs", but without,
# we just get the default (identity) mapping
assertReqIs("main", "sdk/tabs.js", "sdk/tabs.js")
except Exception, e:
self.fail("Must not throw from build_manifest() if modules are missing")

# now, because .dependencies *is* provided, we won't search 'deps',
# so we'll get a link error
# and stop_on_missing is True, we'll get a link error
self.assertRaises(manifest.ModuleNotFoundError,
manifest.build_manifest,
target_cfg, pkg_cfg, deps, scan_tests=False)
target_cfg, pkg_cfg, deps, scan_tests=False,
abort_on_missing=True)

def test_main_in_deps(self):
target_cfg = self.get_pkg("three")
Expand Down

0 comments on commit c5177e0

Please sign in to comment.