每轮只推进合理适量的上下文、禁止顺手扩功能 smoke:源码链接构建约束
This commit is contained in:
@@ -5,24 +5,97 @@ cd "$(dirname "$0")"
|
||||
|
||||
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
|
||||
cxx=${CXX:-g++}
|
||||
build_dir=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_rs274_objects.XXXXXX")
|
||||
if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then
|
||||
cxx="ccache $cxx"
|
||||
fi
|
||||
build_jobs=${CNC_SIM_BUILD_JOBS:-8}
|
||||
if ! [[ "$build_jobs" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs" >&2
|
||||
exit 1
|
||||
fi
|
||||
build_dir=${CNC_SIM_SOURCE_OBJECTS_BUILD_DIR-build/source-objects-test}
|
||||
if [[ -z "$build_dir" ]]; then
|
||||
echo "CNC_SIM_SOURCE_OBJECTS_BUILD_DIR must not be empty" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$build_dir" =~ [[:space:]] ]]; then
|
||||
echo "CNC_SIM_SOURCE_OBJECTS_BUILD_DIR must not contain whitespace: $build_dir" >&2
|
||||
exit 1
|
||||
fi
|
||||
manifest=${1:-linuxcnc-rs274-source-files.txt}
|
||||
|
||||
trap 'rm -rf "$build_dir"' EXIT
|
||||
LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs.sh "$manifest"
|
||||
mkdir -p "$build_dir"
|
||||
build_dir=$(cd "$build_dir" && pwd)
|
||||
if [[ "$build_dir" == "/" ]]; then
|
||||
echo "CNC_SIM_SOURCE_OBJECTS_BUILD_DIR must not be the filesystem root" >&2
|
||||
exit 1
|
||||
fi
|
||||
exec 9>"$build_dir/source-objects.lock"
|
||||
flock 9
|
||||
preflight_cache_dir="$build_dir/preflight-cache"
|
||||
|
||||
LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh --cache-dir "$preflight_cache_dir" "$manifest"
|
||||
manifest=$(cd "$(dirname "$manifest")" && pwd)/$(basename "$manifest")
|
||||
linuxcnc_root=$(cd "$linuxcnc_root" && pwd)
|
||||
|
||||
common_flag_output=$(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-common-cxxflags.sh --python)
|
||||
mapfile -t common_flags <<<"$common_flag_output"
|
||||
|
||||
source_output=$(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-manifest-sources.sh "$manifest" core full)
|
||||
source_output=$(CNC_SIM_PREFLIGHT_CACHE_DIR="$preflight_cache_dir" LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-manifest-sources.sh "$manifest" core full)
|
||||
mapfile -t sources <<<"$source_output"
|
||||
|
||||
objects=()
|
||||
source_index=0
|
||||
for source in "${sources[@]}"; do
|
||||
obj="$build_dir/linuxcnc_${source_index}.o"
|
||||
"$cxx" "${common_flags[@]}" -c "$source" -o "$obj"
|
||||
objects+=("$build_dir/linuxcnc_${source_index}.o")
|
||||
source_index=$((source_index + 1))
|
||||
done
|
||||
|
||||
source_objects_signature="$build_dir/source-objects.signature"
|
||||
source_objects_next_signature="$build_dir/source-objects.signature.next"
|
||||
{
|
||||
printf 'CXX=%s\n' "$cxx"
|
||||
printf 'PWD=%s\n' "$PWD"
|
||||
printf 'LINUXCNC_ROOT=%s\n' "$linuxcnc_root"
|
||||
printf 'MANIFEST=%s\n' "$manifest"
|
||||
printf 'BUILD_RULE_VERSION=1\n'
|
||||
printf 'COMMON_FLAGS='
|
||||
printf ' %s' "${common_flags[@]}"
|
||||
printf '\n'
|
||||
printf 'SOURCES:\n'
|
||||
printf '%s\n' "${sources[@]}"
|
||||
} > "$source_objects_next_signature"
|
||||
if [[ ! -f "$source_objects_signature" ]] || ! cmp -s "$source_objects_signature" "$source_objects_next_signature"; then
|
||||
rm -f "$build_dir"/linuxcnc_*.o "$build_dir"/linuxcnc_*.o.d
|
||||
fi
|
||||
mv "$source_objects_next_signature" "$source_objects_signature"
|
||||
|
||||
source_objects_makefile="$build_dir/source-objects.mk"
|
||||
{
|
||||
printf 'CXX := %s\n' "$cxx"
|
||||
printf 'COMMON_FLAGS :='
|
||||
printf ' %s' "${common_flags[@]}"
|
||||
printf '\n\n'
|
||||
printf 'OBJECTS :='
|
||||
printf ' %s' "${objects[@]}"
|
||||
printf '\n\n'
|
||||
printf 'DEP_FILES :=\n'
|
||||
for object in "${objects[@]}"; do
|
||||
printf 'DEP_FILES += %s.d\n' "$object"
|
||||
done
|
||||
printf '\n.PHONY: all\n'
|
||||
printf 'all: $(OBJECTS)\n\n'
|
||||
|
||||
source_index=0
|
||||
for source in "${sources[@]}"; do
|
||||
printf '%s: %s\n' "${objects[$source_index]}" "$source"
|
||||
printf '\t@$(CXX) $(COMMON_FLAGS) -MMD -MP -MF %s.d -c %s -o %s\n\n' \
|
||||
"${objects[$source_index]}" "$source" "${objects[$source_index]}"
|
||||
source_index=$((source_index + 1))
|
||||
done
|
||||
printf '\n-include $(DEP_FILES)\n'
|
||||
} > "$source_objects_makefile"
|
||||
make --output-sync=target -j"$build_jobs" -f "$source_objects_makefile"
|
||||
|
||||
echo "linuxcnc rs274 source object build passed (${#sources[@]} objects)"
|
||||
echo "built objects in $build_dir"
|
||||
|
||||
Reference in New Issue
Block a user