forked from microsoft/LightGBM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[R-package] replaced gendef.exe with R code to create R.def (fixes mi…
- Loading branch information
Showing
5 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# [description] | ||
# Create a definition file (.def) from a .dll file, using objdump. | ||
# | ||
# [usage] | ||
# | ||
# Rscript make-r-def.R something.dll something.def | ||
# | ||
# [references] | ||
# * https://www.cs.colorado.edu/~main/cs1300/doc/mingwfaq.html | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
IN_DLL_FILE <- args[[1]] | ||
OUT_DEF_FILE <- args[[2]] | ||
print(sprintf("Creating '%s' from '%s'", IN_DLL_FILE, OUT_DEF_FILE)) | ||
|
||
# Creates a .def file from R.dll, using tools bundled with R4.0 | ||
#LIBR_CORE_LIBRARY <- "C:/Program Files/R/R-3.6.1/bin/x64/R.dll" | ||
|
||
# use objdump to dump all the symbols | ||
OBJDUMP_FILE <- "R.fil" | ||
exit_code <- system2( | ||
command = "objdump" | ||
, args = c( | ||
"-p" | ||
, shQuote(IN_DLL_FILE) | ||
) | ||
, stdout = OBJDUMP_FILE | ||
) | ||
|
||
objdump_results <- readLines(OBJDUMP_FILE) | ||
file.remove(OBJDUMP_FILE) | ||
|
||
# Name Pointer table start | ||
# https://www.cs.colorado.edu/~main/cs1300/doc/mingwfaq.html | ||
start_index <- which( | ||
grepl( | ||
pattern = "[Ordinal/Name Pointer] Table" | ||
, x = objdump_results | ||
, fixed = TRUE | ||
) | ||
) | ||
empty_lines <- which(objdump_results == "") | ||
end_of_table <- empty_lines[empty_lines > start_index][1] | ||
|
||
# Read the contents of the table | ||
exported_symbols <- objdump_results[(start_index + 1):end_of_table] | ||
exported_symbols <- gsub("\t", "", exported_symbols) | ||
exported_symbols <- gsub(".*\\] ", "", exported_symbols) | ||
exported_symbols <- gsub(" ", "", exported_symbols) | ||
|
||
# Write R.def file | ||
write_succeeded <- writeLines( | ||
text = c( | ||
paste0("LIBRARY ", '\"R.dll\"') | ||
, "EXPORTS" | ||
, exported_symbols | ||
) | ||
, con = OUT_DEF_FILE | ||
, sep = "\n" | ||
) | ||
if (!isTRUE(write_succeeded)){ | ||
stop("Failed to create R.def") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters