Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1906365 - Gradle plugin: support using an external venv. #2889

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dictionary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 283 utf-8
personal_ws-1.1 en 284 utf-8
AAR
AARs
ABI
Expand Down Expand Up @@ -271,6 +271,7 @@ urlbar
validator
vendored
vendoring
virtualenv
walkthrough
walkthroughs
webextension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ ext.gleanExpireByVersion = 25
Different products have different ways to compute the product version at build-time.
For this reason the Glean Gradle plugin cannot provide an automated way to detect the product major version at build time.
When using the expiration by version feature in Android, products must provide the major version by themselves.

## `gleanPythonEnvDir`

By default, the Glean Gradle plugin will manage its own Python virtualenv in `$gradleUserHomeDir/glean` to install `glean_parser`. By specifying a path in `ext.gleanPythonEnvDir` you can reuse an existing Python virtualenv.

```groovy
ext.gleanExpireByVersion = "$buildDir/externallyManagedVenv"
```

`glean_parser` must be available in that virtualenv, the Gradle plugin will make no attempt at installing it.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ The Glean Kotlin SDK uses a Python script, [`glean_parser`](https://github.com/m

For offline builds, the Python environment, and packages of `glean_parser` and its dependencies must be provided prior to building the Glean-using application.

To build a Glean-using application in offline mode, do the following:
To build a Glean-using application in offline mode, you can either:

### Provide an externally-managed virtualenv

Set `ext.gleanPythonEnvDir` to your existing virtualenv before applying the plugin, see [`gleanPythonEnvDir`](./android-build-configuration-options.md#gleanpythonenvdir).

### Provide a Python interpreter and the required wheels

In this mode Glean will setup its own virtualenv in `$gradleUserHomeDir/glean`, controlled by the `GLEAN_PYTHON` and `GLEAN_PYTHON_WHEELS_DIR` environment variables.

- Install Python 3.8 or later and ensure it's on the `PATH`.

Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This directory contains a Gradle plugin for build-time functionality,
such as generating specific metrics and documentation.

See `docs/user/adding-glean-to-your-project/index.md` for information about using this
See `docs/user/user/adding-glean-to-your-project/index.md` for information about using this
plugin.
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,12 @@ except:
// builds.
println("Requires glean_parser ${parserVersion}")

File envDir = setupPythonEnvironmentTasks(project, parserVersion)
// Store in both gleanCondaDir (for backward compatibility reasons) and
// the more accurate gleanPythonEnvDir variables.
project.ext.set("gleanCondaDir", envDir)
project.ext.set("gleanPythonEnvDir", envDir)
if (!project.ext.has("gleanPythonEnvDir")) {
File envDir = setupPythonEnvironmentTasks(project, parserVersion)
project.ext.set("gleanPythonEnvDir", envDir)
}
// Also store in gleanCondaDir for backward compatibility reasons
project.ext.set("gleanCondaDir", project.ext.gleanPythonEnvDir)

setupExtractMetricsFromAARTasks(project)

Expand All @@ -579,9 +580,9 @@ except:
}

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