Skip to content

Commit

Permalink
[test] Add test/configure-effects.sh
Browse files Browse the repository at this point in the history
Our build detection is inconsistent between C++ and Python.  This test
will help make it consistent.

- Fix flag typo in ./configure
- Refactor ./configure
  • Loading branch information
Andy C committed Jan 5, 2025
1 parent 1aeec95 commit c1eb56c
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 29 deletions.
71 changes: 52 additions & 19 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,23 @@ FLAG_datarootdir='' # default initialized after processing flags
FLAG_with_readline='' # Fail if it's not available.
FLAG_without_readline='' # Don't even check if it's available
FLAG_readline=''
FLAG_with_systemtap_sdt='' # Fail if it's not available.
FLAG_without_systemtap_sdt='' # Don't even check if it's available
FLAG_without_libc_features=''

# These variables are set by detect_readline and used by echo_cpp and
# echo_shell_vars
detected_deps=''

have_readline=''
readline_dir=''

have_systemtap_sdt=''

# libc
have_fnm_extmatch=''
have_glob_period=''
have_pwent=''

parse_flags() {
while true; do
case "$1" in
Expand Down Expand Up @@ -111,12 +117,12 @@ parse_flags() {
FLAG_readline=$1
;;

--with-systemtap_sdt)
FLAG_with_systemtap_sdt=1
--without-systemtap-sdt)
FLAG_without_systemtap_sdt=1
;;

--without-systemtap_sdt)
FLAG_without_systemtap_sdt=1
--without-libc-features)
FLAG_without_libc_features=1
;;

# TODO: Maybe prefix only needs to be part of the install step? I'm not
Expand Down Expand Up @@ -269,25 +275,51 @@ detect_systemtap_sdt() {
fi
}

detect_libc() {
if test -n "$FLAG_without_libc_features"; then
return
fi

# Check if non-POSIX FNM_EXTMATCH is available
if cc_quiet build/detect-fnm-extmatch.c; then
have_fnm_extmatch=1
fi

# Check if non-POSIX GLOB_PERIOD is available
if cc_quiet build/detect-glob-period.c; then
have_glob_period=1
fi

# Check if pwent is callable. E.g. bionic libc (Android) doesn't have it
if cc_quiet build/detect-pwent.c; then
have_pwent=1
fi
}

