Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 723012: fix jetpackID which accidentally changed in 1.4 . r=mhammond
Browse files Browse the repository at this point in the history
This removes the code in packaging.py which accidentally override the code in
__init__.py which converts package.json:id into
harness-options.json:jetpackID . The consequence of that override was that a
"@jetpack" suffix was not appended when necessary, which caused "jetpackID"
to be wrong in 1.4, which caused simple-storage to look in the wrong place
for its saved data.

This also changes the build_xpi() convenience method (used by a couple tests)
to include the id-to-jetpackID conversion step. The lack of that conversion
step is what prompted the addition to packaging.py, as it was the quickest
way to get the tests to pass at the time.

The simple-prefs tests have been enhanced, and new tests were added to assert
that the id-to-jetpackID conversion happens properly for both "jid" and
"jid@jetpack" (i.e. with and without suffix-adding).

Cherry-picked from master: 582a8ea and b1dbb63
  • Loading branch information
KWierso committed Feb 3, 2012
1 parent 4bc2bdb commit 34d7cf8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
17 changes: 10 additions & 7 deletions python-lib/cuddlefish/__init__.py
Expand Up @@ -472,6 +472,15 @@ def get_unique_prefix(jid):

return unique_prefix

def buildJID(target_cfg, harness_guid):
if "id" in target_cfg:
jid = target_cfg["id"]
else:
jid = harness_guid
if not ("@" in jid or jid.startswith("{")):
jid = jid + "@jetpack"
return jid

def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
defaults=None, env_root=os.environ.get('CUDDLEFISH_ROOT'),
stdout=sys.stdout):
Expand Down Expand Up @@ -612,13 +621,7 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
else:
assert command == "test"

if "id" in target_cfg:
jid = target_cfg["id"]
else:
jid = harness_guid
if not ("@" in jid or jid.startswith("{")):
jid = jid + "@jetpack"

jid = buildJID(target_cfg, harness_guid)

targets = [target]
if command == "test":
Expand Down
3 changes: 0 additions & 3 deletions python-lib/cuddlefish/packaging.py
Expand Up @@ -333,9 +333,6 @@ def add_dep_to_build(dep):
if ('preferences' in target_cfg):
build['preferences'] = target_cfg.preferences

if ('id' in target_cfg):
build['jetpackID'] = target_cfg.id

return build

def _get_files_in_dir(path):
Expand Down
1 change: 1 addition & 0 deletions python-lib/cuddlefish/tests/linker-files/one/package.json
@@ -1,3 +1,4 @@
{ "name": "one",
"id": "jid1@jetpack",
"main": "main"
}
@@ -1,4 +1,4 @@
{
"name": "seven",
"id": "jid1"
"id": "jid7"
}
@@ -1,3 +1,6 @@
{
"loader": "lib/main.js"
"id": "jid1-fZHqN9JfrDBa8A",
"fullName": "No Prefs Test",
"author": "Erik Vold",
"loader": "lib/main.js"
}
37 changes: 37 additions & 0 deletions python-lib/cuddlefish/tests/test_linker.py
Expand Up @@ -2,6 +2,7 @@
import shutil
import zipfile
from StringIO import StringIO
import simplejson as json
import unittest
import cuddlefish
from cuddlefish import packaging, manifest
Expand Down Expand Up @@ -131,6 +132,42 @@ def run_in_subdir(self, dirname, f, *args, **kwargs):
def assertIn(self, what, inside_what):
self.failUnless(what in inside_what, inside_what)

def test_jetpackID(self):
# this uses "id": "jid7", to which a @jetpack should be appended
seven = get_linker_files_dir("seven")
def _test(basedir):
stdout = StringIO()
shutil.copytree(seven, "seven")
os.chdir("seven")
try:
# regrettably, run() always finishes with sys.exit()
cuddlefish.run(["xpi", "--no-strip-xpi"],
stdout=stdout)
except SystemExit, e:
self.failUnlessEqual(e.args[0], 0)
zf = zipfile.ZipFile("seven.xpi", "r")
hopts = json.loads(zf.read("harness-options.json"))
self.failUnlessEqual(hopts["jetpackID"], "jid7@jetpack")
self.run_in_subdir("x", _test)

def test_jetpackID_suffix(self):
# this uses "id": "jid1@jetpack", so no suffix should be appended
one = get_linker_files_dir("one")
def _test(basedir):
stdout = StringIO()
shutil.copytree(one, "one")
os.chdir("one")
try:
# regrettably, run() always finishes with sys.exit()
cuddlefish.run(["xpi", "--no-strip-xpi"],
stdout=stdout)
except SystemExit, e:
self.failUnlessEqual(e.args[0], 0)
zf = zipfile.ZipFile("one.xpi", "r")
hopts = json.loads(zf.read("harness-options.json"))
self.failUnlessEqual(hopts["jetpackID"], "jid1@jetpack")
self.run_in_subdir("x", _test)

def test_strip_default(self):
seven = get_linker_files_dir("seven")
# now run 'cfx xpi' in that directory, except put the generated .xpi
Expand Down
19 changes: 15 additions & 4 deletions python-lib/cuddlefish/tests/test_xpi.py
Expand Up @@ -3,9 +3,10 @@
import zipfile
import pprint
import shutil
import uuid

import simplejson as json
from cuddlefish import xpi, packaging, manifest
from cuddlefish import xpi, packaging, manifest, buildJID
from cuddlefish.tests import test_packaging
from test_linker import up

Expand Down Expand Up @@ -34,11 +35,20 @@ def tearDown(self):

def testPackageWithSimplePrefs(self):
self.makexpi('simple-prefs')
assert 'options.xul' in self.xpi.namelist()
self.failUnless('options.xul' in self.xpi.namelist())
prefs = self.xpi.read('options.xul')
self.failUnless('pref="extensions.jid1-fZHqN9JfrDBa8A@jetpack.test"'
in prefs, prefs)
self.failUnless('type="bool"' in prefs, prefs)
self.failUnless('title="test"' in prefs, prefs)
self.failUnlessEqual(self.xpi_harness_options["jetpackID"],
"jid1-fZHqN9JfrDBa8A@jetpack")

def testPackageWithNoPrefs(self):
self.makexpi('no-prefs')
assert 'options.xul' not in self.xpi.namelist()
self.failIf('options.xul' in self.xpi.namelist())
self.failUnlessEqual(self.xpi_harness_options["jetpackID"],
"jid1-fZHqN9JfrDBa8A@jetpack")


class Bug588119Tests(unittest.TestCase):
Expand Down Expand Up @@ -272,7 +282,8 @@ def document_dir_files(path):
def create_xpi(xpiname, pkg_name='aardvark', dirname='static-files',
extra_harness_options={}):
configs = test_packaging.get_configs(pkg_name, dirname)
options = {'main': configs.target_cfg.main}
options = {'main': configs.target_cfg.main,
'jetpackID': buildJID(configs.target_cfg, str(uuid.uuid4())), }
options.update(configs.build)
xpi.build_xpi(template_root_dir=xpi_template_path,
manifest=fake_manifest,
Expand Down

0 comments on commit 34d7cf8

Please sign in to comment.