Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jlink/plugins/StripNativeDebugSymbolsPlugin/FakeObjCopy.java
41155 views
1
/*
2
* Copyright (c) 2019, Red Hat, Inc.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
import java.io.File;
27
import java.io.PrintWriter;
28
import java.nio.file.Files;
29
import java.nio.file.Paths;
30
import java.nio.file.StandardOpenOption;
31
import java.util.Arrays;
32
import java.util.List;
33
import java.util.stream.Collectors;
34
35
/**
36
* Fake objcopy used by StripNativeDebugSymbolsTest. It prints the
37
* passed in arguments to a log and creates a fake debug info file
38
* for --only-keep-debug invocation. Note that the first argument is
39
* the path to the log file. This argument will be omitted when
40
* logged.
41
*
42
* Callers need to ensure the log file is properly truncated.
43
*
44
*/
45
public class FakeObjCopy {
46
47
private static final String OBJCOPY_ONLY_KEEP_DEBUG_OPT = "--only-keep-debug";
48
49
public static void main(String[] args) throws Exception {
50
if (args.length < 1) {
51
throw new AssertionError("At least one argument expected");
52
}
53
String[] objCopyArgs = new String[args.length - 1];
54
System.arraycopy(args, 1, objCopyArgs, 0, objCopyArgs.length);
55
String logFile = args[0];
56
System.out.println("DEBUG: Fake objcopy called. Log file is: " + logFile);
57
// Log options
58
String line = Arrays.asList(objCopyArgs).stream().collect(Collectors.joining(" "));
59
Files.write(Paths.get(logFile),
60
List.<String>of(line),
61
StandardOpenOption.APPEND,
62
StandardOpenOption.CREATE);
63
// Handle --only-keep-debug option as plugin attempts to read
64
// debug info file after this utility being called.
65
if (objCopyArgs.length == 3 && OBJCOPY_ONLY_KEEP_DEBUG_OPT.equals(objCopyArgs[0])) {
66
handleOnlyKeepDebug(objCopyArgs[2]);
67
}
68
}
69
70
private static void handleOnlyKeepDebug(String dbgFile) throws Exception {
71
try (PrintWriter pw = new PrintWriter(new File(dbgFile))) {
72
pw.println("Fake objcopy debug info file");
73
}
74
System.out.println("DEBUG: wrote fake debug file " + dbgFile);
75
}
76
77
}
78
79