Ejemplo n.º 1
0
 def testParseLibraryRegExNoMatchFallbacksToDefaultLibname(self):
   lib_dict = {
       'libname:foo.*': ['path/to/LICENSE'],
   }
   builder = LicenseBuilder([], [], lib_dict, {})
   self.assertEquals(
       builder._ParseLibrary('//a/b/third_party/libname:bar_java'), 'libname')
Ejemplo n.º 2
0
 def testGetThirdPartyLibrariesWithRegex(self):
     lib_regex_dict = {
         'libname2:c.*': ['path/to/LICENSE'],
     }
     builder = LicenseBuilder([], [], {}, lib_regex_dict)
     self.assertEqual(builder._GetThirdPartyLibraries('out/arm', 'target1'),
                      set(['libname1', 'libname2:c.*', 'libname3']))
Ejemplo n.º 3
0
 def testParseLibraryRegExMatchWithSubDirectory(self):
     lib_regex_dict = {
         'libname/foo:bar.*': ['path/to/LICENSE'],
     }
     builder = LicenseBuilder([], [], {}, lib_regex_dict)
     self.assertEquals(
         builder._ParseLibrary('//a/b/third_party/libname/foo:bar_java'),
         'libname/foo:bar.*')
Ejemplo n.º 4
0
 def testParseLibraryName(self):
     self.assertEquals(
         LicenseBuilder._ParseLibraryName('//a/b/third_party/libname1:c'),
         'libname1')
     self.assertEquals(
         LicenseBuilder._ParseLibraryName(
             '//a/b/third_party/libname2:c(d)'), 'libname2')
     self.assertEquals(
         LicenseBuilder._ParseLibraryName(
             '//a/b/third_party/libname3/c:d(e)'), 'libname3')
     self.assertEquals(
         LicenseBuilder._ParseLibraryName('//a/b/not_third_party/c'), None)
Ejemplo n.º 5
0
    def testGenerateLicenseTextFailIfUnknownLibrary(self):
        lib_dict = {
            'simple_library': ['path/to/LICENSE'],
        }
        builder = LicenseBuilder(['dummy_dir'], ['dummy_target'], lib_dict, {})

        with self.assertRaises(Exception) as context:
            builder.GenerateLicenseText('dummy/dir')

        self.assertEquals(
            context.exception.message,
            'Missing licenses for following third_party targets: '
            'libname1, libname2, libname3')
Ejemplo n.º 6
0
def main():
    args = _ParseArgs()

    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    if args.clean:
        _CleanArtifacts(args.output_dir)
        return 0

    architectures = list(args.arch)
    gn_args = args.extra_gn_args

    if args.purify:
        _CleanTemporary(args.output_dir, architectures)
        return 0

    gn_target_name = 'framework_objc'
    if not args.bitcode:
        gn_args.append('enable_dsyms=true')
    gn_args.append('enable_stripping=true')

    # Build all architectures.
    for arch in architectures:
        BuildWebRTC(args.output_dir, arch, args.build_config, gn_target_name,
                    IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode,
                    args.use_goma, gn_args)

    return
    # Create FAT archive.
    lib_paths = [
        os.path.join(args.output_dir, arch + '_libs') for arch in architectures
    ]

    # Combine the slices.
    dylib_path = os.path.join(SDK_FRAMEWORK_NAME, 'WebRTC')
    # Dylibs will be combined, all other files are the same across archs.
    # Use distutils instead of shutil to support merging folders.
    distutils.dir_util.copy_tree(
        os.path.join(lib_paths[0], SDK_FRAMEWORK_NAME),
        os.path.join(args.output_dir, SDK_FRAMEWORK_NAME))
    logging.info('Merging framework slices.')
    dylib_paths = [os.path.join(path, dylib_path) for path in lib_paths]
    out_dylib_path = os.path.join(args.output_dir, dylib_path)
    try:
        os.remove(out_dylib_path)
    except OSError:
        pass
    cmd = ['lipo'] + dylib_paths + ['-create', '-output', out_dylib_path]
    _RunCommand(cmd)

    # Merge the dSYM slices.
    lib_dsym_dir_path = os.path.join(lib_paths[0], 'WebRTC.dSYM')
    if os.path.isdir(lib_dsym_dir_path):
        distutils.dir_util.copy_tree(
            lib_dsym_dir_path, os.path.join(args.output_dir, 'WebRTC.dSYM'))
        logging.info('Merging dSYM slices.')
        dsym_path = os.path.join('WebRTC.dSYM', 'Contents', 'Resources',
                                 'DWARF', 'WebRTC')
        lib_dsym_paths = [os.path.join(path, dsym_path) for path in lib_paths]
        out_dsym_path = os.path.join(args.output_dir, dsym_path)
        try:
            os.remove(out_dsym_path)
        except OSError:
            pass
        cmd = ['lipo'] + lib_dsym_paths + ['-create', '-output', out_dsym_path]
        _RunCommand(cmd)

        # Generate the license file.
        ninja_dirs = [
            os.path.join(args.output_dir, arch + '_libs')
            for arch in architectures
        ]
        gn_target_full_name = '//sdk:' + gn_target_name
        builder = LicenseBuilder(ninja_dirs, [gn_target_full_name])
        builder.GenerateLicenseText(
            os.path.join(args.output_dir, SDK_FRAMEWORK_NAME))

        # Modify the version number.
        # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>.
        # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision 14986.
        infoplist_path = os.path.join(args.output_dir, SDK_FRAMEWORK_NAME,
                                      'Info.plist')
        cmd = [
            'PlistBuddy', '-c', 'Print :CFBundleShortVersionString',
            infoplist_path
        ]
        major_minor = subprocess.check_output(cmd).strip()
        version_number = '%s.%s' % (major_minor, args.revision)
        logging.info('Substituting revision number: %s', version_number)
        cmd = [
            'PlistBuddy', '-c', 'Set :CFBundleVersion ' + version_number,
            infoplist_path
        ]
        _RunCommand(cmd)
        _RunCommand(['plutil', '-convert', 'binary1', infoplist_path])

    logging.info('Done.')
    return 0
