Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "print-search-dirs" argument #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions cccl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ gotparam=
muffle=
verbose=
shared_index=-1
script_dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
libraries=""
print_search_dirs=false

processargs()
{
Expand Down Expand Up @@ -121,15 +124,30 @@ EOF
clopt+=("${slash}O2")
;;

-print-search-dirs | /print-search-dirs)
# Set "print_search_dirs" to print later
print_search_dirs=true
;;

-L)
shift
path=`echo "$1"`
linkopt+=("${slash}LIBPATH:$path")
if [ -z "$libraries" ]; then
libraries="$path"
else
libraries="$path:$libraries"
fi
;;

-L*)
path=`echo "$1" | sed 's/-L//'`
linkopt+=("${slash}LIBPATH:$path")
if [ -z "$libraries" ]; then
libraries="$path"
else
libraries="$path:$libraries"
fi
;;

-link)
Expand Down Expand Up @@ -301,6 +319,77 @@ processargs $CCCL_OPTIONS
IFS=""
processargs $@

# Process "print-search-dirs" and exit gracefully
if $print_search_dirs; then
# Record the original "IFS"
if ! [ -z "$IFS" ]; then
originalIFS="$IFS"
fi

# Set the "winpath" binary to convert Windows paths to Unix paths.
winpath_bin="$CCCL_WINPATH_BIN" # "CCCL_WINPATH_BIN" must have the same format, e.g., as "cygpath"
if [ -z "$winpath_bin" ]; then
# Guess the "winpath" binary
IFS=" "
guess_winpath_bins_str="cygpath wslpath winepath" # For Cygwin/MSYS2 and native Windows, WSL and native Windows, and Linux and Wine, respectfully
read -ra guess_winpath_bins <<< "$guess_winpath_bins_str"
for guess_winpath_bin in ${guess_winpath_bins[@]}; do
winpath_bin="$(which $guess_winpath_bin)"
if ! [ -z "$winpath_bin" ]; then
break
fi
done
if [ -z "$winpath_bin" ]; then
echo "Cannot guess \"winpath\" binary to convert Windows paths to Unix paths. You must set \"CCCL_WINPATH_BIN\" with a format similar to \"cygpath\", \"wslpath\", or \"winepath\"."
exit 1
fi
fi

# Print "install"
echo "install: $script_dir"

# TODO: Implement printing "programs" for the MSVC toolchain. Not sure which bin dirs to print, nor if it is ever needed for
# the MSVC toolchain

# Set the global libraries
global_libraries=""
IFS=";"
read -ra global_libraries_windows <<< "$LIB"
for libpath in ${global_libraries_windows[@]}; do
# Using "realpath" is undesirable, but it might be the only solution to have a path without ":" when the
# the Windows drive letter is present in the path. For instance, a path with "c:" in Wine will be converted
# to a path with "drive_c". The reason for avoiding paths with ":" is that ":" is generally unescapable in Unix
# (e.g. in "PATH" environment variable).
unix_global_library_path="$(realpath $($winpath_bin -u $libpath))"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like to use realpath here, but it is the only way I can think of to remove the : from the Wine drives, for e.g.

I believe this argument is mostly necessary for libtool to search for libraries when creating dynamic libraries, and the issue when going to the parent folder (i.e. ../) won't happen, since only the directories in libraries will be searched.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I resolved this issue by shortening only the Unix portion of the Windows path prefix, by parsing out the prefix using Python's pathlib's PureWindowsPath.

if [ -z "$global_libraries" ]; then
global_libraries="$unix_global_library_path"
else
global_libraries="$unix_global_library_path:$global_libraries"
fi
done

# Update "libraries" with the global libraries
if [ -z "$libraries" ]; then
libraries="$global_libraries"
else
# Global libraries are set after the ones defined by the command line argument "-L", as the latter takes
# precedence
libraries="$libraries:$global_libraries"
fi

# Print "libraries"
echo "libraries: =$libraries"

# Reset the "IFS"
if ! [ -z "$originalIFS" ]; then
IFS="$originalIFS"
else
unset IFS
fi

exit 0
fi

if test $shared_index -ge 0 -a -n "$debug"; then
clopt[$shared_index]="${slash}LDd"
fi
Expand Down