author | Julien Pagès <j.parkouss@gmail.com> |
Fri, 24 Oct 2014 09:02:29 +0200 | |
changeset 212076 | ac33dde6856caa7bffb3ebe6c5d9d0b7b1845c9e |
parent 212075 | 370a0a1ea55d3af862c896ea171a22348d18cf25 |
child 212077 | d2836e069aef6d8ce2cd6aad02cebcc8a1a3b57e |
push id | 27697 |
push user | cbook@mozilla.com |
push date | Fri, 24 Oct 2014 13:48:53 +0000 |
treeherder | mozilla-central@de805196bbc4 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | dhunt |
bugs | 1065988 |
milestone | 36.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/testing/mozbase/mozversion/mozversion/mozversion.py +++ b/testing/mozbase/mozversion/mozversion/mozversion.py @@ -72,45 +72,44 @@ class LocalFennecVersion(Version): else: self._logger.warning('Unable to find %s' % filename) class LocalVersion(Version): def __init__(self, binary, **kwargs): Version.__init__(self, **kwargs) - path = None - - def find_location(path): - if os.path.exists(os.path.join(path, 'application.ini')): - return path - - if sys.platform == 'darwin': - path = os.path.join(os.path.dirname(path), 'Resources') - - if os.path.exists(os.path.join(path, 'application.ini')): - return path - else: - return None if binary: # on Windows, the binary may be specified with or without the # .exe extension if not os.path.exists(binary) and not os.path.exists(binary + '.exe'): raise IOError('Binary path does not exist: %s' % binary) - path = find_location(os.path.dirname(os.path.realpath(binary))) + path = os.path.dirname(os.path.realpath(binary)) else: - path = find_location(os.getcwd()) + path = os.getcwd() - if not path: - raise errors.LocalAppNotFoundError(path) + if not self.check_location(path): + if sys.platform == 'darwin': + resources_path = os.path.join(os.path.dirname(path), + 'Resources') + if self.check_location(resources_path): + path = resources_path + else: + raise errors.LocalAppNotFoundError(path) + else: + raise errors.LocalAppNotFoundError(path) self.get_gecko_info(path) + def check_location(self, path): + return (os.path.exists(os.path.join(path, 'application.ini')) + and os.path.exists(os.path.join(path, 'platform.ini'))) + class B2GVersion(Version): def __init__(self, sources=None, **kwargs): Version.__init__(self, **kwargs) sources = sources or \ os.path.exists(os.path.join(os.getcwd(), 'sources.xml')) and \
--- a/testing/mozbase/mozversion/tests/test_b2g.py +++ b/testing/mozbase/mozversion/tests/test_b2g.py @@ -21,16 +21,19 @@ class SourcesTest(unittest.TestCase): self.binary = os.path.join(self.tempdir, 'binary') with open(self.binary, 'w') as f: f.write('foobar') with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: f.writelines("""[App]\nName = B2G\n""") + with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f: + f.write('[Build]\nBuildID = PlatformBuildID\n') + def tearDown(self): mozfile.remove(self.tempdir) def _create_zip(self, revision=None, date=None): zip_path = os.path.join( self.tempdir, 'gaia', 'profile', 'webapps', 'settings.gaiamobile.org', 'application.zip') os.makedirs(os.path.dirname(zip_path))
--- a/testing/mozbase/mozversion/tests/test_binary.py +++ b/testing/mozbase/mozversion/tests/test_binary.py @@ -1,16 +1,18 @@ #!/usr/bin/env python # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. import os +import sys import tempfile +import shutil import unittest import mozfile from mozversion import errors, get_version class BinaryTest(unittest.TestCase): @@ -74,31 +76,63 @@ SourceRepository = PlatformSourceRepo mozfile.remove(tempdir) def test_binary_in_current_path(self): self._write_ini_files() os.chdir(self.tempdir) self._check_version(get_version()) + def test_with_ini_files_on_osx(self): + self._write_ini_files() + + platform = sys.platform + sys.platform = 'darwin' + try: + # get_version is working with ini files next to the binary + self._check_version(get_version(binary=self.binary)) + + # or if they are in the Resources dir + # in this case the binary must be in a Contents dir, next + # to the Resources dir + contents_dir = os.path.join(self.tempdir, 'Contents') + os.mkdir(contents_dir) + moved_binary = os.path.join(contents_dir, + os.path.basename(self.binary)) + shutil.move(self.binary, moved_binary) + + resources_dir = os.path.join(self.tempdir, 'Resources') + os.mkdir(resources_dir) + for ini_file in ('application.ini', 'platform.ini'): + shutil.move(os.path.join(self.tempdir, ini_file), resources_dir) + + self._check_version(get_version(binary=moved_binary)) + finally: + sys.platform = platform + def test_invalid_binary_path(self): self.assertRaises(IOError, get_version, os.path.join(self.tempdir, 'invalid')) def test_without_ini_files(self): """With missing ini files an exception should be thrown""" self.assertRaises(errors.AppNotFoundError, get_version, self.binary) - def test_without_platform_file(self): - """With a missing platform file no exception should be thrown""" + def test_without_platform_ini_file(self): + """With a missing platform.ini file an exception should be thrown""" self._write_ini_files(platform=False) + self.assertRaises(errors.AppNotFoundError, get_version, + self.binary) - v = get_version(self.binary) - self.assertTrue(isinstance(v, dict)) + def test_without_application_ini_file(self): + """With a missing application.ini file an exception should be thrown""" + self._write_ini_files(application=False) + self.assertRaises(errors.AppNotFoundError, get_version, + self.binary) def test_with_exe(self): """Test that we can resolve .exe files""" self._write_ini_files() exe_name_unprefixed = self.binary + '1' exe_name = exe_name_unprefixed + '.exe' with open(exe_name, 'w') as f:
--- a/testing/mozbase/mozversion/tests/test_sources.py +++ b/testing/mozbase/mozversion/tests/test_sources.py @@ -12,16 +12,21 @@ import mozfile from mozversion import errors, get_version class SourcesTest(unittest.TestCase): """test getting version information from a sources xml""" application_ini = """[App]\nName = B2G\n""" + platform_ini = """[Build] +BuildID = PlatformBuildID +SourceStamp = PlatformSourceStamp +SourceRepository = PlatformSourceRepo +""" sources_xml = """<?xml version="1.0" ?><manifest> <project path="build" revision="build_revision" /> <project path="gaia" revision="gaia_revision" /> <project path="gecko" revision="gecko_revision" /> </manifest> """ def setUp(self): @@ -31,46 +36,46 @@ class SourcesTest(unittest.TestCase): self.binary = os.path.join(self.tempdir, 'binary') with open(self.binary, 'w') as f: f.write('foobar') def tearDown(self): os.chdir(self.cwd) mozfile.remove(self.tempdir) - def test_sources(self): + def _write_conf_files(self, sources=True): with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: f.writelines(self.application_ini) + with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f: + f.writelines(self.platform_ini) + if sources: + with open(os.path.join(self.tempdir, 'sources.xml'), 'w') as f: + f.writelines(self.sources_xml) - sources = os.path.join(self.tempdir, 'sources.xml') - with open(sources, 'w') as f: - f.writelines(self.sources_xml) + def test_sources(self): + self._write_conf_files() os.chdir(self.tempdir) - self._check_version(get_version(sources=sources)) + self._check_version(get_version(sources=os.path.join(self.tempdir, + 'sources.xml'))) def test_sources_in_current_directory(self): - with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: - f.writelines(self.application_ini) - - with open(os.path.join(self.tempdir, 'sources.xml'), 'w') as f: - f.writelines(self.sources_xml) + self._write_conf_files() os.chdir(self.tempdir) self._check_version(get_version()) def test_invalid_sources_path(self): """An invalid source path should cause an exception""" self.assertRaises(errors.AppNotFoundError, get_version, self.binary, os.path.join(self.tempdir, 'invalid')) def test_without_sources_file(self): """With a missing sources file no exception should be thrown""" - with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: - f.writelines(self.application_ini) + self._write_conf_files(sources=False) get_version(self.binary) def _check_version(self, version): self.assertEqual(version.get('build_changeset'), 'build_revision') self.assertEqual(version.get('gaia_changeset'), 'gaia_revision') self.assertEqual(version.get('gecko_changeset'), 'gecko_revision') self.assertIsNone(version.get('invalid_key'))