Skip to content

Commit

Permalink
Merge pull request #1654 from badboy/skip-buildinfo-generation
Browse files Browse the repository at this point in the history
Bug 1713084 - Glean Plugin: Skip buildinfo generation for libraries
  • Loading branch information
badboy authored May 28, 2021
2 parents 5d40717 + 9935f3e commit 9cac57f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* Android
* **Deprecation**: The old event recording API is replaced by a new one, accepting a typed object ([#1603](https://github.com/mozilla/glean/pull/1603)).
See [the event documentation](https://mozilla.github.io/glean/book/reference/metrics/event.html#recordobject) for details.
* Skip build info generation for libraries ([#1654](https://github.com/mozilla/glean/pull/1654))
* Python
* **Deprecation**: The old event recording API is replaced by a new one, accepting a typed object ([#1603](https://github.com/mozilla/glean/pull/1603)).
See [the event documentation](https://mozilla.github.io/glean/book/reference/metrics/event.html#recordobject) for details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.coroutines.Dispatchers as KotlinDispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.runBlocking
import mozilla.telemetry.glean.GleanMetrics.GleanBuildInfo
import mozilla.telemetry.glean.GleanMetrics.GleanError
import mozilla.telemetry.glean.GleanMetrics.GleanInternalMetrics
import mozilla.telemetry.glean.GleanMetrics.Pings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ import java.util.Calendar
import java.util.UUID
import java.util.concurrent.ExecutionException

// This will be generated by the glean_parser for applications only.
// For testing purposes we create it ourselves.
object GleanBuildInfo {
val buildInfo: BuildInfo by lazy {
BuildInfo(
versionCode = "0.0.1",
versionName = "0.0.1"
)
}
}

/**
* Checks ping content against the Glean ping schema.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.work.testing.WorkManagerTestInitHelper
import mozilla.telemetry.glean.Glean
import mozilla.telemetry.glean.GleanMetrics.GleanBuildInfo
import mozilla.telemetry.glean.GleanBuildInfo
import mozilla.telemetry.glean.Dispatchers
import mozilla.telemetry.glean.config.Configuration
import org.junit.After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.telemetry.glean.Dispatchers
import mozilla.telemetry.glean.Glean
import mozilla.telemetry.glean.collectAndCheckPingSchema
import mozilla.telemetry.glean.GleanMetrics.GleanBuildInfo
import mozilla.telemetry.glean.GleanBuildInfo
import mozilla.telemetry.glean.GleanMetrics.Pings
import mozilla.telemetry.glean.testing.ErrorType
import mozilla.telemetry.glean.testing.GleanTestRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import java.lang.NullPointerException
import mozilla.telemetry.glean.Dispatchers
import mozilla.telemetry.glean.Glean
import mozilla.telemetry.glean.GleanMetrics.GleanBuildInfo
import mozilla.telemetry.glean.GleanBuildInfo
import mozilla.telemetry.glean.GleanTimerId
import mozilla.telemetry.glean.testing.ErrorType
import mozilla.telemetry.glean.testing.GleanTestRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.work.testing.WorkManagerTestInitHelper
import mozilla.telemetry.glean.any
import mozilla.telemetry.glean.Glean
import mozilla.telemetry.glean.GleanMetrics.GleanBuildInfo
import mozilla.telemetry.glean.GleanBuildInfo
import mozilla.telemetry.glean.GleanMetrics.Pings
import mozilla.telemetry.glean.checkPingSchema
import mozilla.telemetry.glean.private.Lifetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ except:
/*
* Adds tasks that generates the Glean metrics API for a project.
*/
def setupTasks(Project project, File envDir) {
def setupTasks(Project project, File envDir, boolean isApplication) {
return { variant ->
def sourceOutputDir = "${project.buildDir}/generated/source/glean/${variant.dirName}/kotlin"
// Get the name of the package as if it were to be used in the R or BuildConfig
Expand Down Expand Up @@ -200,6 +200,14 @@ except:
args "--allow-reserved"
}

// Only generate build info for applications, not for libraries.
// From android-gradle 7.0 on the `VERSION_CODE` and `VERSION_NAME` fields
// are not set for libraries anymore
if (!isApplication) {
args "-s"
args "with_buildinfo=false"
}

doFirst {
// Add the potential 'metrics.yaml' files at evaluation-time, rather than
// configuration-time. Otherwise the Gradle build will fail.
Expand Down Expand Up @@ -497,9 +505,9 @@ except:
setupExtractMetricsFromAARTasks(project)

if (project.android.hasProperty('applicationVariants')) {
project.android.applicationVariants.all(setupTasks(project, envDir))
project.android.applicationVariants.all(setupTasks(project, envDir, true))
} else {
project.android.libraryVariants.all(setupTasks(project, envDir))
project.android.libraryVariants.all(setupTasks(project, envDir, false))
}
}
}
Expand Down

0 comments on commit 9cac57f

Please sign in to comment.