mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 06:30:27 +03:00 
			
		
		
		
	Revert: gradle file: use flavour specific versionCode/versionName, fall back to parsing line by line
This commit is contained in:
		
							parent
							
								
									8c243ee7eb
								
							
						
					
					
						commit
						918bd15c45
					
				
					 3 changed files with 19 additions and 108 deletions
				
			
		| 
						 | 
				
			
			@ -1336,58 +1336,27 @@ def parse_androidmanifests(paths, app):
 | 
			
		|||
        vercode = None
 | 
			
		||||
        package = None
 | 
			
		||||
 | 
			
		||||
        flavour = ""
 | 
			
		||||
        if app.builds and 'gradle' in app.builds[-1] and app.builds[-1].gradle:
 | 
			
		||||
                flavour = app.builds[-1].gradle[-1]
 | 
			
		||||
 | 
			
		||||
        if has_extension(path, 'gradle'):
 | 
			
		||||
            # first try to get version name and code from correct flavour
 | 
			
		||||
            with open(path, 'r') as f:
 | 
			
		||||
                buildfile = f.read()
 | 
			
		||||
 | 
			
		||||
                regex_string = r"" + flavour + "[^}]*?{.*?}"
 | 
			
		||||
                search = re.compile(regex_string, re.DOTALL)
 | 
			
		||||
                result = search.search(buildfile)
 | 
			
		||||
 | 
			
		||||
            if result is not None:
 | 
			
		||||
                resultgroup = result.group()
 | 
			
		||||
 | 
			
		||||
                if not package:
 | 
			
		||||
                    matches = psearch_g(resultgroup)
 | 
			
		||||
                    if matches:
 | 
			
		||||
                        s = matches.group(2)
 | 
			
		||||
                        if app_matches_packagename(app, s):
 | 
			
		||||
                            package = s
 | 
			
		||||
                if not version:
 | 
			
		||||
                    matches = vnsearch_g(resultgroup)
 | 
			
		||||
                    if matches:
 | 
			
		||||
                        version = matches.group(2)
 | 
			
		||||
                if not vercode:
 | 
			
		||||
                    matches = vcsearch_g(resultgroup)
 | 
			
		||||
                    if matches:
 | 
			
		||||
                        vercode = matches.group(1)
 | 
			
		||||
            else:
 | 
			
		||||
                # fall back to parse file line by line
 | 
			
		||||
                with open(path, 'r') as f:
 | 
			
		||||
                    for line in f:
 | 
			
		||||
                        if gradle_comment.match(line):
 | 
			
		||||
                            continue
 | 
			
		||||
                        # Grab first occurence of each to avoid running into
 | 
			
		||||
                        # alternative flavours and builds.
 | 
			
		||||
                        if not package:
 | 
			
		||||
                            matches = psearch_g(line)
 | 
			
		||||
                            if matches:
 | 
			
		||||
                                s = matches.group(2)
 | 
			
		||||
                                if app_matches_packagename(app, s):
 | 
			
		||||
                                    package = s
 | 
			
		||||
                        if not version:
 | 
			
		||||
                            matches = vnsearch_g(line)
 | 
			
		||||
                            if matches:
 | 
			
		||||
                                version = matches.group(2)
 | 
			
		||||
                        if not vercode:
 | 
			
		||||
                            matches = vcsearch_g(line)
 | 
			
		||||
                            if matches:
 | 
			
		||||
                                vercode = matches.group(1)
 | 
			
		||||
                for line in f:
 | 
			
		||||
                    if gradle_comment.match(line):
 | 
			
		||||
                        continue
 | 
			
		||||
                    # Grab first occurence of each to avoid running into
 | 
			
		||||
                    # alternative flavours and builds.
 | 
			
		||||
                    if not package:
 | 
			
		||||
                        matches = psearch_g(line)
 | 
			
		||||
                        if matches:
 | 
			
		||||
                            s = matches.group(2)
 | 
			
		||||
                            if app_matches_packagename(app, s):
 | 
			
		||||
                                package = s
 | 
			
		||||
                    if not version:
 | 
			
		||||
                        matches = vnsearch_g(line)
 | 
			
		||||
                        if matches:
 | 
			
		||||
                            version = matches.group(2)
 | 
			
		||||
                    if not vercode:
 | 
			
		||||
                        matches = vcsearch_g(line)
 | 
			
		||||
                        if matches:
 | 
			
		||||
                            vercode = matches.group(1)
 | 
			
		||||
        else:
 | 
			
		||||
            try:
 | 
			
		||||
                xml = parse_xml(path)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -612,49 +612,6 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        sig = fdroidserver.common.metadata_find_developer_signature('org.smssecure.smssecure')
 | 
			
		||||
        self.assertEqual('b30bb971af0d134866e158ec748fcd553df97c150f58b0a963190bbafbeb0868', sig)
 | 
			
		||||
 | 
			
		||||
    def test_parse_androidmanifests(self):
 | 
			
		||||
        source_files_dir = os.path.join(os.path.dirname(__file__), 'source-files')
 | 
			
		||||
        app = fdroidserver.metadata.App()
 | 
			
		||||
        app.id = 'org.fdroid.fdroid'
 | 
			
		||||
        paths = [
 | 
			
		||||
            os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'AndroidManifest.xml'),
 | 
			
		||||
            os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'build.gradle'),
 | 
			
		||||
        ]
 | 
			
		||||
        for path in paths:
 | 
			
		||||
            self.assertTrue(os.path.isfile(path))
 | 
			
		||||
        self.assertEqual(('0.94-test', '940', 'org.fdroid.fdroid'),
 | 
			
		||||
                         fdroidserver.common.parse_androidmanifests(paths, app))
 | 
			
		||||
 | 
			
		||||
    def test_parse_androidmanifests_with_flavor(self):
 | 
			
		||||
        source_files_dir = os.path.join(os.path.dirname(__file__), 'source-files')
 | 
			
		||||
 | 
			
		||||
        app = fdroidserver.metadata.App()
 | 
			
		||||
        build = fdroidserver.metadata.Build()
 | 
			
		||||
        build.gradle = ['devVersion']
 | 
			
		||||
        app.builds = [build]
 | 
			
		||||
        app.id = 'org.fdroid.fdroid.dev'
 | 
			
		||||
        paths = [
 | 
			
		||||
            os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'AndroidManifest.xml'),
 | 
			
		||||
            os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'build.gradle'),
 | 
			
		||||
        ]
 | 
			
		||||
        for path in paths:
 | 
			
		||||
            self.assertTrue(os.path.isfile(path))
 | 
			
		||||
        self.assertEqual(('0.95-dev', '949', 'org.fdroid.fdroid.dev'),
 | 
			
		||||
                         fdroidserver.common.parse_androidmanifests(paths, app))
 | 
			
		||||
 | 
			
		||||
        app = fdroidserver.metadata.App()
 | 
			
		||||
        build = fdroidserver.metadata.Build()
 | 
			
		||||
        build.gradle = ['free']
 | 
			
		||||
        app.builds = [build]
 | 
			
		||||
        app.id = 'eu.siacs.conversations'
 | 
			
		||||
        paths = [
 | 
			
		||||
            os.path.join(source_files_dir, 'eu.siacs.conversations', 'build.gradle'),
 | 
			
		||||
        ]
 | 
			
		||||
        for path in paths:
 | 
			
		||||
            self.assertTrue(os.path.isfile(path))
 | 
			
		||||
        self.assertEqual(('1.23.1', '245', 'eu.siacs.conversations'),
 | 
			
		||||
                         fdroidserver.common.parse_androidmanifests(paths, app))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -128,21 +128,6 @@ task binaryDeps(type: Copy, dependsOn: ':F-Droid:prepareReleaseDependencies') {
 | 
			
		|||
android {
 | 
			
		||||
    compileSdkVersion 21
 | 
			
		||||
    buildToolsVersion '22.0.1'
 | 
			
		||||
    
 | 
			
		||||
    defaultConfig {
 | 
			
		||||
    
 | 
			
		||||
        flavorDimensions "default"
 | 
			
		||||
                
 | 
			
		||||
        productFlavors {
 | 
			
		||||
            devVersion {
 | 
			
		||||
                applicationId "org.fdroid.fdroid.dev"
 | 
			
		||||
                dimension "default"
 | 
			
		||||
                versionCode 949
 | 
			
		||||
                versionName "0.95-dev"
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sourceSets {
 | 
			
		||||
        main {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue