Resolve build path leaks and enhance ADB readiness & Java sources handling
This commit is contained in:
@@ -186,6 +186,15 @@ def wait_for_authorization(serial: Optional[str] = None, timeout: float = 15.0)
|
||||
attention("Authorization timeout. Device is still unauthorized.")
|
||||
return False
|
||||
|
||||
def ensure_device_ready(timeout: float = 15.0) -> bool:
|
||||
ensure_server_running()
|
||||
state = get_device_state()
|
||||
if state == STATE_DEVICE_CONNECTED:
|
||||
return True
|
||||
if state in (STATE_DEVICE_AUTHORIZING, STATE_NO_DEVICES, STATE_DISCONNECTED, STATE_UNKNOWN):
|
||||
return wait_for_authorization(timeout=timeout)
|
||||
return False
|
||||
|
||||
def get_adb_command_by_serial(serial: str) -> List[str]:
|
||||
ensure_server_running()
|
||||
devices = GLOBALS.TOOLCHAIN_CONFIG.get_value("devices", list())
|
||||
|
||||
@@ -165,6 +165,10 @@ def task_push_everything() -> int:
|
||||
description="Starts launcher with predefined autostart setting on a connected device using ADB."
|
||||
)
|
||||
def task_monkey_launcher() -> int:
|
||||
from .device import ensure_device_ready
|
||||
if not ensure_device_ready():
|
||||
return 1
|
||||
|
||||
preferred_launcher = GLOBALS.PREFERRED_CONFIG.get_value("adb.launcherPackage")
|
||||
preferred_activity = GLOBALS.PREFERRED_CONFIG.get_value("adb.launcherActivity")
|
||||
from .device import (LAUNCHER_PACKAGES, launch_package_via_am,
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from .adb import (LAUNCHER_PACKAGES, STATE_DEVICE_AUTHORIZING,
|
||||
STATE_DEVICE_CONNECTED, STATE_DISCONNECTED, STATE_NO_DEVICES,
|
||||
STATE_UNKNOWN, device_list, download_adb,
|
||||
ensure_server_running, get_adb_command_by_serial,
|
||||
get_adb_command_by_serialno_type, get_adb_command_by_tcp,
|
||||
get_adb_executable, get_device_serial, get_device_state,
|
||||
launch_package_via_am, launch_package_via_monkey, ls,
|
||||
test_directory_exist, wait_for_authorization, which_state)
|
||||
ensure_device_ready, ensure_server_running,
|
||||
get_adb_command_by_serial, get_adb_command_by_serialno_type,
|
||||
get_adb_command_by_tcp, get_adb_executable,
|
||||
get_device_serial, get_device_state, launch_package_via_am,
|
||||
launch_package_via_monkey, ls, test_directory_exist,
|
||||
wait_for_authorization, which_state)
|
||||
from .device_setup import (get_adb_command, person_readable_device_name,
|
||||
setup_device_connection, setup_externally,
|
||||
setup_how_to_use, setup_via_network,
|
||||
@@ -20,7 +21,7 @@ from .push import make_locks, push_directory, push_everything, push_file
|
||||
|
||||
__all__ = [
|
||||
"get_ip", "ping", "ping_async", "ping_via_shell", "connect", "connect_async",
|
||||
"download_adb", "get_adb_executable", "ensure_server_running", "get_device_state",
|
||||
"download_adb", "get_adb_executable", "ensure_server_running", "ensure_device_ready", "get_device_state",
|
||||
"get_device_serial", "device_list", "which_state", "wait_for_authorization",
|
||||
"get_adb_command_by_serial", "get_adb_command_by_tcp",
|
||||
"get_adb_command_by_serialno_type", "launch_package_via_am",
|
||||
|
||||
@@ -570,9 +570,12 @@ def build_java_directories(tool: str, directories: Iterable[MakeJavaData], targe
|
||||
|
||||
if target.manifest.keep_sources:
|
||||
target_sources_directory = join(target_directory, "classes", target.relative_directory, "generated", "sources")
|
||||
sources_jar = join(target.output_directory, "classpath-sources.jar")
|
||||
sources_jar = join(target.output_directory, f"{target.manifest.output_path}-sources.jar")
|
||||
legacy_sources_jar = join(target.output_directory, "classpath-sources.jar")
|
||||
if isfile(sources_jar):
|
||||
os.remove(sources_jar)
|
||||
if isfile(legacy_sources_jar):
|
||||
os.remove(legacy_sources_jar)
|
||||
|
||||
with ZipFile(sources_jar, "w") as archive:
|
||||
has_sources = False
|
||||
@@ -586,8 +589,18 @@ def build_java_directories(tool: str, directories: Iterable[MakeJavaData], targe
|
||||
walk_all_files(abs_src_dir, lambda path: archive.write(path, arcname=relpath(path, abs_src_dir)))
|
||||
has_sources = True
|
||||
|
||||
for lib_dir in target.manifest.libraries:
|
||||
abs_lib_dir = join(target.directory, lib_dir)
|
||||
if isdir(abs_lib_dir):
|
||||
for lib_file in get_all_files(abs_lib_dir, (".jar")):
|
||||
if lib_file.endswith(("-sources.jar", "-javadoc.jar")):
|
||||
walk_all_files(lib_file, lambda path: archive.write(path, arcname=relpath(path, abs_lib_dir)))
|
||||
has_sources = True
|
||||
|
||||
if not has_sources and isfile(sources_jar):
|
||||
os.remove(sources_jar)
|
||||
elif isfile(sources_jar):
|
||||
copy_file(sources_jar, legacy_sources_jar)
|
||||
|
||||
if not built_successfully:
|
||||
attention(f"Directory {target.relative_directory!r} is empty.")
|
||||
|
||||
@@ -11,6 +11,10 @@ from .utils import DEVNULL
|
||||
|
||||
|
||||
def push_everything(push_unchanged: bool = True, cleanup_remote: bool = True) -> int:
|
||||
from .adb import ensure_device_ready
|
||||
if not ensure_device_ready():
|
||||
return 1
|
||||
|
||||
destination_directory = get_modpack_push_directory()
|
||||
if not destination_directory:
|
||||
# probably someday it will return 0, but only when we merge push and launch
|
||||
|
||||
Reference in New Issue
Block a user