@@ -23,67 +23,51 @@ spotless {
2323import org.gradle.api.tasks.*
2424import javax.inject.Inject
2525
26- // Task to extract and patch Kolibri tar file (replicates Makefile install-tar)
27- abstract class PatchKolibriTask extends DefaultTask {
26+ // Task to extract Kolibri tar file, stripping unnecessary packages
27+ abstract class StreamlineKolibriTask extends DefaultTask {
2828 @InputFile
2929 abstract RegularFileProperty getTarFile ()
3030
3131 @OutputDirectory
32- abstract DirectoryProperty getPatchedDir ()
32+ abstract DirectoryProperty getExtractedDir ()
3333
3434 @Inject
3535 abstract ExecOperations getExecOperations ()
3636
37- @TaskAction
38- void patchKolibri () {
39- def tarFile = getTarFile(). get(). asFile
40- def patchedDir = getPatchedDir(). get(). asFile
37+ /* * Extract Kolibri tar, cleaning the output directory and stripping unnecessary packages. */
38+ static void extract (File tarFile , File extractedDir , def execOps ) {
39+ println " Extracting Kolibri from ${ tarFile.name} "
4140
42- if (! tarFile . exists()) {
43- throw new GradleException ( " Kolibri tar file not found: ${ tarFile } " )
41+ if (extractedDir . exists()) {
42+ extractedDir . deleteDir( )
4443 }
44+ extractedDir. mkdirs()
4545
46- println " Patching Kolibri from ${ tarFile.name} "
47-
48- // Clean and create patched directory
49- if (patchedDir. exists()) {
50- patchedDir. deleteDir()
51- }
52- patchedDir. mkdirs()
53-
54- // Extract tar file, excluding problematic packages
55- execOperations. exec {
46+ execOps. exec {
5647 commandLine ' tar' , ' xzf' , tarFile. absolutePath,
57- ' --exclude=kolibri/dist/py2only*' ,
5848 ' --exclude=kolibri/dist/cext/*' ,
5949 ' --exclude=kolibri/dist/ifaddr*' ,
60- ' --directory=' + patchedDir . absolutePath,
50+ ' --directory=' + extractedDir . absolutePath,
6151 ' --strip-components=1'
6252 }
6353
64- // Patch Django to allow .pyc migration files
65- // This is critical because Chaquopy compiles .py files and deletes them
66- def djangoLoader = new File (patchedDir, ' kolibri/dist/django/db/migrations/loader.py' )
67- if (djangoLoader. exists()) {
68- def content = djangoLoader. text
69- content = content. replace(
70- ' if name.endswith(".py"):' ,
71- ' if name.endswith(".py") or name.endswith(".pyc"):'
72- )
73- djangoLoader. text = content
74- println " Patched Django migrations loader"
75- } else {
76- throw new GradleException (" Could not find Django loader.py to patch" )
77- }
54+ println " Kolibri extracted successfully at ${ extractedDir.absolutePath} "
55+ }
7856
79- println " Kolibri patched successfully at ${ patchedDir.absolutePath} "
57+ @TaskAction
58+ void streamlineKolibri () {
59+ def tarFile = getTarFile(). get(). asFile
60+ if (! tarFile. exists()) {
61+ throw new GradleException (" Kolibri tar file not found: ${ tarFile} " )
62+ }
63+ extract(tarFile, getExtractedDir(). get(). asFile, execOperations)
8064 }
8165}
8266
83- tasks. register(' patchKolibriTar ' , PatchKolibriTask ) {
67+ tasks. register(' streamlineKolibriTar ' , StreamlineKolibriTask ) {
8468 def tarFile = file(' ../tar' ). listFiles()?. find { it. name. endsWith(' .tar.gz' ) && it. name. startsWith(' kolibri' ) }
8569 getTarFile(). set(tarFile)
86- getPatchedDir (). set(file(' ../tar/patched ' ))
70+ getExtractedDir (). set(file(' ../tar/extracted ' ))
8771}
8872
8973// Determine which Python to use for build scripts
@@ -93,52 +77,22 @@ if (venvPython.exists()) {
9377 buildPythonExecutable = venvPython. absolutePath
9478}
9579
96- // Ensure Kolibri tar is patched during configuration phase
80+ // Ensure Kolibri tar is extracted during configuration phase
9781// This is necessary so version can be calculated before tasks run
98- def patchedKolibriDir = file(' ../tar/patched ' )
82+ def extractedKolibriDir = file(' ../tar/extracted ' )
9983def tarFile = file(' ../tar' ). listFiles()?. find { it. name. endsWith(' .tar.gz' ) && it. name. startsWith(' kolibri' ) }
10084
101- if (tarFile != null && tarFile. exists() && ! new File (patchedKolibriDir, ' kolibri/VERSION' ). exists()) {
102- println " Extracting and patching Kolibri tar during configuration..."
103-
104- // Clean and create patched directory
105- if (patchedKolibriDir. exists()) {
106- patchedKolibriDir. deleteDir()
107- }
108- patchedKolibriDir. mkdirs()
109-
110- // Extract tar file, excluding problematic packages
111- exec {
112- commandLine ' tar' , ' xzf' , tarFile. absolutePath,
113- ' --exclude=kolibri/dist/py2only*' ,
114- ' --exclude=kolibri/dist/cext/*' ,
115- ' --exclude=kolibri/dist/ifaddr*' ,
116- ' --directory=' + patchedKolibriDir. absolutePath,
117- ' --strip-components=1'
118- }
119-
120- // Patch Django to allow .pyc migration files
121- def djangoLoader = new File (patchedKolibriDir, ' kolibri/dist/django/db/migrations/loader.py' )
122- if (djangoLoader. exists()) {
123- def content = djangoLoader. text
124- content = content. replace(
125- ' if name.endswith(".py"):' ,
126- ' if name.endswith(".py") or name.endswith(".pyc"):'
127- )
128- djangoLoader. text = content
129- println " Patched Django migrations loader"
130- }
131-
132- println " Kolibri patched successfully"
85+ if (tarFile != null && tarFile. exists() && ! new File (extractedKolibriDir, ' kolibri/VERSION' ). exists()) {
86+ StreamlineKolibriTask . extract(tarFile, extractedKolibriDir, this )
13387}
13488
13589// Calculate version name and code
13690def calculatedVersionName
13791def calculatedVersionCode
13892
139- if (patchedKolibriDir . exists() && patchedKolibriDir . isDirectory()) {
93+ if (extractedKolibriDir . exists() && extractedKolibriDir . isDirectory()) {
14094 // Read VERSION_NAME from Kolibri's VERSION file
141- def kolibriVersionFile = new File (patchedKolibriDir , ' kolibri/VERSION' )
95+ def kolibriVersionFile = new File (extractedKolibriDir , ' kolibri/VERSION' )
14296 if (! kolibriVersionFile. exists()) {
14397 throw new GradleException (" Kolibri VERSION file not found at: ${ kolibriVersionFile} " )
14498 }
@@ -211,21 +165,21 @@ abstract class GenerateKolibriStringsTask extends DefaultTask {
211165}
212166
213167tasks. register(' generateKolibriStrings' , GenerateKolibriStringsTask ) {
214- dependsOn patchKolibriTar
168+ dependsOn streamlineKolibriTar
215169 getScriptFile(). set(file(' ../scripts/create_strings.py' ))
216170 getResDir(). set(file(' src/main/res' ))
217171 // Version text input is sufficient - when it changes, task reruns
218172 getVersionText(). set(calculatedVersionName)
219173 getPythonExecutable(). set(buildPythonExecutable)
220174}
221175
222- // Make sure Kolibri is patched before Python requirements are generated
176+ // Make sure Kolibri is extracted before Python requirements are generated
223177afterEvaluate {
224178 tasks. matching { task ->
225179 task. name. contains(' PythonRequirements' ) ||
226180 task. name. contains(' extractPythonBuildPackages' )
227181 }. all { task ->
228- task. dependsOn patchKolibriTar
182+ task. dependsOn streamlineKolibriTar
229183 }
230184
231185 // Generate strings before resources are processed or mapped
@@ -278,8 +232,8 @@ android {
278232
279233 pip {
280234 // Install Kolibri from patched tar file
281- // The patchKolibriTar task extracts and patches the tar before this runs
282- install " ../tar/patched "
235+ // The streamlineKolibriTar task extracts the tar before this runs
236+ install " ../tar/extracted "
283237 install " -r" , " ../requirements.txt"
284238 }
285239 }
0 commit comments