rochus-keller / BUSY

BUSY is a lean, statically typed, cross-platform, easily bootstrappable build system for GCC, CLANG and MSVC inspired by Google GN
GNU General Public License v2.0
81 stars 6 forks source link

build.lua:105: getcwd delivered a path not supported by this application #1

Closed mingodad closed 1 year ago

mingodad commented 1 year ago

Following the instructions on the README I'm getting this result on Ubuntu 18.04 64 bits

cc *.c -O2 -lm -O2 -o lua-busy
./lua-busy build.lua 
# Hello from BUSY version 2023-01-21
./lua-busy: build.lua:105: getcwd delivered a path not supported by this application
stack traceback:
    [C]: in function 'compile'
    build.lua:105: in main chunk
    [C]: ?
rochus-keller commented 1 year ago

Oops, looks like I made something worse. Can you use explicit path?

mingodad commented 1 year ago

How to do that ?

./lua-busy /home/xxx/dev/BUSY/build.lua 
# Hello from BUSY version 2023-01-21
./lua-busy: /home/xxx/dev/BUSY/build.lua:105: getcwd delivered a path not supported by this application
stack traceback:
    [C]: in function 'compile'
    /home/xxx/dev/BUSY/build.lua:105: in main chunk
    [C]: ?
rochus-keller commented 1 year ago

See the section "Running Busy" (https://github.com/rochus-keller/BUSY/blob/main/README.md#running-busy) in the Readme.

I will try to reproduce the issue you reported and provide a fix soon.

mingodad commented 1 year ago
./lua-busy build.lua -B $PWD
# Hello from BUSY version 2023-01-21
./lua-busy: build.lua:105: path format is invalid: /home/xxx/dev/BUSY
stack traceback:
    [C]: in function 'compile'
    build.lua:105: in main chunk
    [C]: ?
rochus-keller commented 1 year ago

Unfortunately I cannot reproduce what you get. Apparently you're on a Linux machine aswell. I just randomly created a busy directory somewhere and put the source code in, and then run "cc *.c -O2 -lm -O2 -o lua" and after that "./lua build.lua" and I get the following:

~/Desktop/Lisa_Source/busy $ cc *.c -O2 -lm -O2 -o lua
bshost.c: In function ‘bs_cwd’:
bshost.c:319:11: warning: ignoring return value of ‘getcwd’, declared with attribute warn_unused_result [-Wunused-result]
     getcwd(buffer, sizeof(buffer));
           ^
/tmp/ccss8zKK.o: In function `os_tmpname':
loslib.c:(.text+0x32d): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
~/Desktop/Lisa_Source/busy $ ./lua build.lua
# Hello from BUSY version 2023-01-21
# running parser
# root source directory is //home/me/Desktop/Lisa_Source
cannot open file for reading /home/me/Desktop/Lisa_Source/BUSY
~/Desktop/Lisa_Source/busy $ 

You could instrument the result of getcwd() like so (bshost.c line 316):

BSPathStatus bs_cwd()
{
    char buffer[PATH_MAX];
    getcwd(buffer, sizeof(buffer));
    printf(stdout, "result of getcwd: %s\n", buffer);
    return bs_normalize_path2(buffer);
}

and tell me what comes out.

EDIT: according to your console outputs there seems to be something in your path which bs_normalize_path2 doesn't like; is it a special char? or spaces without "" framing?

mingodad commented 1 year ago

I build it with debug info and using gdb found that it doesn't recognize one letter directory in my case /home/xxx/dev/c/BUSY it stops processing ẁhen it encounter /c/ in the code shown bellow from bshost.c::bs_normalize_path:

    while( inlen )
    {
        uchar n = 0;
        uint ch = unicode_decode_utf8((const uchar*) in, &n);
        if( ch == '/' || ch == '\\' )
        {
            if( lastSlash )
            {
                const int diff = i - lastSlash;
                switch(diff)
                {
                case 1:
                    return BS_InvalidFormat;
                case 2:
                    if( strncmp(out+lastSlash,"/./",3) == 0 ||
                            strncmp(out+lastSlash,"\\.\\",3))
                        return BS_InvalidFormat;  /////!!!!!! returning from here
                    break;
rochus-keller commented 1 year ago

Ok, that helps, thanks for debugging. With this information I should be able to locate and fix the issue. Will try tonight.

rochus-keller commented 1 year ago

I've found it; actually I should have immediately seen it in your above post, but I had to run the code in the debugger that it finally caught my eye. Just replace the line strncmp(out+lastSlash,"\\.\\",3)) with strncmp(out+lastSlash,"\\.\\",3)==0 ). This will be part of the next commit. Thanks again for your help.

mingodad commented 1 year ago

Now with the proposed fix I'm getting this:

./lua-busy build.lua
# Hello from BUSY version 2023-01-21
# running parser
# root source directory is //home/xxx/dev/c/A_apps
# analyzing //home/mingo/dev/c/A_apps/BUSY
cannot determine file size /home/xxx/dev/c/A_apps/BUSY
mingodad commented 1 year ago

My cloned code is at /home/xxx/dev/c/A_apps/BUSY folder.

mingodad commented 1 year ago

Using this command line I'm getting this (missing -lm ?):

./lua-busy build.lua -S $PWD
# Hello from BUSY version 2023-01-21
# running parser
# root source directory is //home/xxx/dev/c/A_apps/BUSY
# analyzing //home/xxx/dev/c/A_apps/BUSY/BUSY
# running build for //home/xxx/dev/c/A_apps/BUSY
# root build directory is //home/xxx/dev/c/A_apps/BUSY/output
# building Library lib
gcc  -O2 -c -o "/home/xxx/dev/c/A_apps/BUSY/output/lib_bshost.c.o" "/home/xxx/dev/c/A_apps/BUSY/bshost.c" 
...
gcc  -O2 -c -o "/home/xxx/dev/c/A_apps/BUSY/output/exe_lua.c.o" "/home/xxx/dev/c/A_apps/BUSY/lua.c" 
gcc @"/home/xxx/dev/c/A_apps/BUSY/output/exe.rsp" -o "/home/xxx/dev/c/A_apps/BUSY/output/exe"
/home/xxx/dev/c/A_apps/BUSY/output/liblib.a(lib_loslib.c.o): In function `os_tmpname':
loslib.c:(.text+0x2a1): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
/home/xxx/dev/c/A_apps/BUSY/output/liblib.a(lib_lvm.c.o): In function `Arith':
lvm.c:(.text+0x5b9): undefined reference to `pow'
/home/xxx/dev/c/A_apps/BUSY/output/liblib.a(lib_lvm.c.o): In function `luaV_execute':
lvm.c:(.text+0x2437): undefined reference to `pow'
...
/home/xxx/dev/c/A_apps/BUSY/output/liblib.a(lib_lmathlib.c.o): In function `math_acos':
lmathlib.c:(.text+0x95f): undefined reference to `acos'
collect2: error: ld returned 1 exit status
rochus-keller commented 1 year ago

Can you please have a look at and try an example project, e.g. https://github.com/rochus-keller/NAppgui or https://github.com/rochus-keller/LeanQt/blob/main/Readme.md#how-to-build-the-oberon-ide-with-leanqt.

You seem to try BUSY with no project, but BUSY sees itself and either tries to use the BUSY folder as a file (why you get the size error) or to run its own BUSY file (which is not suited to build BUSY itself, but to integrate BUSY in another application such as LeanCreator).