1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 12:40:36 +00:00

Merge pull request #201 from mkilgore/compile-relative-bas

Fix compiling bas files relative to the CWD
This commit is contained in:
Matt Kilgore 2022-10-01 13:25:01 -04:00 committed by GitHub
commit bdcb8f1b4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 95 additions and 3 deletions

View file

@ -379,7 +379,13 @@ DIM SHARED compilelog$
'$INCLUDE:'global\IDEsettings.bas'
DIM OutputIsRelativeToStartDir AS LONG
CMDLineFile = ParseCMDLineArgs$
IF CMDLineFile <> "" AND _FILEEXISTS(_STARTDIR$ + "/" + CMDLineFile) THEN
CMDLineFile = _STARTDIR$ + "/" + CMDLineFile
OutputIsRelativeToStartDir = -1
END IF
IF ConsoleMode THEN
_DEST _CONSOLE
@ -12316,19 +12322,38 @@ IF idemode = 0 AND No_C_Compile_Mode = 0 THEN
path.out$ = getfilepath$(outputfile_cmd$)
f$ = MID$(outputfile_cmd$, LEN(path.out$) + 1)
file$ = RemoveFileExtension$(f$)
IF LEN(path.out$) THEN
IF LEN(path.out$) OR OutputIsRelativeToStartDir THEN
currentdir$ = _CWD$
IF OutputIsRelativeToStartDir THEN
' This CHDIR makes the next CHDIR relative to _STARTDIR$
' We do this if the provided source file was also relative to _STARTDIR$
CHDIR _STARTDIR$
' If there was no provided path then that is the same as the
' output file being directly in _STARTDIR$. Assigning it here
' is perfectly fine and avoids failing the error check below
' with a blank string.
IF LEN(path.out$) = 0 THEN
path.out$ = _STARTDIR$
END IF
END IF
IF _DIREXISTS(path.out$) = 0 THEN
PRINT
PRINT "Can't create output executable - path not found: " + path.out$
IF ConsoleMode THEN SYSTEM 1
END 1
END IF
currentdir$ = _CWD$
CHDIR path.out$
path.out$ = _CWD$
CHDIR currentdir$
IF RIGHT$(path.out$, 1) <> pathsep$ THEN path.out$ = path.out$ + pathsep$
path.exe$ = path.out$
SaveExeWithSource = -1 'Override the global setting if an output file was specified
END IF
END IF

View file

@ -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 -q -m -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

View file

@ -0,0 +1,2 @@
PRINT "include_extra.bi was included!"

View 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'

View file

@ -0,0 +1,4 @@
includeCount = includeCount + 1
PRINT "include_extra_target.bi was included! Include count:"; includeCount

View file

@ -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

View file

@ -0,0 +1,2 @@
include_extra.bi was included!
include_extra.bi was included!

View 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

View 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

View 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

View file

@ -0,0 +1 @@
include_extra.bi was included!