Merge pull request #2911 from element-hq/feature/bma/reproducibleBuild

Reproducible build
This commit is contained in:
Benoit Marty 2024-05-27 12:46:19 +02:00 committed by GitHub
commit 436a876317
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 6 deletions

View file

@ -36,6 +36,6 @@ class ElementXApplication : Application(), DaggerComponentOwner {
initializeComponent(TracingInitializer::class.java)
initializeComponent(CacheCleanerInitializer::class.java)
}
logApplicationInfo()
logApplicationInfo(this)
}
}

View file

@ -26,6 +26,7 @@ import dagger.Provides
import io.element.android.appconfig.ApplicationConfig
import io.element.android.features.messages.impl.timeline.components.customreaction.DefaultEmojibaseProvider
import io.element.android.features.messages.impl.timeline.components.customreaction.EmojibaseProvider
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.core.meta.BuildType
@ -87,7 +88,7 @@ object AppModule {
// TODO EAx Config.LOW_PRIVACY_LOG_ENABLE,
lowPrivacyLoggingEnabled = false,
versionName = BuildConfig.VERSION_NAME,
versionCode = BuildConfig.VERSION_CODE,
versionCode = context.getVersionCodeFromManifest(),
gitRevision = BuildConfig.GIT_REVISION,
gitBranchName = BuildConfig.GIT_BRANCH_NAME,
flavorDescription = BuildConfig.FLAVOR_DESCRIPTION,

View file

@ -16,17 +16,19 @@
package io.element.android.x.info
import android.content.Context
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
import io.element.android.x.BuildConfig
import timber.log.Timber
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
fun logApplicationInfo() {
fun logApplicationInfo(context: Context) {
val appVersion = buildString {
append(BuildConfig.VERSION_NAME)
append(" (")
append(BuildConfig.VERSION_CODE)
append(context.getVersionCodeFromManifest())
append(") - ")
append(BuildConfig.BUILD_TYPE)
append(" / ")

View file

@ -28,6 +28,7 @@ import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.RequiresApi
import androidx.core.content.pm.PackageInfoCompat
import io.element.android.libraries.androidutils.R
import io.element.android.libraries.androidutils.compat.getApplicationInfoCompat
import io.element.android.libraries.core.mimetype.MimeTypes
@ -47,6 +48,19 @@ fun Context.getApplicationLabel(packageName: String): String {
}
}
/**
* Retrieve the versionCode from the Manifest.
* The value is more accurate than BuildConfig.VERSION_CODE, as it is correct according to the
* computation in the `androidComponents` block of the app build.gradle.kts file.
* In other words, the last digit (for the architecture) will be set, whereas BuildConfig.VERSION_CODE
* last digit will always be 0.
*/
fun Context.getVersionCodeFromManifest(): Long {
return PackageInfoCompat.getLongVersionCode(
packageManager.getPackageInfo(packageName, 0)
)
}
// ==============================================================================================================
// Clipboard helper
// ==============================================================================================================

View file

@ -25,7 +25,7 @@ data class BuildMeta(
val applicationId: String,
val lowPrivacyLoggingEnabled: Boolean,
val versionName: String,
val versionCode: Int,
val versionCode: Long,
val gitRevision: String,
val gitBranchName: String,
val flavorDescription: String,

View file

@ -28,7 +28,7 @@ fun aBuildMeta(
applicationId: String = "",
lowPrivacyLoggingEnabled: Boolean = true,
versionName: String = "",
versionCode: Int = 0,
versionCode: Long = 0,
gitRevision: String = "",
gitBranchName: String = "",
flavorDescription: String = "",

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.tests.konsist
import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.ext.list.withImportNamed
import com.lemonappdev.konsist.api.verify.assertFalse
import org.junit.Test
class KonsistContentTest {
@Test
fun `assert that BuildConfig dot VersionCode is not used`() {
Konsist
.scopeFromProduction()
.files
.withImportNamed("io.element.android.x.BuildConfig")
.assertFalse(additionalMessage = "Please do not use BuildConfig.VERSION_CODE, but use the versionCode from BuildMeta") {
it.text.contains("BuildConfig.VERSION_CODE")
}
}
}