Skip to content
Open
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
13 changes: 12 additions & 1 deletion Android/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,15 @@ def setup_testbed():
def build_testbed(context):
setup_sdk()
setup_testbed()

# Ensure that CROSS_BUILD_DIR is in the Gradle environment, regardless
# of whether it was set by environment variable or `--cross-build-dir`.
env = os.environ.copy()
env["CROSS_BUILD_DIR"] = CROSS_BUILD_DIR
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say that we could avoid duplication by setting this environment variable in main. However, running the app outside of this script isn't actually useful in practice, so I suggest instead deleting the build-testbed command completely.

run(
[gradlew, "--console", "plain", "packageDebug", "packageDebugAndroidTest"],
cwd=TESTBED_DIR,
env=env,
)


Expand Down Expand Up @@ -645,6 +651,10 @@ async def gradle_task(context):
task_prefix = "connected"
env["ANDROID_SERIAL"] = context.connected

# Ensure that CROSS_BUILD_DIR is in the Gradle environment, regardless
# of whether it was set by environment variable or `--cross-build-dir`.
env["CROSS_BUILD_DIR"] = CROSS_BUILD_DIR

if context.ci_mode:
context.args[0:0] = [
# See _add_ci_python_opts in libregrtest/main.py.
Expand Down Expand Up @@ -896,7 +906,7 @@ def add_parser(*args, **kwargs):
help="Delete build directories for the selected target"
)

add_parser("build-testbed", help="Build the testbed app")
build_testbed = add_parser("build-testbed", help="Build the testbed app")
test = add_parser("test", help="Run the testbed app")
package = add_parser("package", help="Make a release package")
ci = add_parser("ci", help="Run build, package and test")
Expand All @@ -912,6 +922,7 @@ def add_parser(*args, **kwargs):
make_host,
build,
package,
build_testbed,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main accesses context.cross_build_dir unconditionally even though not every command has this option. In pypa/cibuildwheel#2818 I worked around this using getattr, but in fact every command should have this option, because even env calls subdir in some situations. So I suggest moving the add_argument("--cross-build-dir") call to add_parser.

test,
ci,
]:
Expand Down
5 changes: 4 additions & 1 deletion Android/testbed/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ plugins {

val ANDROID_DIR = file("../..")
val PYTHON_DIR = ANDROID_DIR.parentFile!!
val PYTHON_CROSS_DIR = file("$PYTHON_DIR/cross-build")
val CROSS_BUILD_DIR = System.getenv("CROSS_BUILD_DIR") ?: "cross-build"
val PYTHON_CROSS_DIR = file(
if ((File(CROSS_BUILD_DIR)).isAbsolute) CROSS_BUILD_DIR else "$PYTHON_DIR/$CROSS_BUILD_DIR"
Comment on lines +11 to +13
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running Gradle from android.py, the environment variable will always be absolute. But if Gradle is run directly, the user would expect relative paths to be resolved not against PYTHON_DIR, but the working directory, which I think file already does.

Suggested change
val CROSS_BUILD_DIR = System.getenv("CROSS_BUILD_DIR") ?: "cross-build"
val PYTHON_CROSS_DIR = file(
if ((File(CROSS_BUILD_DIR)).isAbsolute) CROSS_BUILD_DIR else "$PYTHON_DIR/$CROSS_BUILD_DIR"
val PYTHON_CROSS_DIR = file(System.getenv("CROSS_BUILD_DIR") ?: "$PYTHON_DIR/cross-build")

)
val inSourceTree = (
ANDROID_DIR.name == "Android" && file("$PYTHON_DIR/pyconfig.h.in").exists()
)
Expand Down
Loading