Ejemplo n.º 7
0
 def testGetThirdPartyLibrariesWithoutRegex(self):
     builder = LicenseBuilder([], [], {}, {})
     self.assertEquals(
         builder._GetThirdPartyLibraries('out/arm', 'target1'),
         set(['libname1', 'libname2', 'libname3']))
Ejemplo n.º 8
0
 def testParseLibrarySimpleMatch(self):
     builder = LicenseBuilder([], [], {}, {})
     self.assertEquals(builder._ParseLibrary('//a/b/third_party/libname:c'),
                       'libname')
Ejemplo n.º 9
0
def GenerateLicenses(output_dir, build_dir, archs):
    builder = LicenseBuilder(
        [_GetOutputDirectory(build_dir, arch) for arch in archs], TARGETS)
    builder.GenerateLicenseText(output_dir)
Ejemplo n.º 10
0
def main():
    args = _ParseArgs()

    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    if args.clean:
        _CleanArtifacts(args.output_dir)
        return 0

    # architectures is typed as Dict[str, Set[str]],
    # where key is for the environment (device or simulator)
    # and value is for the cpu type.
    architectures = _ParseArchitecture(args.arch)
    gn_args = args.extra_gn_args

    if args.purify:
        _CleanTemporary(args.output_dir, list(architectures.keys()))
        return 0

    gn_target_name = 'framework_objc'
    if not args.bitcode:
        gn_args.append('enable_dsyms=true')
    gn_args.append('enable_stripping=true')

    # Build all architectures.
    framework_paths = []
    all_lib_paths = []
    for (environment, archs) in list(architectures.items()):
        framework_path = os.path.join(args.output_dir, environment)
        framework_paths.append(framework_path)
        lib_paths = []
        for arch in archs:
            lib_path = os.path.join(framework_path, arch + '_libs')
            lib_paths.append(lib_path)
            BuildWebRTC(lib_path, environment, arch, args.build_config,
                        gn_target_name, IOS_DEPLOYMENT_TARGET[environment],
                        LIBVPX_BUILD_VP9, args.bitcode, args.use_goma, gn_args)
        all_lib_paths.extend(lib_paths)

        # Combine the slices.
        dylib_path = os.path.join(SDK_FRAMEWORK_NAME, 'WebRTC')
        # Dylibs will be combined, all other files are the same across archs.
        shutil.rmtree(os.path.join(framework_path, SDK_FRAMEWORK_NAME),
                      ignore_errors=True)
        shutil.copytree(os.path.join(lib_paths[0], SDK_FRAMEWORK_NAME),
                        os.path.join(framework_path, SDK_FRAMEWORK_NAME),
                        symlinks=True)
        logging.info('Merging framework slices for %s.', environment)
        dylib_paths = [os.path.join(path, dylib_path) for path in lib_paths]
        out_dylib_path = os.path.join(framework_path, dylib_path)
        if os.path.islink(out_dylib_path):
            out_dylib_path = os.path.join(os.path.dirname(out_dylib_path),
                                          os.readlink(out_dylib_path))
        try:
            os.remove(out_dylib_path)
        except OSError:
            pass
        cmd = ['lipo'] + dylib_paths + ['-create', '-output', out_dylib_path]
        _RunCommand(cmd)

        # Merge the dSYM slices.
        lib_dsym_dir_path = os.path.join(lib_paths[0], SDK_DSYM_NAME)
        if os.path.isdir(lib_dsym_dir_path):
            shutil.rmtree(os.path.join(framework_path, SDK_DSYM_NAME),
                          ignore_errors=True)
            shutil.copytree(lib_dsym_dir_path,
                            os.path.join(framework_path, SDK_DSYM_NAME))
            logging.info('Merging dSYM slices.')
            dsym_path = os.path.join(SDK_DSYM_NAME, 'Contents', 'Resources',
                                     'DWARF', 'WebRTC')
            lib_dsym_paths = [
                os.path.join(path, dsym_path) for path in lib_paths
            ]
            out_dsym_path = os.path.join(framework_path, dsym_path)
            try:
                os.remove(out_dsym_path)
            except OSError:
                pass
            cmd = ['lipo'
                   ] + lib_dsym_paths + ['-create', '-output', out_dsym_path]
            _RunCommand(cmd)

            # Check for Mac-style WebRTC.framework/Resources/ (for Catalyst)...
            resources_dir = os.path.join(framework_path, SDK_FRAMEWORK_NAME,
                                         'Resources')
            if not os.path.exists(resources_dir):
                # ...then fall back to iOS-style WebRTC.framework/
                resources_dir = os.path.dirname(resources_dir)

            # Modify the version number.
            # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>.
            # e.g. 55.0.14986 means
            # branch cut 55, no hotfixes, and revision 14986.
            infoplist_path = os.path.join(resources_dir, 'Info.plist')
            cmd = [
                'PlistBuddy', '-c', 'Print :CFBundleShortVersionString',
                infoplist_path
            ]
            major_minor = subprocess.check_output(cmd).decode('utf-8').strip()
            version_number = '%s.%s' % (major_minor, args.revision)
            logging.info('Substituting revision number: %s', version_number)
            cmd = [
                'PlistBuddy', '-c', 'Set :CFBundleVersion ' + version_number,
                infoplist_path
            ]
            _RunCommand(cmd)
            _RunCommand(['plutil', '-convert', 'binary1', infoplist_path])

    xcframework_dir = os.path.join(args.output_dir, SDK_XCFRAMEWORK_NAME)
    if os.path.isdir(xcframework_dir):
        shutil.rmtree(xcframework_dir)

    logging.info('Creating xcframework.')
    cmd = ['xcodebuild', '-create-xcframework', '-output', xcframework_dir]

    # Apparently, xcodebuild needs absolute paths for input arguments
    for framework_path in framework_paths:
        cmd += [
            '-framework',
            os.path.abspath(os.path.join(framework_path, SDK_FRAMEWORK_NAME)),
        ]
        dsym_full_path = os.path.join(framework_path, SDK_DSYM_NAME)
        if os.path.exists(dsym_full_path):
            cmd += ['-debug-symbols', os.path.abspath(dsym_full_path)]

    _RunCommand(cmd)

    # Generate the license file.
    logging.info('Generate license file.')
    gn_target_full_name = '//sdk:' + gn_target_name
    builder = LicenseBuilder(all_lib_paths, [gn_target_full_name])
    builder.GenerateLicenseText(
        os.path.join(args.output_dir, SDK_XCFRAMEWORK_NAME))

    logging.info('Done.')
    return 0
Ejemplo n.º 11
0
 def testGetThirdPartyLibraries(self):
     self.assertEquals(
         LicenseBuilder._GetThirdPartyLibraries('out/arm', 'target1'),
         set(['libname1', 'libname2', 'libname3']))