Skip to content

Commit

Permalink
tools/cripts/compiler.sh: sanitize and allow for extensibility (#12018)
Browse files Browse the repository at this point in the history
- Avoid potential issues with globbing/space in filenames
- Make this script usable by other scripts calling into it
  • Loading branch information
yannk authored Feb 7, 2025
1 parent 9a7488f commit 1fdb602
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tools/cripts/compiler.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
Expand All @@ -24,24 +24,24 @@
##############################################################################

# Configurable parts
ATS_ROOT=/opt/ats
CXX=clang++
CXXFLAGS="-std=c++20 -I/opt/homebrew/include -undefined dynamic_lookup"
: ${ATS_ROOT:="/opt/ats"}
: ${CXX:="clang++"}
: ${CXXFLAGS:="-std=c++20 -I/opt/homebrew/include -undefined dynamic_lookup"}

# Probably don't need to change these ?
STDFLAGS="-shared -fPIC -Wall -Werror -I${ATS_ROOT}/include -L${ATS_ROOT}/lib -lcripts"

# This is optional, but if set, the script will cache the compiled shared objects for faster restarts/reloads
CACHE_DIR=/tmp/ats-cache
: ${CACHE_DIR:="/tmp/ats-cache"}

# Extract the arguments, and do some sanity checks
SOURCE=$1
DEST=$2
SOURCE="$1"
DEST="$2"

SOURCE_DIR=$(dirname $SOURCE)
DEST_DIR=$(dirname $DEST)
SOURCE_FILE=$(basename $SOURCE)
DEST_FILE=$(basename $DEST)
SOURCE_DIR=$(dirname "$SOURCE")
DEST_DIR=$(dirname "$DEST")
SOURCE_FILE=$(basename "$SOURCE")
DEST_FILE=$(basename "$DEST")

cd "$SOURCE_DIR"
if [ $(pwd) != "$SOURCE_DIR" ]; then
Expand Down Expand Up @@ -81,10 +81,10 @@ if [ -d "$CACHE_DIR" ]; then
fi

# Compile the plugin
${CXX} ${CXXFLAGS} ${STDFLAGS} -o $DEST $SOURCE
${CXX} ${CXXFLAGS} ${STDFLAGS} -o "$DEST" "$SOURCE"
exit_code=$?

if [ $exit_code -ne 0 ]; then
if [ "$exit_code" -ne 0 ]; then
echo "Compilation failed with exit code $exit_code"
exit $exit_code
fi
Expand Down

0 comments on commit 1fdb602

Please sign in to comment.