mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-01 13:50:36 +00:00
Fix compiling bas files relative to the CWD
Fix was pulled from QB64Official/qb64#17 by Cory Smith, I just added tests around it. Most (all?) compilers allow you to run the compiler from a separate directory than the compiler itself is located in and compile source files relative to that directory. QB64-PE however does not allow that, for a variety of reasons it always search for the provided source file relative to the location of the QB64-PE compiler rather than the CWD it was run from. This is pretty unexpected behavior in a lot of cases, and also doesn't give very helpful error messages either. This change has us check if the source file exists at the given CWD location, and if it does we will prepend the CWD to produce the correct path to the file. To test that this behavior works as expected I modified `compile_test.sh` to compile from within the test directories using a relative path directly to the test file, this fails with current QB64-PE versions because it can't find the source file. Additionally, I was unsure of whether this would impact the behavior of `'$include`, so I added some tests around include that uses various combinations of paths relative to QB64-PE and relative to the source file being compiled, and they all find the files as expected so I think it's fine.
This commit is contained in:
parent
e93e389e03
commit
094a8c82b2
|
@ -380,6 +380,9 @@ DIM SHARED compilelog$
|
|||
'$INCLUDE:'global\IDEsettings.bas'
|
||||
|
||||
CMDLineFile = ParseCMDLineArgs$
|
||||
IF CMDLineFile <> "" AND _FILEEXISTS(_STARTDIR$ + "/" + CMDLineFile) THEN
|
||||
CMDLineFile = _STARTDIR$ + "/" + CMDLineFile
|
||||
END IF
|
||||
|
||||
IF ConsoleMode THEN
|
||||
_DEST _CONSOLE
|
||||
|
|
|
@ -56,9 +56,14 @@ do
|
|||
compilerFlags=$(cat "./tests/compile_tests/$category/$testName.flags")
|
||||
fi
|
||||
|
||||
pushd . >/dev/null
|
||||
cd "./tests/compile_tests/$category"
|
||||
|
||||
# -m and -q make sure that we get predictable results
|
||||
"$QB64" $compilerFlags -m -q -x "./tests/compile_tests/$category/$testName.bas" -o "$EXE" 1>"$compileResultOutput"
|
||||
"../../../$QB64" $compilerFlags -m -q -x "$testName.bas" -o "$EXE" 1>"../../../$compileResultOutput"
|
||||
ERR=$?
|
||||
|
||||
popd >/dev/null
|
||||
cp_if_exists ./internal/temp/compilelog.txt "$RESULTS_DIR/$category-$testName-compilelog.txt"
|
||||
|
||||
if [ "$testType" == "success" ]; then
|
||||
|
|
2
tests/compile_tests/extra/include_extra.bi
Normal file
2
tests/compile_tests/extra/include_extra.bi
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
PRINT "include_extra.bi was included!"
|
12
tests/compile_tests/extra/include_extra_include.bi
Normal file
12
tests/compile_tests/extra/include_extra_include.bi
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
' Include a file relative to the location of this file (which itself is included from elsewhere)
|
||||
|
||||
' Both relative formats should work
|
||||
|
||||
'$include:'./include_extra_target.bi'
|
||||
'$include:'include_extra_target.bi'
|
||||
|
||||
' Absolute position relative to the compiler should work too
|
||||
|
||||
'$include:'./tests/compile_tests/extra/include_extra_target.bi'
|
||||
'$include:'tests/compile_tests/extra/include_extra_target.bi'
|
4
tests/compile_tests/extra/include_extra_target.bi
Normal file
4
tests/compile_tests/extra/include_extra_target.bi
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
includeCount = includeCount + 1
|
||||
|
||||
PRINT "include_extra_target.bi was included! Include count:"; includeCount
|
|
@ -0,0 +1,10 @@
|
|||
$CONSOLE:ONLY
|
||||
|
||||
' This include path is relative to the location of QB64-PE
|
||||
|
||||
' Both relative path formats should work
|
||||
|
||||
'$include:'./tests/compile_tests/extra/include_extra.bi'
|
||||
'$include:'tests/compile_tests/extra/include_extra.bi'
|
||||
|
||||
SYSTEM
|
|
@ -0,0 +1,2 @@
|
|||
include_extra.bi was included!
|
||||
include_extra.bi was included!
|
12
tests/compile_tests/include_paths/include_multiple.bas
Normal file
12
tests/compile_tests/include_paths/include_multiple.bas
Normal file
|
@ -0,0 +1,12 @@
|
|||
$CONSOLE:ONLY
|
||||
|
||||
' Include a file that itself includes another file. It does so in a relative
|
||||
' fashion
|
||||
|
||||
Dim includeCount As Long
|
||||
|
||||
'$include:'../extra/include_extra_include.bi'
|
||||
'$include:'./tests/compile_tests/extra/include_extra_include.bi'
|
||||
'$include:'tests/compile_tests/extra/include_extra_include.bi'
|
||||
|
||||
SYSTEM
|
12
tests/compile_tests/include_paths/include_multiple.output
Normal file
12
tests/compile_tests/include_paths/include_multiple.output
Normal file
|
@ -0,0 +1,12 @@
|
|||
include_extra_target.bi was included! Include count: 1
|
||||
include_extra_target.bi was included! Include count: 2
|
||||
include_extra_target.bi was included! Include count: 3
|
||||
include_extra_target.bi was included! Include count: 4
|
||||
include_extra_target.bi was included! Include count: 5
|
||||
include_extra_target.bi was included! Include count: 6
|
||||
include_extra_target.bi was included! Include count: 7
|
||||
include_extra_target.bi was included! Include count: 8
|
||||
include_extra_target.bi was included! Include count: 9
|
||||
include_extra_target.bi was included! Include count: 10
|
||||
include_extra_target.bi was included! Include count: 11
|
||||
include_extra_target.bi was included! Include count: 12
|
7
tests/compile_tests/include_paths/include_relative.bas
Normal file
7
tests/compile_tests/include_paths/include_relative.bas
Normal file
|
@ -0,0 +1,7 @@
|
|||
$CONSOLE:ONLY
|
||||
|
||||
' This include path is specified relative to the location of the current source file
|
||||
|
||||
'$include:'../extra/include_extra.bi'
|
||||
|
||||
SYSTEM
|
|
@ -0,0 +1 @@
|
|||
include_extra.bi was included!
|
Loading…
Reference in a new issue