gcc: Replace the original patch with the new one that adds support for paths containing spaces in spec functions#30252
Open
Fourish wants to merge 1 commit into
Open
gcc: Replace the original patch with the new one that adds support for paths containing spaces in spec functions#30252Fourish wants to merge 1 commit into
Fourish wants to merge 1 commit into
Conversation
Contributor
Author
|
Here is a simple script for testing support for directories whose paths contain spaces. #!/bin/bash
# make directory {test_dir, test_dir/normal_dir, test_dir/dir with spaces}
# make something.o to {test_dir/normal_dir/something.o, test_dir/dir with spaces/something.o}
# write main.c to test_dir/main.c
# make {test_dir/total.log, test_dir/fail.log}
# dump default specs to test_dir/specs_default
prepare() {
local normal_dir="$1"
local dir_with_space="$2"
if [[ -d "test_dir" ]]; then
return
fi
mkdir -p "test_dir"
pushd "test_dir" > /dev/null
mkdir -p "${PWD}/${normal_dir}"
mkdir -p "${PWD}/${dir_with_space}"
printf "\n" > "something.c"
printf "int main() { return 0; }\n" > "main.c"
gcc --compile something.c
cp something.o "${normal_dir}/something.o"
mv something.o "${dir_with_space}/something.o"
touch {total,fail}.log
gcc -dumpspecs > specs_default
popd > /dev/null
}
# excute cmd,
# compare output with expected_out,
# print result and log details to total.log and fail.log
expected() {
local name="$1"
local cmd="$2"
local expected_out="$3"
local got
got="$(bash -c "$cmd")"
if [[ -z "$got" && -z "$expected_out" ]] || \
[[ -n "$got" && -n "$expected_out" && "$got" == *"$expected_out"* ]]; then
printf '\033[32m%s Success\033[0m\n' "$name"
{
printf '##### %s Success #####\n' "$name"
printf 'Command:\n%s\n' "$cmd"
printf 'Expected:\n'
printf '%s\n' "$expected_out"
printf 'Got:\n'
printf '%s\n\n' "$got"
} >> total.log
return 0
else
printf '\033[31m%s Failed\033[0m\n' "$name"
{
printf '##### %s Failed #####\n' "$name"
printf 'Command:\n%s\n' "$cmd"
printf 'Expected:\n'
printf '%s\n' "$expected_out"
printf 'Got:\n'
printf '%s\n\n' "$got"
} | tee -a total.log fail.log >/dev/null
return 1
fi
}
# generate specs by appending var to the line after *segment: in specs_default
generate_specs() {
local segment="$1"
local var="$2"
local output="$3"
sed "/^\*${segment}:$/ { n; s/$/ ${var}/ }" specs_default > "${output}"
}
test_wrap() {
local id="$1"
local var="$2"
local dir="$3"
local expected_compile_out="$4"
printf 'Test %s with %s in %s\n' "$id" "$var" "$dir"
generate_specs "endfile" "${var}" "specs_${id}"
expected "Test${id} compile" \
"gcc -specs=specs_${id} main.c -B\"${dir}\" -o a.out 2>&1" \
"${expected_compile_out}"
if [[ $? -eq 0 ]] && [[ -n "$5" ]]; then
local expected_check_out="$5"
expected "Test${id} check" \
"strings a.out | grep ${expected_check_out}" \
"${expected_check_out}"
fi
}
main() {
normal_dir="normal_dir"
dir_with_space="dir with spaces"
prepare "${normal_dir}" "${dir_with_space}"
pushd "test_dir" > /dev/null
normal_dir="$PWD/${normal_dir}"
dir_with_space="$PWD/${dir_with_space}"
printf "====================\n" | tee -a {total,fail}.log > /dev/null
gcc --version | tee -a {total,fail}.log
# append_to_specs, compile_include_dir, expected_compile_out, [expected_check_out]
test_args=(
"" "${dir_with_space}" "" ""
"something.o%s" "${normal_dir}" "" "something.c"
"something.o%s" "${dir_with_space}" "" "something.c"
"%:if-exists(something.o%s)" "${normal_dir}" "" "something.c"
"%:if-exists(something.o%s)" "${dir_with_space}" "" "something.c"
"%:if-exists(%:if-exists(something.o%s))" "${normal_dir}" "" "something.c"
"%:if-exists(%:if-exists(something.o%s))" "${dir_with_space}" "" "something.c"
"non-existfile%s" "${normal_dir}" "cannot find non-existfile" ""
"%:if-exists(non-existfile%s)" "${normal_dir}" "" ""
"%:if-exists(%:if-exists(non-existfile%s))" "${normal_dir}" "" ""
)
for ((i=0; i<${#test_args[@]}; i+=4)); do
id=$(((i+4)/4))
var="${test_args[i]}"
dir="${test_args[i+1]}"
expected_compile_out="${test_args[i+2]}"
expected_check_out="${test_args[i+3]}"
test_wrap "$id" "$var" "$dir" "$expected_compile_out" "$expected_check_out"
done
popd > /dev/null
}
#set -x
main
|
support for paths containing spaces in spec functions. The old patch disrupts the evaluation of spec functions. As a result, on MinGW targets, the expression used to add the default manifest file: `%:if-exists(default-manifest.o%s)` appends `default-manifest.o` to the end of the collect2 argument list regardless of whether the file actually exists. This is not the intended behavior. However, it usually does not cause an error on MSYS2 because the `mingw-w64-gcc` package depends on the `mingw-w64-windows-default-manifest` package.
73bc104 to
f63e368
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The old patch disrupts the evaluation of spec functions. As a result, on MinGW targets, the expression used to add the default manifest file:
appends
default-manifest.oto the end of the collect2 argument list regardless of whether the file actually exists. This is not the intended behavior.However, it usually does not cause an error on MSYS2 because the
mingw-w64-gccpackage depends on themingw-w64-windows-default-manifestpackage.