Skip to content

Commit

Permalink
Add initial warning for Termux users
Browse files Browse the repository at this point in the history
The protoc binary on Maven Central may return 'Bad System Call'
for users on Termux using AARCH64 systems.
  • Loading branch information
ascopes committed Nov 25, 2023
1 parent d1b8753 commit 55310c9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ public static Set<String> systemPathExtensions() {
}
}

/**
* Get the current working directory.
*
* @return the current working directory.
*/
public static Path workingDirectory() {
return Path.of("").toAbsolutePath();
}

// Visible for testing purposes only.
static Optional<String> environmentVariable(String name) {
return ofNullable(System.getenv(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.github.ascopes.protobufmavenplugin.resolve;

import java.nio.file.Files;
import java.nio.file.Path;
import io.github.ascopes.protobufmavenplugin.platform.HostEnvironment;
import org.apache.maven.shared.transfer.artifact.ArtifactCoordinate;
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
Expand Down Expand Up @@ -43,6 +45,8 @@ public final class MavenProtocCoordinateFactory {
* @throws ProtocResolutionException if the system is not supported.
*/
public ArtifactCoordinate create(String versionRange) throws ProtocResolutionException {
emitPlatformWarnings();

var coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(GROUP_ID);
coordinate.setArtifactId(ARTIFACT_ID);
Expand All @@ -52,6 +56,17 @@ public ArtifactCoordinate create(String versionRange) throws ProtocResolutionExc
return coordinate;
}

private void emitPlatformWarnings() {
if (HostEnvironment.workingDirectory().toString().startsWith("/data/data/com.termux")) {
LOGGER.warn(
"It appears you are running on Termux. You may have difficulties "
+ "invoking the 'protoc' executable from Maven Central. If this "
+ "is an issue, install protoc directly ('pkg in protoc'), and "
+ "invoke Maven with '-Dprotoc.version=PATH' instead."
);
}
}

private String determineClassifier() throws ProtocResolutionException {
String classifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,12 @@ void environmentVariableReturnsEmptyOptionalWhenVariableIsNotSet() {
assertThat(HostEnvironment.environmentVariable(unexpectedVariableName))
.isEmpty();
}

@DisplayName(".workingDirectory() returns the working directory")
@Test
void workingDirectoryReturnsTheWorkingDirectory() {
// Then
assertThat(HostEnvironment.workingDirectory())
.isEqualTo(Path.of("").toAbsolutePath());
}
}

0 comments on commit 55310c9

Please sign in to comment.