class test_artifact_manager_chain(unit_test):

  DEBUG = unit_test.DEBUG
  #DEBUG = True

  LINUX_BT = build_target('linux', 'ubuntu', '18', 'x86_64', 'release')
  MACOS_BT = build_target('macos', '', '10.14', 'x86_64', 'release')

  def test_publish(self):
    t1 = AMT(recipes = RECIPES.APPLE)
    t2 = AMT(recipes = RECIPES.WATER)

    adesc1 = 'apple;1.2.3;1;0;linux;release;x86_64;ubuntu;18'
    adesc2 = 'water;1.0.0;0;0;linux;release;x86_64;ubuntu;18'

    t1.publish(adesc1)
    t2.publish(adesc2)
    
    self.assertEqual( [ AD.parse(adesc1) ], t1.am.list_all_by_descriptor(None) )
    self.assertEqual( [ AD.parse(adesc2) ], t2.am.list_all_by_descriptor(None) )

    c = AMC()
    c.add_artifact_manager(t1.am)
    c.add_artifact_manager(t2.am)

    self.assertEqual( [ AD.parse(adesc1), AD.parse(adesc2) ], c.list_all_by_descriptor(None) )

    rm = c.get_requirement_manager(self.LINUX_BT)
    dm = rm.dependency_map( [ 'RUN' ], 'linux')
    print(dm)
Пример #2
0
 def _load_builder_script(self, filename):
     bt = build_target()
     config = builder_config()
     config.build_root = temp_file.make_temp_dir()
     config.no_network = True
     config.no_checksums = True
     config.source_dir = path.dirname(filename)
     config.verbose = True
     env = builder_env(config, [filename])
     sm = builder_script_manager([filename], bt, env)
     self.assertEqual(1, len(sm.scripts))
     return sm.scripts.values()[0]
Пример #3
0
class toolchain_testing(object):
    @classmethod
    def can_compile_macos(clazz):
        return host.is_macos()

    @classmethod
    def can_compile_ios(clazz):
        return host.is_macos()

    BT = build_target(build_system.ANDROID, '', '', (build_arch.ARMV7, ),
                      build_level.RELEASE)

    @classmethod
    def android_toolchain_is_valid(clazz):
        return toolchain.get_toolchain(clazz.BT).is_valid()

    @classmethod
    def can_compile_android(clazz):
        return (host.is_macos()
                or host.is_linux()) and clazz.android_toolchain_is_valid()

    @classmethod
    def can_compile_linux(clazz):
        return host.is_linux()
