Skip to content

Commit f0fd12e

Browse files
committed
Try adding 1.8.7 support
1 parent 3e7fe32 commit f0fd12e

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

bin/copy_java_sources.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,33 @@
88
import shutil
99
import sys
1010
from pathlib import Path
11+
from typing import Tuple, Optional
1112

1213
BASEDIR = Path(sys.argv[1])
1314
RELEASE = sys.argv[2]
1415
VERSION = RELEASE.split("-")[0]
15-
AP_SOURCE_DIR = BASEDIR / "ap-releases" / f"async-profiler-{VERSION}-code" / "src"
16-
AP_CONVERTER_SOURCE_DIR = AP_SOURCE_DIR / "converter"
17-
AP_RESOURCES_SOURCE_DIR = AP_SOURCE_DIR / "res"
18-
AP_API_SOURCE_DIR = AP_SOURCE_DIR / "api" / "one" / "profiler"
19-
TARGET_SOURCE_DIR = BASEDIR / "src" / "main" / "java"
16+
17+
def either(*dirs: Path) -> Path:
18+
for dir in dirs:
19+
if dir.exists():
20+
return dir
21+
raise AssertionError(f"None of {', '.join(map(str, dirs))} exists")
22+
23+
24+
def either_or_none(*dirs: Path) -> Optional[Path]:
25+
return ([dir for dir in dirs if dir.exists()] + [None]) [0]
26+
27+
28+
AP_SOURCE_DIR = either(BASEDIR / "ap-releases" / f"async-profiler-{VERSION}-code" / "src")
29+
AP_CONVERTER_SOURCE_DIR = either(AP_SOURCE_DIR / "converter")
30+
AP_RESOURCES_SOURCE_DIR = either_or_none(AP_SOURCE_DIR / "res", AP_SOURCE_DIR / "main" / "resources")
31+
AP_API_SOURCE_DIR = either(AP_SOURCE_DIR / "api" / "one" / "profiler")
32+
TARGET_SOURCE_DIR = either(BASEDIR / "src" / "main" / "java")
2033
TARGET_ONE_DIR = TARGET_SOURCE_DIR / "one"
21-
TARGET_ONE_PROFILER_DIR = TARGET_ONE_DIR / "profiler"
34+
TARGET_ONE_PROFILER_DIR = either(TARGET_ONE_DIR / "profiler")
2235
TARGET_CONVERTER_DIR = TARGET_ONE_DIR / "converter"
2336
TARGET_RESOURCES_DIR = BASEDIR / "src" / "main" / "resources"
2437

25-
assert AP_SOURCE_DIR.exists(), f"Source directory {AP_SOURCE_DIR} does not exist"
26-
assert AP_CONVERTER_SOURCE_DIR.exists(), f"Source directory {AP_CONVERTER_SOURCE_DIR} does not exist"
27-
assert AP_API_SOURCE_DIR.exists()
28-
assert TARGET_SOURCE_DIR.exists()
29-
assert TARGET_ONE_PROFILER_DIR.exists()
30-
assert AP_RESOURCES_SOURCE_DIR.exists()
3138

3239
PROJECT_FILES = ["AsyncProfilerLoader.java"]
3340

@@ -71,13 +78,14 @@
7178
else:
7279
shutil.copy(f, target_file)
7380

74-
print("Copy converter resource files")
75-
for f in AP_RESOURCES_SOURCE_DIR.glob("*"):
76-
target_file = TARGET_RESOURCES_DIR / f.name
77-
if DRY_RUN:
78-
print(f"would copy {f} to {target_file}")
79-
else:
80-
shutil.copy(f, target_file)
81+
if AP_RESOURCES_SOURCE_DIR:
82+
print("Copy converter resource files")
83+
for f in AP_RESOURCES_SOURCE_DIR.glob("*"):
84+
target_file = TARGET_RESOURCES_DIR / f.name
85+
if DRY_RUN:
86+
print(f"would copy {f} to {target_file}")
87+
else:
88+
shutil.copy(f, target_file)
8189

8290
print("Copy converter directories")
8391
for directory in AP_CONVERTER_SOURCE_DIR.glob("one/*"):

src/main/java/one/profiler/AsyncProfilerLoader.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,14 @@ public static Path getExtractionDirectory() throws IOException {
140140
private static String getLibrarySuffix() throws OSNotSupportedException {
141141
if (librarySuffix == null) {
142142
String version = getVersion();
143+
boolean oldVersion = version.startsWith("1.");
143144
String os = System.getProperty("os.name").toLowerCase();
144145
String arch = System.getProperty("os.arch").toLowerCase();
145146
if (os.startsWith("linux")) {
146147
if (arch.equals("arm64") || arch.equals("aarch64")) {
147148
librarySuffix = version + "-linux-aarch64.so";
149+
} else if (arch.equals("x86") && oldVersion) {
150+
librarySuffix = version + "-linux-x86.so";
148151
} else if (arch.equals("x86_64") || arch.equals("x64") || arch.equals("amd64")) {
149152
if (isOnMusl()) {
150153
librarySuffix = version + "-linux-x64-musl.so";
@@ -155,7 +158,14 @@ private static String getLibrarySuffix() throws OSNotSupportedException {
155158
throw new OSNotSupportedException("Async-profiler does not work on Linux " + arch);
156159
}
157160
} else if (os.startsWith("macosx") || os.startsWith("mac os x")) {
158-
librarySuffix = version + "-macos.so";
161+
if (oldVersion) {
162+
if (!arch.contains("x86")) {
163+
throw new OSNotSupportedException("Async-profiler does not work on MacOS " + arch);
164+
}
165+
librarySuffix = version + "-macosx-x86.so";
166+
} else {
167+
librarySuffix = version + "-macos.so";
168+
}
159169
} else {
160170
throw new OSNotSupportedException("Async-profiler does not work on " + os);
161171
}

0 commit comments

Comments
 (0)