echo_shell_vars() {
if test "$detected_deps" != 1; then
die 'called echo_shell_vars before detecting readline.'
fi

# Present a consistent interface to build/ninja-rules-cpp.sh
if test "$have_readline" = 1; then
echo 'HAVE_READLINE=1'
echo "READLINE_DIR=$readline_dir"
else
echo 'HAVE_READLINE='
# Present a consistent interface to build/ninja-rules-cpp.sh
echo 'READLINE_DIR='
fi

# TODO: I don't think we need this in shell
if test "$have_systemtap_sdt" = 1; then
echo 'HAVE_SYSTEMTAP_SDT=1'
else
echo 'HAVE_SYSTEMTAP_SDT='
fi

echo "PREFIX=$FLAG_prefix"
echo "DATAROOTDIR=$FLAG_datarootdir"

if cc_quiet build/detect-cc.c -Wl,--gc-sections; then
echo 'STRIP_FLAGS=--gc-sections'
elif cc_quiet build/detect-cc.c -Wl,-dead_strip; then
Expand Down Expand Up @@ -433,35 +465,34 @@ echo_cpp() {
echo '/* #undef HAVE_READLINE */'
fi

# Used by mycpp/probes.h
if test "$have_systemtap_sdt" = 1; then
echo '#define HAVE_SYSTEMTAP_SDT 1'
else
echo '/* #undef HAVE_SYSTEMTAP_SDT */'
fi

# Check if pwent is callable. E.g. bionic libc (Android) doesn't have it
if cc_quiet build/detect-pwent.c; then
echo '#define HAVE_PWENT 1'
if test "$have_fnm_extmatch" = 1; then
echo '/* libc defines FNM_EXTMATCH */'
else
echo '/* #undef HAVE_PWENT */'
# INVALID value that we can detect in code
# e.g. musl libc does not support this, but glibc does
echo '#define FNM_EXTMATCH 0'
fi

# Check if non-POSIX GLOB_PERIOD is available
if cc_quiet build/detect-glob-period.c; then
if test "$have_glob_period" = 1; then
echo '/* libc defines GLOB_PERIOD */'
else
# INVALID value that we can detect in code
# e.g. Android does not support this, but glibc and musl libc do
echo '#define GLOB_PERIOD 0'
fi

# Check if non-POSIX GLOB_PERIOD is available
if cc_quiet build/detect-fnm-extmatch.c; then
echo '/* libc defines FNM_EXTMATCH */'
# Used by cpp/core.cc
if test "$have_pwent" = 1; then
echo '#define HAVE_PWENT 1'
else
# INVALID value that we can detect in code
# e.g. musl libc does not support this, but glibc does
echo '#define FNM_EXTMATCH 0'
echo '/* #undef HAVE_PWENT */'
fi
}

Expand All @@ -480,9 +511,11 @@ main() {
# Sets globals $have_readline and $readline_dir
detect_readline

detect_libc

detect_systemtap_sdt

# Generate configuration for oil-native
# Generate configuration for oils-for-unix
local cpp_out=_build/detected-cpp-config.h
echo_cpp > $cpp_out
log "Wrote $cpp_out"
Expand Down
16 changes: 15 additions & 1 deletion core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
NewDict)
from pylib import os_path

from libc import GLOB_PERIOD
import posix_ as posix

from typing import Tuple, List, Dict, Optional, Any, cast, TYPE_CHECKING
Expand Down Expand Up @@ -344,6 +345,14 @@ def _SetOptionNum(opt_name):
return opt_num


def _MaybeWarnDotglob():
# type: () -> None
if GLOB_PERIOD == 0: # invalid value that means it wasn't detected
# GNU libc and musl libc have GLOB_PERIOD, but Android doesn't
print_stderr(
"osh warning: GLOB_PERIOD wasn't found in libc, so 'shopt -s dotglob' won't work")


class MutableOpts(object):

def __init__(self, mem, environ, opt0_array, opt_stacks, opt_hook):
Expand Down Expand Up @@ -379,6 +388,9 @@ def _InitOptionsFromEnv(self, shellopts):

def Push(self, opt_num, b):
# type: (int, bool) -> None
if opt_num == option_i.dotglob:
_MaybeWarnDotglob()

overlay = self.opt_stacks[opt_num]
if overlay is None or len(overlay) == 0:
self.opt_stacks[opt_num] = [b] # Allocate a new list
Expand Down Expand Up @@ -418,6 +430,8 @@ def _Set(self, opt_num, b):
For bash compatibility in command sub.
"""
if opt_num == option_i.dotglob:
_MaybeWarnDotglob()

# Like _Getter in core/optview.py
overlay = self.opt_stacks[opt_num]
Expand Down Expand Up @@ -510,7 +524,7 @@ def _SetOldOption(self, opt_name, b):
self.SetDeferredErrExit(b)
else:
if opt_num == option_i.verbose and b:
print_stderr('Warning: set -o verbose not implemented')
print_stderr('osh warning: set -o verbose not implemented')
self._SetArrayByNum(opt_num, b)

# note: may FAIL before we get here.
Expand Down
11 changes: 6 additions & 5 deletions deps/from-tar.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env bash
#
# Handle build dependencies that are in tarballs.
# Handle build dependencies that are in tarballs, like the wild
#
# Usage:
# deps/from-tar.sh <function name>
#
# Examples:
# deps/from-tar.sh download-re2c
# deps/from-tar.sh build-re2c
# For releases:
#
# The executable will be in ../oil_DEPS/re2c/re2c.
# deps/from-tar.sh configure-python
# deps/from-tar.sh build-python
#
# Note: this is not a tarball; it's in the repo.

set -o nounset
set -o pipefail
Expand Down
3 changes: 2 additions & 1 deletion devtools/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# devtools/release.sh <function name>
#
# Steps:
# edit oils-version.txt, build/doc.sh update-src-versions, bump devtools/release-note.sh
# edit oils-version.txt, build/doc.sh update-src-versions, and
# bump devtools/release-note.sh
# $0 make-release-branch
# $0 two-tarballs # CPython, then oils-for-unix, which is INSTALLED
# demo/osh-debug.sh osh-for-release: Start a shell to dogfood
Expand Down
2 changes: 0 additions & 2 deletions doc/portability.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ which some libc's implement.

This is unlike bash, which has its own glob library.

TODO: `shopt -s dotglob` should give a warning when turned on.

### Atomic Assignments

The signal handler assumes that int and pointer assignments are atomic. This
Expand Down
4 changes: 4 additions & 0 deletions frontend/py_readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
try:
import line_input
except ImportError:
# Note: build/ovm-compile.sh doesn't build pyext/line_input.c unless shell
# var $HAVE_READLINE is set
# On the other hand, cpp/frontend_pyreadline.cc uses -D HAVE_READLINE, a
# C++ preprocessor var
line_input = None

from typing import Optional, TYPE_CHECKING
Expand Down
3 changes: 2 additions & 1 deletion osh/glob_.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
)
from core import pyutil
from frontend import match
from libc import GLOB_PERIOD
from mycpp import mylib
from mycpp.mylib import log, print_stderr

from libc import GLOB_PERIOD

from typing import List, Tuple, cast, TYPE_CHECKING
if TYPE_CHECKING:
from core import optview
Expand Down
62 changes: 62 additions & 0 deletions test/configure-effects.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
#
# What happens if various build features aren't detected?
# In Python and C++
#
# Usage:
# test/configure-effects.sh <function name>

set -o nounset
set -o pipefail
set -o errexit

# bugs:
# echo | tr
# echo | cat
# history | less

prepare-cpp() {
./NINJA-config.sh

# This overwrites the config
./configure --without-readline --without-libc-features --without-systemtap-sdt

ninja
}

prepare-py() {
make
}

test-osh() {
local osh=$1

$osh -x -c 'set -o vi'
$osh -x -c 'set -o emacs'

# GLOB_PERIOD
$osh -x -c 'shopt -s dotglob'

# FNM_EXTMATCH
# Hm this will works
$osh -x -c 'echo */@(*.bash|*.asdl)'

# HAVE_PWENT
$osh -x -c 'compgen -A user'
}

cpp() {
#prepare

test-osh _bin/cxx-asan/osh
}

py() {
#prepare-py

ln -s -f -v oil.ovm _bin/osh

test-osh _bin/osh
}

"$@"

0 comments on commit c1eb56c

Please sign in to comment.