@@ -210,25 +210,7 @@ compile <- function(fsub, build_dir = tempfile(paste0(fsub@name, "-build-"))) {
210210
211211 # Link against the same BLAS/LAPACK/Fortran libs as the running R
212212 # to support generated calls to vendor BLAS (e.g., dgemm, dgesv).
213- cfg <- function (var ) {
214- r_cmd <- R.home(" bin/R" )
215- if (identical(.Platform $ OS.type , " windows" ) && ! file.exists(r_cmd )) {
216- r_cmd <- paste0(r_cmd , " .exe" )
217- }
218- tryCatch(
219- {
220- out <- system2(
221- r_cmd ,
222- c(" CMD" , " config" , var ),
223- stdout = TRUE ,
224- stderr = FALSE
225- )
226- paste(out , collapse = " " )
227- },
228- error = function (e ) " "
229- )
230- }
231-
213+ cfg <- quickr_r_cmd_config_value
232214 BLAS_LIBS <- strsplit(cfg(" BLAS_LIBS" ), " [[:space:]]+" )[[1 ]]
233215 LAPACK_LIBS <- strsplit(cfg(" LAPACK_LIBS" ), " [[:space:]]+" )[[1 ]]
234216 FLIBS <- strsplit(cfg(" FLIBS" ), " [[:space:]]+" )[[1 ]]
@@ -237,8 +219,8 @@ compile <- function(fsub, build_dir = tempfile(paste0(fsub@name, "-build-"))) {
237219 FLIBS <- FLIBS [nzchar(FLIBS )]
238220 link_flags <- c(LAPACK_LIBS , BLAS_LIBS , FLIBS )
239221
222+ use_openmp <- isTRUE(attr(fsub @ scope , " uses_openmp" , exact = TRUE ))
240223 suppressWarnings({
241- use_openmp <- isTRUE(attr(fsub @ scope , " uses_openmp" , exact = TRUE ))
242224 env <- quickr_fcompiler_env(
243225 build_dir = build_dir ,
244226 use_openmp = use_openmp ,
@@ -261,42 +243,37 @@ compile <- function(fsub, build_dir = tempfile(paste0(fsub@name, "-build-"))) {
261243 stderr = TRUE ,
262244 env = env
263245 )
264- if (! is.null(attr(result , " status" )) && length(env )) {
265- if (use_openmp ) {
266- attr(result , " quickr_openmp_failed" ) <- TRUE
246+ if (! is.null(attr(result , " status" )) && length(env ) && ! use_openmp ) {
247+ result2 <- system2(
248+ R.home(" bin/R" ),
249+ r_args_libs ,
250+ stdout = TRUE ,
251+ stderr = TRUE
252+ )
253+ if (is.null(attr(result2 , " status" ))) {
254+ result <- result2
267255 } else {
268- result2 <- system2(
269- R.home(" bin/R" ),
270- r_args_libs ,
271- stdout = TRUE ,
272- stderr = TRUE
256+ # Prefer to show the flang attempt first, then the fallback attempt.
257+ result <- c(
258+ " --- flang attempt ---" ,
259+ result ,
260+ " " ,
261+ " --- fallback attempt ---" ,
262+ result2
273263 )
274- if (is.null(attr(result2 , " status" ))) {
275- result <- result2
276- } else {
277- # Prefer to show the flang attempt first, then the fallback attempt.
278- result <- c(
279- " --- flang attempt ---" ,
280- result ,
281- " " ,
282- " --- fallback attempt ---" ,
283- result2
284- )
285- attr(result , " status" ) <- attr(result2 , " status" )
286- }
264+ attr(result , " status" ) <- attr(result2 , " status" )
287265 }
288266 }
289267 })
290268
291269 status <- attr(result , " status" )
292- openmp_failed <- isTRUE(attr(result , " quickr_openmp_failed" ))
293270 if (! is.null(status )) {
294271 # Adjust the compiler error so RStudio console formatter doesn't mangle
295272 # the actual error message https://github.com/rstudio/rstudio/issues/16365
296273 result <- gsub(" Error: " , " Compiler Error: " , result , fixed = TRUE )
297274 writeLines(result , stderr())
298275 cat(" ---\n Compiler exit status:" , status , " \n " , file = stderr())
299- if (openmp_failed ) {
276+ if (use_openmp ) {
300277 openmp_abort(
301278 paste(
302279 " OpenMP was requested but compilation with OpenMP flags failed." ,
@@ -340,7 +317,7 @@ compile <- function(fsub, build_dir = tempfile(paste0(fsub@name, "-build-"))) {
340317quickr_windows_add_dll_paths <- function (
341318 flags ,
342319 os_type = .Platform $ OS.type ,
343- config_value = openmp_config_value ,
320+ config_value = quickr_r_cmd_config_value ,
344321 which = Sys.which
345322) {
346323 if (! identical(os_type , " windows" )) {
0 commit comments