From ad73fef7570b37aea10822ecf01f706ebbf87911 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Fri, 7 May 2021 12:18:40 +0200 Subject: [PATCH] fix(./make): chdir before signing for Android (#339) More cleanup after https://github.com/ooni/probe/issues/1466 --- make | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/make b/make index 5c6fa50..a18c86a 100755 --- a/make +++ b/make @@ -256,7 +256,7 @@ The third form of the command prints this help screen. def _print_target(self, target: Target, indent: int) -> None: sys.stdout.write( - '{}{}{}\n'.format( + "{}{}{}\n".format( " " * indent, target.name(), ":" if target.deps() else "" ) ) @@ -468,6 +468,23 @@ class AugmentedPath(Environ): super().__init__(engine, "PATH", value) +class WorkingDir: + """WorkingDir is a context manager that enters into a given working + directory and returns to the previous directory when done.""" + + def __init__(self, dirpath: str) -> None: + self._dirpath = dirpath + self._prev: str = "" + + def __enter__(self) -> None: + self._prev = os.getcwd() + os.chdir(self._dirpath) + + def __exit__(self, type: Any, value: Any, traceback: Any) -> bool: + os.chdir(self._prev) + return False # propagate exc + + class Target(Protocol): """Target is a target to build.""" @@ -853,9 +870,10 @@ class BundleJAR(BaseTarget): "oonimkall-{}.pom".format(version), ) allnames: List[str] = [] - for name in names: - allnames.append(name) - allnames.append(sign(engine, name)) + with WorkingDir(os.path.join(".", "MOBILE", "android")): + for name in names: + allnames.append(name) + allnames.append(sign(engine, name)) engine.run( [ "jar",