Пример #4
0
class test_artifact_db(unit_test):

    TEST_FILES = package_files(FCL([
        ('f1', 'fchk1'),
        ('f2', 'fchk2'),
    ]), FCL([
        ('e1', 'echk1'),
        ('e2', 'echk2'),
    ]), 'files_chk', 'env_files_chk')

    TEST_FILES2 = package_files(FCL([
        ('g1', 'gchk1'),
        ('g2', 'gchk2'),
    ]), FCL([
        ('h1', 'hchk1'),
        ('h2', 'hchk2'),
    ]), 'files2_chk', 'env_files2_chk')

    DEBUG = unit_test.DEBUG
    #DEBUG = True

    LINUX_BT = build_target('linux', 'ubuntu', '18', ('x86_64', ), 'release')
    MACOS_BT = build_target('macos', '', '10.13', ('x86_64', ), 'release')

    def _make_tmp_db_path(self):
        tmp_dir = temp_file.make_temp_dir(delete=not self.DEBUG)
        f = path.join(tmp_dir, 'db.sqlite')
        if self.DEBUG:
            self.spew('_make_tmp_db_path() => %s' % (f))
        return f

    def test_db_create_empty(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        self.assertEqual([], db.list_all_by_descriptor())

    def test_db_recreate_empty(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        self.assertEqual([], db.list_all_by_descriptor())
        del db
        recreated_db = DB(tmp_db)
        self.assertEqual([], recreated_db.list_all_by_descriptor())

    def test_add(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
               ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        adesc = e.artifact_descriptor
        self.assertFalse(db.has_artifact(adesc))
        db.add_artifact(e)
        self.assertTrue(db.has_artifact(adesc))

    def test_add_duplicate(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
               ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        adesc = e.artifact_descriptor
        self.assertFalse(db.has_artifact(adesc))
        db.add_artifact(e)
        self.assertTrue(db.has_artifact(adesc))
        with self.assertRaises(AlreadyInstalledError) as context:
            db.add_artifact(e)

    def test_remove(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
               ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        adesc = e.artifact_descriptor
        self.assertFalse(db.has_artifact(adesc))
        db.add_artifact(e)
        self.assertTrue(db.has_artifact(adesc))
        db.remove_artifact(adesc)
        self.assertFalse(db.has_artifact(adesc))

    def test_readd(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
               ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        adesc = e.artifact_descriptor
        self.assertFalse(db.has_artifact(adesc))
        db.add_artifact(e)
        self.assertTrue(db.has_artifact(adesc))
        db.remove_artifact(adesc)
        self.assertFalse(db.has_artifact(adesc))
        db.add_artifact(e)
        self.assertTrue(db.has_artifact(adesc))
        db.remove_artifact(adesc)
        self.assertFalse(db.has_artifact(adesc))

    def test_remove_not_installed(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
               ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        adesc = e.artifact_descriptor
        self.assertFalse(db.has_artifact(adesc))
        with self.assertRaises(NotInstalledError) as context:
            db.remove_artifact(adesc)

    def test_replace(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        self.assertFalse(db.has_artifact(e1.artifact_descriptor))
        db.add_artifact(e1)
        self.assertTrue(db.has_artifact(e1.artifact_descriptor))
        self.assertEqual([e1.artifact_descriptor], db.list_all_by_descriptor())
        db.replace_artifact(e2)
        self.assertEqual([e2.artifact_descriptor], db.list_all_by_descriptor())

    def test_replace_not_installed(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        self.assertFalse(db.has_artifact(e1.artifact_descriptor))
        with self.assertRaises(NotInstalledError) as context:
            db.replace_artifact(e2)

    def test_find(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
               ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        adesc = e.artifact_descriptor
        self.assertEqual(None, db.find_artifact(adesc))
        db.add_artifact(e)
        r = db.find_artifact(adesc)
        print('R: %s' % (str(r)))
        self.assertEqual(e, r)
        db.remove_artifact(adesc)
        self.assertEqual(None, db.find_artifact(adesc))

    def test_get(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
               ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        adesc = e.artifact_descriptor
        with self.assertRaises(NotInstalledError) as context:
            db.get_artifact(adesc)
            db.add_artifact(e)
            self.assertEqual(e, db.get_artifact(adesc))
            db.remove_artifact(adesc)
        with self.assertRaises(NotInstalledError) as context:
            db.get_artifact(adesc)

    def test_list_all_by_descriptor(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        db.add_artifact(e1)
        self.assertEqual([e1.artifact_descriptor], db.list_all_by_descriptor())
        db.add_artifact(e2)
        self.assertEqual([e2.artifact_descriptor, e1.artifact_descriptor],
                         db.list_all_by_descriptor())

    def test_list_all_by_descriptor_with_build_target(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        db.add_artifact(e1)
        db.add_artifact(e2)
        self.assertEqual([e2.artifact_descriptor],
                         db.list_all_by_descriptor(build_target=self.LINUX_BT))
        self.assertEqual([e1.artifact_descriptor],
                         db.list_all_by_descriptor(build_target=self.MACOS_BT))

    def test_list_all_by_metadata(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        db.add_artifact(e1)
        self.assertEqual([e1], db.list_all_by_metadata())
        db.add_artifact(e2)
        self.assertEqual([e2, e1], db.list_all_by_metadata())

    def test_list_all_by_metadata_with_build_target(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        db.add_artifact(e1)
        db.add_artifact(e2)
        self.assertEqual([e2],
                         db.list_all_by_metadata(build_target=self.LINUX_BT))
        self.assertEqual([e1],
                         db.list_all_by_metadata(build_target=self.MACOS_BT))

    def test_list_all_by_package_descriptor(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        pd1 = PD('foo', '1.2.3-1')
        pd2 = PD('bar', '5.6.7-1')
        db.add_artifact(e1)
        self.assertEqual([pd1], db.list_all_by_package_descriptor())
        db.add_artifact(e2)
        self.assertEqual([pd2, pd1], db.list_all_by_package_descriptor())

    def test_list_all_by_package_descriptor_with_build_target(self):
        tmp_db = self._make_tmp_db_path()
        db = DB(tmp_db)
        e1 = PM('foo-1.2.3.tar.gz', 'foo', '1.2.3', 1, 0, 'macos', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES)
        e2 = PM('bar-5.6.7.tar.gz', 'bar', '5.6.7', 1, 0, 'linux', 'release',
                ('x86_64', ), '', '', [], {}, self.TEST_FILES2)
        pd1 = PD('foo', '1.2.3-1')
        pd2 = PD('bar', '5.6.7-1')
        db.add_artifact(e1)
        db.add_artifact(e2)
        self.assertEqual(
            [pd2],
            db.list_all_by_package_descriptor(build_target=self.LINUX_BT))
        self.assertEqual(
            [pd1],
            db.list_all_by_package_descriptor(build_target=self.MACOS_BT))
Пример #5
0
def _make_compiler(system, arch):
    return compiler(build_target(system, '', '', arch, 'release'))
Пример #6
0
 def build_target(self):
     return build_target(self.system, self.distro, self.distro_version,
                         self.arch, self.level)
Пример #7
0
    def __init__(self, scons_locals, verbose=SPEW_MED):
        self._scons_locals = tuple_util.dict_to_named_tuple(
            'SconsLocals', scons_locals)

        self.verbose = verbose

        self.env = SConsEnvironment(
        )  #PRINT_CMD_LINE_FUNC = self.print_cmd_line)
        scons_vars = self._scons_locals.variables()

        scons_vars.Add(
            self._scons_locals.Enumvariable('system',
                                            'The system to build for',
                                            build_target.HOST_SYSTEM_NAME,
                                            allowed_values=set(
                                                build_target.SYSTEMS)))

        scons_vars.Add(
            self._scons_locals.Enumvariable('build_level',
                                            'The build type',
                                            build_target.DEBUG,
                                            allowed_values=set(
                                                build_target.LEVELS)))

        PRINT_CMD_LINE_FUNC = self.print_cmd_line
        #PRINT_CMD_LINE_FUNC = None
        self.env = self._scons_locals.Environment(
            variables=scons_vars, PRINT_CMD_LINE_FUNC=PRINT_CMD_LINE_FUNC)

        unknown_vars = scons_vars.Unknownvariables()
        if unknown_vars:
            raise RuntimeError('Unknown scons variables: "%s"' %
                               (unknown_vars))

        self.env['BES_BUILD'] = self

        self.build_target = build_target()

        self.source_dir = os.getcwd()
        self.target_dir = path.abspath(
            path.join(self.build_target.build_path, 'BUILD'))
        self.obj_dir = path.join(self.target_dir, 'obj')
        self.bin_dir = path.join(self.target_dir, 'bin')
        self.unit_test_dir = path.join(self.target_dir, 'unit_tests')
        self.lib_dir = path.join(self.target_dir, 'lib')
        self.include_dir = path.join(self.target_dir, 'include')

        self._longest_target = 0

        self._packages = {}

        self._pkg_config_exe = path.join(
            self.__get_package_home_dir('pkg-config'), 'bin/pkg-config')

        self.add_package(
            '__builtin__',
            PackageFlags(cpppath=self.include_dir, libpath=self.lib_dir))

        # FIXME: conditionalize this on verbosity level
        #    self.env.AppendUnique(CCCOMSTR = 'compile c')
        #    self.env.AppendUnique(CXXCOMSTR = 'compile c++')
        #    self.env.AppendUnique(LINKCOMSTR = 'link')
        #    self.env.AppendUnique(ARCOMSTR = 'archive')
        #    self.env.AppendUnique(RANLIBCOMSTR = 'ranlib')

        #    self.env.AppendUnique(CCFLAGS = [ '-std=c++11' ])

        self.register_builder('_unit_test_runner_builder',
                              self._unit_test_runner_builder)
Пример #8
0
class test_artifact_manager_local(unit_test):

    DEBUG = unit_test.DEBUG
    #DEBUG = True

    LINUX_BT = build_target('linux', 'ubuntu', '18', 'x86_64', 'release')
    MACOS_BT = build_target('macos', '', '10.14', 'x86_64', 'release')

    def test_publish(self):
        t = AMT(recipes=RECIPES.APPLE)
        adesc = 'apple;1.2.3;1;0;linux;release;x86_64;ubuntu;18'
        tmp_tarball = t.create_package(adesc)
        filename = t.am.publish(tmp_tarball, self.LINUX_BT, False, None)
        self.assertTrue(path.exists(filename))
        expected = [
            AD.parse('apple;1.2.3;1;0;linux;release;x86_64;ubuntu;18'),
        ]
        self.assertEqual(expected, t.am.list_all_by_descriptor(None))

    def test_artifact_path(self):
        t = AMT(recipes=RECIPES.APPLE)
        self.assertEqual([], t.am.list_all_by_descriptor(None))
        t.publish('apple;1.2.3;1;0;linux;release;x86_64;ubuntu;18')
        self.assertEqual(
            'linux-ubuntu-18/x86_64/release/apple-1.2.3-1.tar.gz',
            t.am.artifact_path(PD('apple', '1.2.3-1'), self.LINUX_BT, True))

    def test_publish_again_with_replace(self):
        am = FPUT.make_artifact_manager(debug=self.DEBUG)
        tmp_tarball = FPUT.create_one_package(RECIPES.APPLE)
        filename = am.publish(tmp_tarball, self.LINUX_BT, False, None)
        self.assertTrue(path.exists(filename))
        expected = [
            AD.parse('apple;1.2.3;1;0;linux;release;x86_64;ubuntu;18'),
        ]
        self.assertEqual(expected, am.list_all_by_descriptor(None))
        filename = am.publish(tmp_tarball, self.LINUX_BT, True, None)
        self.assertEqual(expected, am.list_all_by_descriptor(None))

    def test_publish_again_without_replace(self):
        am = FPUT.make_artifact_manager(debug=self.DEBUG)
        tmp_tarball = FPUT.create_one_package(RECIPES.APPLE)
        filename = am.publish(tmp_tarball, self.LINUX_BT, False, None)
        self.assertTrue(path.exists(filename))
        expected = [
            AD.parse('apple;1.2.3;1;0;linux;release;x86_64;ubuntu;18'),
        ]
        self.assertEqual(expected, am.list_all_by_descriptor(None))
        with self.assertRaises(AlreadyInstalledError) as context:
            am.publish(tmp_tarball, self.LINUX_BT, False, None)

    def test_find_by_package_descriptor_linux(self):
        mutations = {
            'system': 'linux',
            'distro': 'ubuntu',
            'distro_version': '18'
        }
        am = FPUT.make_artifact_manager(self.DEBUG, RECIPES.FOODS,
                                        self.LINUX_BT, mutations)
        self.assertEqual(
            'water-1.0.0',
            am.find_by_package_descriptor(PD('water', '1.0.0'), self.LINUX_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'water-1.0.0-1',
            am.find_by_package_descriptor(PD('water',
                                             '1.0.0-1'), self.LINUX_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'water-1.0.0-2',
            am.find_by_package_descriptor(PD('water',
                                             '1.0.0-2'), self.LINUX_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'fructose-3.4.5-6',
            am.find_by_package_descriptor(PD('fructose',
                                             '3.4.5-6'), self.LINUX_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'apple-1.2.3-1',
            am.find_by_package_descriptor(PD('apple',
                                             '1.2.3-1'), self.LINUX_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'orange-6.5.4-3',
            am.find_by_package_descriptor(PD('orange',
                                             '6.5.4-3'), self.LINUX_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'orange_juice-1.4.5',
            am.find_by_package_descriptor(PD('orange_juice',
                                             '1.4.5'), self.LINUX_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'pear_juice-6.6.6',
            am.find_by_package_descriptor(PD('pear_juice',
                                             '6.6.6'), self.LINUX_BT,
                                          False).package_descriptor.full_name)

    def test_find_by_package_descriptor_macos(self):
        mutations = {
            'system': 'macos',
            'distro': '',
            'distro_version': '10.14'
        }
        am = FPUT.make_artifact_manager(self.DEBUG, RECIPES.FOODS,
                                        self.MACOS_BT, mutations)
        self.assertEqual(
            'water-1.0.0',
            am.find_by_package_descriptor(PD('water', '1.0.0'), self.MACOS_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'water-1.0.0-1',
            am.find_by_package_descriptor(PD('water',
                                             '1.0.0-1'), self.MACOS_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'water-1.0.0-2',
            am.find_by_package_descriptor(PD('water',
                                             '1.0.0-2'), self.MACOS_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'fructose-3.4.5-6',
            am.find_by_package_descriptor(PD('fructose',
                                             '3.4.5-6'), self.MACOS_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'apple-1.2.3-1',
            am.find_by_package_descriptor(PD('apple',
                                             '1.2.3-1'), self.MACOS_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'orange-6.5.4-3',
            am.find_by_package_descriptor(PD('orange',
                                             '6.5.4-3'), self.MACOS_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'orange_juice-1.4.5',
            am.find_by_package_descriptor(PD('orange_juice',
                                             '1.4.5'), self.MACOS_BT,
                                          False).package_descriptor.full_name)
        self.assertEqual(
            'pear_juice-6.6.6',
            am.find_by_package_descriptor(PD('pear_juice',
                                             '6.6.6'), self.MACOS_BT,
                                          False).package_descriptor.full_name)

    def test_list_latest_versions_linux(self):
        self.maxDiff = None
        mutations = {
            'system': 'linux',
            'distro': 'ubuntu',
            'distro_version': '18'
        }
        am = FPUT.make_artifact_manager(self.DEBUG, RECIPES.FOODS,
                                        self.LINUX_BT, mutations)
        expected = [
            AD.parse('apple;1.2.3;1;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('arsenic;1.2.9;1;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('citrus;1.0.0;2;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('fiber;1.0.0;0;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('fructose;3.4.5;6;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('fruit;1.0.0;0;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('knife;1.0.0;0;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('mercury;1.2.9;0;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('orange;6.5.4;3;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('orange_juice;1.4.5;0;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('pear;1.2.3;1;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('pear_juice;6.6.6;0;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('smoothie;1.0.0;0;0;linux;release;x86_64;ubuntu;18'),
            AD.parse('water;1.0.0;2;0;linux;release;x86_64;ubuntu;18'),
        ]
        self.assertEqual(expected, am.list_latest_versions(self.LINUX_BT))

    def test_list_latest_versions_macos(self):
        self.maxDiff = None
        mutations = {
            'system': 'macos',
            'distro': '',
            'distro_version': '10.14'
        }
        am = FPUT.make_artifact_manager(self.DEBUG, RECIPES.FOODS,
                                        self.MACOS_BT, mutations)
        expected = [
            AD.parse('apple;1.2.3;1;0;macos;release;x86_64;;10.14'),
            AD.parse('arsenic;1.2.9;1;0;macos;release;x86_64;;10.14'),
            AD.parse('citrus;1.0.0;2;0;macos;release;x86_64;;10.14'),
            AD.parse('fiber;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('fructose;3.4.5;6;0;macos;release;x86_64;;10.14'),
            AD.parse('fruit;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('knife;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('mercury;1.2.9;0;0;macos;release;x86_64;;10.14'),
            AD.parse('orange;6.5.4;3;0;macos;release;x86_64;;10.14'),
            AD.parse('orange_juice;1.4.5;0;0;macos;release;x86_64;;10.14'),
            AD.parse('pear;1.2.3;1;0;macos;release;x86_64;;10.14'),
            AD.parse('pear_juice;6.6.6;0;0;macos;release;x86_64;;10.14'),
            AD.parse('smoothie;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('water;1.0.0;2;0;macos;release;x86_64;;10.14'),
        ]
        self.assertEqual(expected, am.list_latest_versions(self.MACOS_BT))

    def test_remove_artifact(self):
        self.maxDiff = None
        mutations = {
            'system': 'macos',
            'distro': '',
            'distro_version': '10.14'
        }
        am = FPUT.make_artifact_manager(self.DEBUG, RECIPES.FOODS,
                                        self.MACOS_BT, mutations)
        expected = [
            AD.parse('apple;1.2.3;1;0;macos;release;x86_64;;10.14'),
            AD.parse('arsenic;1.2.9;1;0;macos;release;x86_64;;10.14'),
            AD.parse('citrus;1.0.0;2;0;macos;release;x86_64;;10.14'),
            AD.parse('fiber;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('fructose;3.4.5;6;0;macos;release;x86_64;;10.14'),
            AD.parse('fruit;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('knife;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('mercury;1.2.9;0;0;macos;release;x86_64;;10.14'),
            AD.parse('orange;6.5.4;3;0;macos;release;x86_64;;10.14'),
            AD.parse('orange_juice;1.4.5;0;0;macos;release;x86_64;;10.14'),
            AD.parse('pear;1.2.3;1;0;macos;release;x86_64;;10.14'),
            AD.parse('pear_juice;6.6.6;0;0;macos;release;x86_64;;10.14'),
            AD.parse('smoothie;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('water;1.0.0;2;0;macos;release;x86_64;;10.14'),
        ]
        self.assertEqual(expected, am.list_latest_versions(self.MACOS_BT))
        self.assertEqual([
            'artifacts.db',
            'macos-10.14/x86_64/release/apple-1.2.3-1.tar.gz',
            'macos-10.14/x86_64/release/arsenic-1.2.10.tar.gz',
            'macos-10.14/x86_64/release/arsenic-1.2.9-1.tar.gz',
            'macos-10.14/x86_64/release/arsenic-1.2.9.tar.gz',
            'macos-10.14/x86_64/release/citrus-1.0.0-2.tar.gz',
            'macos-10.14/x86_64/release/fiber-1.0.0.tar.gz',
            'macos-10.14/x86_64/release/fructose-3.4.5-6.tar.gz',
            'macos-10.14/x86_64/release/fruit-1.0.0.tar.gz',
            'macos-10.14/x86_64/release/knife-1.0.0.tar.gz',
            'macos-10.14/x86_64/release/mercury-1.2.8-1.tar.gz',
            'macos-10.14/x86_64/release/mercury-1.2.8.tar.gz',
            'macos-10.14/x86_64/release/mercury-1.2.9.tar.gz',
            'macos-10.14/x86_64/release/orange-6.5.4-3.tar.gz',
            'macos-10.14/x86_64/release/orange_juice-1.4.5.tar.gz',
            'macos-10.14/x86_64/release/pear-1.2.3-1.tar.gz',
            'macos-10.14/x86_64/release/pear_juice-6.6.6.tar.gz',
            'macos-10.14/x86_64/release/smoothie-1.0.0.tar.gz',
            'macos-10.14/x86_64/release/water-1.0.0-1.tar.gz',
            'macos-10.14/x86_64/release/water-1.0.0-2.tar.gz',
            'macos-10.14/x86_64/release/water-1.0.0.tar.gz',
        ], file_find.find(am.root_dir))
        am.remove_artifact(
            AD.parse('apple;1.2.3;1;0;macos;release;x86_64;;10.14'))
        am.remove_artifact(
            AD.parse('smoothie;1.0.0;0;0;macos;release;x86_64;;10.14'))
        expected = [
            AD.parse('arsenic;1.2.9;1;0;macos;release;x86_64;;10.14'),
            AD.parse('citrus;1.0.0;2;0;macos;release;x86_64;;10.14'),
            AD.parse('fiber;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('fructose;3.4.5;6;0;macos;release;x86_64;;10.14'),
            AD.parse('fruit;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('knife;1.0.0;0;0;macos;release;x86_64;;10.14'),
            AD.parse('mercury;1.2.9;0;0;macos;release;x86_64;;10.14'),
            AD.parse('orange;6.5.4;3;0;macos;release;x86_64;;10.14'),
            AD.parse('orange_juice;1.4.5;0;0;macos;release;x86_64;;10.14'),
            AD.parse('pear;1.2.3;1;0;macos;release;x86_64;;10.14'),
            AD.parse('pear_juice;6.6.6;0;0;macos;release;x86_64;;10.14'),
            AD.parse('water;1.0.0;2;0;macos;release;x86_64;;10.14'),
        ]
        self.assertEqual(expected, am.list_latest_versions(self.MACOS_BT))
        self.assertEqual([
            'artifacts.db',
            'macos-10.14/x86_64/release/arsenic-1.2.10.tar.gz',
            'macos-10.14/x86_64/release/arsenic-1.2.9-1.tar.gz',
            'macos-10.14/x86_64/release/arsenic-1.2.9.tar.gz',
            'macos-10.14/x86_64/release/citrus-1.0.0-2.tar.gz',
            'macos-10.14/x86_64/release/fiber-1.0.0.tar.gz',
            'macos-10.14/x86_64/release/fructose-3.4.5-6.tar.gz',
            'macos-10.14/x86_64/release/fruit-1.0.0.tar.gz',
            'macos-10.14/x86_64/release/knife-1.0.0.tar.gz',
            'macos-10.14/x86_64/release/mercury-1.2.8-1.tar.gz',
            'macos-10.14/x86_64/release/mercury-1.2.8.tar.gz',
            'macos-10.14/x86_64/release/mercury-1.2.9.tar.gz',
            'macos-10.14/x86_64/release/orange-6.5.4-3.tar.gz',
            'macos-10.14/x86_64/release/orange_juice-1.4.5.tar.gz',
            'macos-10.14/x86_64/release/pear-1.2.3-1.tar.gz',
            'macos-10.14/x86_64/release/pear_juice-6.6.6.tar.gz',
            'macos-10.14/x86_64/release/water-1.0.0-1.tar.gz',
            'macos-10.14/x86_64/release/water-1.0.0-2.tar.gz',
            'macos-10.14/x86_64/release/water-1.0.0.tar.gz',
        ], file_find.find(am.root_dir))
Пример #9
0
class test_recipe_step(unit_test):

    BT_LINUX = build_target('linux', 'ubuntu', '18', ('x86_64'), 'release')
    BT_MACOS = build_target('macos', '', '', ('x86_64'), 'release')
    BT_ANDROID = build_target('android', '', '', ('armv7'), 'release')

    def test_empty_defaults(self):
        text = '''\
'''
        step = self._parse(text)
        r = step.resolve_values({}, testing_recipe_load_env(self.BT_LINUX))
        expected = {
            'bool_value': False,
            'install_file_value': [],
            'file_list_value': value_file_list(),
            'file_value': None,
            'hook_list_value': [],
            'int_value': None,
            'key_values_value': KVL(),
            'string_list_value': string_list(),
            'string_value': None,
            'git_address_value': None,
        }
        self.assertEqual(expected, r)

        r = step.resolve_values({}, testing_recipe_load_env(self.BT_MACOS))
        self.assertEqual(expected, r)

    def test_takes_all(self):
        text = '''\
bool_value:
  all: True

string_list_value
  all: a b "x y"

key_values_value
  all: a=forall b=6
  linux: a=forlinux
  macos: a=formacos
  android: a=forandroid
'''
        step = self._parse(text)
        r = step.resolve_values({}, testing_recipe_load_env(self.BT_LINUX))
        expected = {
            'bool_value': True,
            'install_file_value': [],
            'file_list_value': [],
            'file_value': None,
            'hook_list_value': [],
            'int_value': None,
            'key_values_value': KVL([('a', 'forlinux'), ('b', '6')]),
            'string_list_value': ['a', 'b', '"x y"'],
            'string_value': None,
            'git_address_value': None,
        }
        self.assertEqual(expected, r)
        r = step.resolve_values({}, testing_recipe_load_env(self.BT_MACOS))
        expected = {
            'bool_value': True,
            'install_file_value': [],
            'file_list_value': [],
            'file_value': None,
            'hook_list_value': [],
            'int_value': None,
            'key_values_value': KVL([('a', 'formacos'), ('b', '6')]),
            'string_list_value': ['a', 'b', '"x y"'],
            'string_value': None,
            'git_address_value': None,
        }
        self.assertEqual(expected, r)
        r = step.resolve_values({}, testing_recipe_load_env(self.BT_ANDROID))
        expected = {
            'bool_value': True,
            'install_file_value': [],
            'file_list_value': [],
            'file_value': None,
            'hook_list_value': [],
            'int_value': None,
            'key_values_value': KVL([('a', 'forandroid'), ('b', '6')]),
            'string_list_value': ['a', 'b', '"x y"'],
            'string_value': None,
            'git_address_value': None,
        }
        self.assertEqual(expected, r)

    def test_takes_git_address(self):
        self.maxDiff = None
        text = '''\
git_address_value
  linux: linux_address linux_tag
  macos: macos_address macos_tag
'''
        step = self._parse(text)
        env = testing_recipe_load_env(self.BT_LINUX)
        r = step.resolve_values({}, env)
        expected = {
            'bool_value':
            False,
            'install_file_value': [],
            'file_list_value': [],
            'file_value':
            None,
            'hook_list_value': [],
            'int_value':
            None,
            'key_values_value': [],
            'string_list_value': [],
            'string_value':
            None,
            'git_address_value':
            value_git_address(VO('caca', 1, 'caca'), 'linux_address',
                              'linux_tag'),
        }
        self.assertEqual(expected, r)

        env = testing_recipe_load_env(self.BT_MACOS)
        r = step.resolve_values({}, env)
        expected = {
            'bool_value':
            False,
            'install_file_value': [],
            'file_list_value': [],
            'file_value':
            None,
            'hook_list_value': [],
            'int_value':
            None,
            'key_values_value': [],
            'string_list_value': [],
            'string_value':
            None,
            'git_address_value':
            value_git_address(VO('caca', 1, 'caca'), 'macos_address',
                              'macos_tag'),
        }
        self.assertEqual(expected, r)

    @classmethod
    def _parse(clazz, s):
        recipe_template = '''!rebuild.recipe!
package foo 1.2.3 4
  steps
    step_takes_all
%s
'''
        indented_values = clazz._add_indent(s, 3)
        recipe_text = recipe_template % (indented_values)
        r = recipe_parser('<test>', recipe_text).parse()
        return r[0].steps[0]

    @classmethod
    def _add_indent(clazz, s, n):
        indent = ' ' * 2 * n
        lines = s.split('\n')
        lines = ['%s%s' % (indent, x) for x in lines]
        return '\n'.join(lines)