mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 14:30:30 +03:00 
			
		
		
		
	metadata: allow ndk: to be str or list of release or revision
				
					
				
			There are two version numbers used for NDKs: the "release" and the "revision". The "release" is used in the download URL and zipball and the "revision" is used in the source.properties and the gradle ndkVersion field. Also, there are some builds which need multiple NDKs installed, so this makes it possible to have a list of release/revision entries in build.ndk. This does not yet add full support since _fdroidserver/build.py_ will also need changes.
This commit is contained in:
		
							parent
							
								
									096532dddb
								
							
						
					
					
						commit
						4686c06f62
					
				
					 3 changed files with 67 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -4021,6 +4021,32 @@ def auto_install_ndk(build):
 | 
			
		|||
    ndk = build.get('ndk')
 | 
			
		||||
    if not ndk:
 | 
			
		||||
        return
 | 
			
		||||
    if isinstance(ndk, str):
 | 
			
		||||
        _install_ndk(ndk)
 | 
			
		||||
    elif isinstance(ndk, list):
 | 
			
		||||
        for n in ndk:
 | 
			
		||||
            _install_ndk(n)
 | 
			
		||||
    else:
 | 
			
		||||
        BuildException(_('Invalid ndk: entry in build: "{ndk}"')
 | 
			
		||||
                       .format(ndk=str(ndk)))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _install_ndk(ndk):
 | 
			
		||||
    """Install specified NDK if it is not already installed
 | 
			
		||||
 | 
			
		||||
    Parameters
 | 
			
		||||
    ----------
 | 
			
		||||
 | 
			
		||||
    ndk
 | 
			
		||||
        The NDK version to install, either in "release" form (r21e) or
 | 
			
		||||
        "revision" form (21.4.7075529).
 | 
			
		||||
    """
 | 
			
		||||
    if re.match(r'[1-9][0-9.]+[0-9]', ndk):
 | 
			
		||||
        for ndkdict in NDKS:
 | 
			
		||||
            if ndk == ndkdict['revision']:
 | 
			
		||||
                ndk = ndkdict['release']
 | 
			
		||||
                break
 | 
			
		||||
 | 
			
		||||
    ndk_path = config.get(ndk)
 | 
			
		||||
    if ndk_path and os.path.isdir(ndk_path):
 | 
			
		||||
        return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -326,7 +326,11 @@ class Build(dict):
 | 
			
		|||
        return 'ant'
 | 
			
		||||
 | 
			
		||||
    def ndk_path(self):
 | 
			
		||||
        return fdroidserver.common.config['ndk_paths'].get(self.ndk, '')
 | 
			
		||||
        """Returns the path to the first configured NDK or an empty string"""
 | 
			
		||||
        ndk = self.ndk
 | 
			
		||||
        if isinstance(ndk, list):
 | 
			
		||||
            ndk = self.ndk[0]
 | 
			
		||||
        return fdroidserver.common.config['ndk_paths'].get(ndk, '')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
flagtypes = {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1796,6 +1796,42 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
            fdroidserver.common.metadata_find_developer_signing_files(appid, vc)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_auto_install_ndk(self):
 | 
			
		||||
        """Test all possible field data types for build.ndk"""
 | 
			
		||||
        build = fdroidserver.metadata.Build()
 | 
			
		||||
 | 
			
		||||
        none_entry = mock.Mock()
 | 
			
		||||
        with mock.patch('fdroidserver.common._install_ndk', none_entry):
 | 
			
		||||
            fdroidserver.common.auto_install_ndk(build)
 | 
			
		||||
            none_entry.assert_not_called()
 | 
			
		||||
 | 
			
		||||
        empty_list = mock.Mock()
 | 
			
		||||
        build.ndk = []
 | 
			
		||||
        with mock.patch('fdroidserver.common._install_ndk', empty_list):
 | 
			
		||||
            fdroidserver.common.auto_install_ndk(build)
 | 
			
		||||
            empty_list.assert_not_called()
 | 
			
		||||
 | 
			
		||||
        release_entry = mock.Mock()
 | 
			
		||||
        build.ndk = 'r21e'
 | 
			
		||||
        with mock.patch('fdroidserver.common._install_ndk', release_entry):
 | 
			
		||||
            fdroidserver.common.auto_install_ndk(build)
 | 
			
		||||
            release_entry.assert_called_once_with('r21e')
 | 
			
		||||
 | 
			
		||||
        revision_entry = mock.Mock()
 | 
			
		||||
        build.ndk = '21.4.7075529'
 | 
			
		||||
        with mock.patch('fdroidserver.common._install_ndk', revision_entry):
 | 
			
		||||
            fdroidserver.common.auto_install_ndk(build)
 | 
			
		||||
            revision_entry.assert_called_once_with('21.4.7075529')
 | 
			
		||||
 | 
			
		||||
        list_entry = mock.Mock()
 | 
			
		||||
        calls = []
 | 
			
		||||
        build.ndk = ['11.0.2655954', 'r12b', 'r21e']
 | 
			
		||||
        for n in build.ndk:
 | 
			
		||||
            calls.append(mock.call(n))
 | 
			
		||||
        with mock.patch('fdroidserver.common._install_ndk', list_entry):
 | 
			
		||||
            fdroidserver.common.auto_install_ndk(build)
 | 
			
		||||
            list_entry.assert_has_calls(calls)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue