Skip to content
Snippets Groups Projects
Commit d38619e8 authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

PKG: unix file command have different output

parent 107dc86b
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,9 @@ macro(macro_super_package)
message(FATAL_ERROR "PATCHELF_PROGRAM not set")
endif()
#setting this variable. prints a lot of debug information
#set( PKG_OTB_DEBUG 1)
set(loader_program_PATHS)
set(eol_char "E")
if(MSVC)
......@@ -312,13 +315,11 @@ function(func_prepare_package)
endif()
unset(${var_to_unset} CACHE)
endforeach()
foreach(infile ${PKG_PEFILES})
get_filename_component(bn ${infile} NAME)
func_process_deps(${bn})
endforeach()
endfunction() #func_prepare_package
......@@ -327,9 +328,9 @@ function(func_process_deps input_file)
if(NOT input_file_full_path)
message(FATAL_ERROR "${input_file} not found. searched in ${PKG_SEARCHDIRS}")
endif()
message("Processing ${input_file_full_path}")
set(is_executable FALSE)
is_file_executable2("${input_file_full_path}" is_executable)
if(NOT is_executable)
......@@ -428,21 +429,28 @@ function(func_process_deps input_file)
list(APPEND raw_items ${raw_item})
endforeach()
if(PKG_OTB_DEBUG)
message(FATAL_ERROR "raw_items=${raw_items}")
string(REPLACE ";" "\n" raw_items_pretty_print "${raw_items}")
message(FATAL_ERROR "raw_items=${raw_items_pretty_print}")
endif(PKG_OTB_DEBUG)
if(raw_items)
list(REVERSE raw_items)
foreach(item ${raw_items})
search_library(${item} PKG_SEARCHDIRS item_full_path)
set(is_a_symlink FALSE)
set(item_target_file)
if(PKG_OTB_DEBUG)
message("item0=${item_full_path}")
endif()
func_is_file_a_symbolic_link("${item_full_path}" is_a_symlink item_target_file)
if(is_a_symlink)
set(${item}_RESOLVED TRUE CACHE INTERNAL "")
set(item ${item_target_file})
set(item ${item_target_file})
endif()
if(PKG_OTB_DEBUG)
message("running func_process_deps on '${item}'")
endif()
func_process_deps(${item})
endforeach()
......
......@@ -283,6 +283,11 @@ function(func_is_file_a_symbolic_link file result_var1 result_var2)
#
endif()
#if we are not on a unix or unix-like platform, then we don't have any business here
if(NOT UNIX)
return()
endif()
# Use the information returned from the Unix shell command "file" to
# determine if ${file_full} should be considered an executable file...
#
......@@ -290,59 +295,52 @@ function(func_is_file_a_symbolic_link file result_var1 result_var2)
# "text" then it is likely an executable suitable for prerequisite analysis
# via the get_prerequisites macro.
#
if(UNIX)
if(NOT file_cmd)
find_program(file_cmd "file")
mark_as_advanced(file_cmd)
if(NOT file_cmd)
find_program(file_cmd "file")
mark_as_advanced(file_cmd)
endif()
if(file_cmd)
execute_process(COMMAND "${file_cmd}" "${file_full}"
RESULT_VARIABLE file_rv
OUTPUT_VARIABLE file_ov
ERROR_VARIABLE file_ev
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT file_rv STREQUAL "0")
message(FATAL_ERROR "${file_cmd} failed: ${file_rv}\n${file_ev}")
endif()
if(file_cmd)
execute_process(COMMAND "${file_cmd}" "${file_full}"
RESULT_VARIABLE file_rv
OUTPUT_VARIABLE file_ov
ERROR_VARIABLE file_ev
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT file_rv STREQUAL "0")
message(FATAL_ERROR "${file_cmd} failed: ${file_rv}\n${file_ev}")
endif()
# Replace the name of the file in the output with a placeholder token
# (the string " _file_full_ ") so that just in case the path name of
# the file contains the word "text" or "executable" we are not fooled
# into thinking "the wrong thing" because the file name matches the
# other 'file' command output we are looking for...
#
string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
string(TOLOWER "${file_ov}" file_ov_lower)
# Replace the name of the file in the output with a placeholder token
# (the string " _file_full_ ") so that just in case the path name of
# the file contains the word "text" or "executable" we are not fooled
# into thinking "the wrong thing" because the file name matches the
# other 'file' command output we are looking for...
#
string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
string(TOLOWER "${file_ov}" file_ov_lower)
#message(FATAL_ERROR "file_ov='${file_ov}'")
if("${file_ov_lower}" MATCHES "symbolic link")
set(${result_var1} 1 PARENT_SCOPE)
#Now find where the symlink is linked to.
#Do a regex replace
if(UNIX)
if(APPLE)
string(REGEX REPLACE "_file_full_*.*symbolic.link.to."
"" symlinked_to ${file_ov})
else(APPLE)
string(REGEX REPLACE "_file_full_*.*symbolic.link.to.."
"" symlinked_to ${file_ov})
endif(APPLE)
endif(UNIX)
#Take out last character which is a single quote
string(REPLACE "'" "" symlinked_to "${symlinked_to}")
#strip for our own sanity
string(STRIP ${symlinked_to} symlinked_to)
set(${result_var2} "${symlinked_to}" PARENT_SCOPE)
#message(FATAL_ERROR "${file_full} is symlinked_to ${symlinked_to}")
return()
endif()
#message(FATAL_ERROR "file_ov='${file_ov}'")
if("${file_ov_lower}" MATCHES "symbolic link")
set(${result_var1} 1 PARENT_SCOPE)
#Now find where the symlink is linked to.
#Do a regex replace
string(REGEX REPLACE "_file_full_*.*symbolic.link.to." "" symlinked_to ${file_ov})
#Take out last character which is a single quote
string(REPLACE "'" "" symlinked_to "${symlinked_to}")
else()
message(STATUS "warning: No 'file' command, skipping execute_process...")
#strip final output
string(STRIP ${symlinked_to} symlinked_to)
set(${result_var2} "${symlinked_to}" PARENT_SCOPE)
#message(FATAL_ERROR "${file_full} is symlinked_to ${symlinked_to}")
return()
endif()
else()
message(STATUS "warning: No 'file' command, skipping execute_process...")
endif()
endfunction()
macro(setif_value_in_list matched value list)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment