Skip to content

Commit 5874d3f

Browse files
committed
[GR-6145] File fastr_errors.log should live somewhere else.
PullRequest: fastr/1527
2 parents bb63511 + 7569c92 commit 5874d3f

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

ci_common/common.hocon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ java9Downloads : {
2525
}
2626

2727
logfiles : [
28-
"fastr_errors.log"
28+
"fastr_errors*.log"
2929
"results.json"
3030
"libdownloads/R-*/gnur_configure.log"
3131
"libdownloads/R-*/config.log"

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalError.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
public final class RInternalError extends Error implements TruffleException {
4747

48-
private static final String FASTR_ERRORS_LOG = "fastr_errors.log";
48+
private static final String FASTR_ERRORS_LOG = "fastr_errors";
4949

5050
private static final long serialVersionUID = 80698622974155216L;
5151

@@ -194,7 +194,7 @@ private static void reportError(String errMsg, Throwable throwable, int contextI
194194

195195
String message = "An internal error occurred: \"" + errMsg + "\"\nPlease report an issue at https://github.com/oracle/fastr including the commands";
196196
if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue()) {
197-
message += " and the error log file '" + getLogFileName(contextId) + "'.";
197+
message += " and the error log file '" + Utils.getLogPath(getLogFileName(contextId)) + "'.";
198198
} else {
199199
message += ".";
200200
}

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.truffle.r.runtime.data.model.RAbstractContainer;
6060
import com.oracle.truffle.r.runtime.env.frame.FrameSlotChangeMonitor.MultiSlotData;
6161
import com.oracle.truffle.r.runtime.ffi.BaseRFFI;
62+
import java.nio.file.Files;
6263

6364
public final class Utils {
6465

@@ -241,22 +242,41 @@ public static void updateCurwd(String path) {
241242
}
242243

243244
/**
244-
* Returns a {@link Path} for a log file with base name {@code fileName}, taking into account
245-
* whether the system is running in embedded mode. In the latter case, we can't assume that the
246-
* cwd is writable. Plus some embedded apps, e.g. RStudio, spawn multiple R sub-processes
247-
* concurrently so we tag the file with the pid.
245+
* Returns a {@link Path} for a log file with base name {@code fileNamePrefix}, adding '_pid'
246+
* and process-id and '.log' and taking into account whether the system is running in embedded
247+
* mode. In the latter case, we can't assume that the cwd is writable so '/tmp' is attempted.
248+
* For regular mode dirs are attempted in this order: cwd, user's home, '/tmp', rHome. If none
249+
* of the dirs is writable null is returned.
248250
*/
249-
public static Path getLogPath(String fileName) {
250-
String root = RContext.isEmbedded() ? "/tmp" : REnvVars.rHome();
251-
String baseName;
252-
if (RContext.isEmbedded()) {
253-
int pid = RContext.getInitialPid();
254-
String threadName = Thread.currentThread().getName();
255-
baseName = fileName + "-" + Integer.toString(pid) + "-" + threadName;
256-
} else {
257-
baseName = fileName;
251+
public static Path getLogPath(String fileNamePrefix) {
252+
String dir = RContext.isEmbedded() ? "/tmp" : System.getProperty("user.dir");
253+
int dirId = 0;
254+
int pid = RContext.getInitialPid();
255+
String baseName = fileNamePrefix + "_pid" + Integer.toString(pid) + ".log";
256+
while (true) {
257+
Path path = FileSystems.getDefault().getPath(dir, baseName);
258+
if (Files.isWritable(path.getParent())) {
259+
return path;
260+
}
261+
switch (dirId) {
262+
case 0:
263+
if (RContext.isEmbedded()) {
264+
return null;
265+
} else {
266+
dir = System.getProperty("user.home");
267+
}
268+
break;
269+
case 1:
270+
dir = "/tmp";
271+
break;
272+
case 2:
273+
dir = REnvVars.rHome();
274+
break;
275+
default:
276+
return null;
277+
}
278+
dirId++;
258279
}
259-
return FileSystems.getDefault().getPath(root, baseName);
260280
}
261281

262282
/**

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFILog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class RFFILog {
4646
/**
4747
* Always trace to a file because stdout is problematic for embedded mode.
4848
*/
49-
private static final String TRACEFILE = "fastr_trace_nativecalls.log";
49+
private static final String TRACEFILE = "fastr_trace_nativecalls";
5050
private static PrintWriter traceStream;
5151

5252
/**

mx.fastr/mx_fastr.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,6 @@ def gnu_rtests(args, env=None):
485485
os.chdir(_fastr_suite.dir) # Packages install fails otherwise
486486
# mx_fastr_pkgs.installpkgs(['--pkg-pattern', '^MASS$']) # required by tests/Examples/base-Ex.R
487487
np = mx.project('com.oracle.truffle.r.native')
488-
ferrs = join(_fastr_suite.dir, 'fastr_errors.log')
489-
ferrs_size = os.stat(ferrs).st_size if os.access(ferrs, os.R_OK) else 0
490488
tst = join(np.dir, 'gnur', 'tests')
491489
tstsrc = join(tst, 'src')
492490
tstlog = join(tst, 'log')
@@ -511,12 +509,6 @@ def gnu_rtests(args, env=None):
511509
os.rename(outf, outff)
512510
print 'Running {} explicitly by GnuR CMD BATCH ...'.format(f)
513511
mx.run([join(_gnur_path(), 'R'), '--vanilla', 'CMD', 'BATCH', join(srcd, f)] + args, nonZeroIsFatal=False, env=env, timeout=90)
514-
ferrs_new_size = os.stat(ferrs).st_size if os.access(ferrs, os.R_OK) else 0
515-
if ferrs_new_size - ferrs_size > 0:
516-
with open(ferrs) as f:
517-
nlines = sum(1 for _ in f)
518-
print ' Size of {} increased to {:,} bytes ({:,} lines).\n'.format(ferrs, ferrs_new_size, nlines)
519-
ferrs_size = ferrs_new_size
520512
if os.path.isfile(outf):
521513
outfg = outf + '.gnur'
522514
os.rename(outf, outfg)
@@ -525,7 +517,7 @@ def gnu_rtests(args, env=None):
525517
subprocess.Popen([r_path(), 'CMD', 'Rdiff', outfg, outff], stdout=diff, stderr=diff, shell=False)
526518
diff.flush()
527519
diff.close()
528-
print 'FastR to GnuR diff was written to {}.'.format(diffname)
520+
print 'FastR to GnuR diff was written to {}'.format(diffname)
529521
finally:
530522
shutil.rmtree(join(_fastr_suite.dir, 'deparse'), True)
531523

0 commit comments

Comments
 (0)