Skip to content

./bin/build.sh does not automatically set ROOT_DIR outside of tipc directory #115

Description

@thepetertessier

I don't know if this counts as a "bug", but when using build.sh outside of the tipc directory, I get the strange error message:

fatal: not a git repository (or any parent up to mount point /u)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

See the full example of what I'm getting (on portal, after the aforementioned git pull):

# Just entered portal, go to my desired directory and load the module:
fpv5gr@portal10:~$ cd CS_4620/
fpv5gr@portal10:~/CS_4620$ module load /u/fpv5gr/CS_4620/tipc/conf/modulefiles/tipc/F24
Loading /u/fpv5gr/CS_4620/tipc/conf/modulefiles/tipc/F24
  Loading requirement: /u/fpv5gr/CS_4620/tipc/conf/modulefiles/java/11 clang-llvm-17.0.6 cmake-3.26.4

# An example tip program:
fpv5gr@portal10:~/CS_4620$ cat exercise_01/hello.tip
main(x) {
    return x+13;
}

# I try to use build.sh outside of tipc:
fpv5gr@portal10:~/CS_4620$ tipc/bin/build.sh exercise_01/hello.tip
fatal: not a git repository (or any parent up to mount point /u)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

# I try again, inside of tipc:
fpv5gr@portal10:~/CS_4620$ cd tipc/
fpv5gr@portal10:~/CS_4620/tipc$ bin/build.sh ../exercise_01/hello.tip

# No error message now, and indeed it worked:
fpv5gr@portal10:~/CS_4620/tipc$ ./hello 1
Program output: 14

I believe this is due to line 5 of build.sh:

ROOT_DIR=${TIPDIR:-$(git rev-parse --show-toplevel)}

If I still want to run build.sh outside of the tipc directory, I can just export TIPDIR=.../tipc. However, I had to do some digging to figure this out. Perhaps we can add some validation before setting ROOT_DIR, such as:

# Check if we can set the ROOT_DIR as TIPDIR or as the root of the git repo
if [ -z "${TIPDIR}" ] && ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
    echo "error: Not in a git repository and TIPDIR is not set. Please export TIPDIR=.../tipc"
    exit 1
fi

That will at least make the issue more diagnosable for the user.

The method of automatically setting ROOT_DIR based on what git repo we are in could have another potential problem of quietly setting it to another git repo we are currently in. But perhaps for the scope of this project, it is fine to assume this edge case won't happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions