File: sip_include.sh

package info (click to toggle)
qgis 3.44.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,237,544 kB
  • sloc: cpp: 1,668,420; python: 381,688; xml: 23,474; perl: 4,078; sh: 3,733; ansic: 2,799; sql: 2,137; yacc: 1,068; lex: 577; javascript: 540; lisp: 411; makefile: 155
file content (87 lines) | stat: -rwxr-xr-x 3,491 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
###########################################################################
#    sip_include.sh
#    ---------------------
#    Date                 : 21.06.2017
#    Copyright            : (C) 2017 by Denis Rouzaud
#    Email                : denis.rouzaud@gmail.com
###########################################################################
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 2 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
###########################################################################
set -e

if [ $BASH_VERSINFO -lt 4 ]; then
    echo "You need bash version 4+ to run this script."
    echo "Your bash version is $BASH_VERSION"
    exit 1
fi

DIR=$(git rev-parse --show-toplevel)

pushd ${DIR} > /dev/null

# GNU prefix command for bsd/mac os support (gsed, gsplit)
GP=
if [[ "$OSTYPE" == *bsd* ]] || [[ "$OSTYPE" =~ darwin* ]]; then
  GP=g
fi

if [[ -n $1 ]]; then
  modules=("$1")
else
  modules=(core gui analysis server 3d)
fi
sources=(HDRS MOC_HDRS SRCS)

for root_dir in python python/PyQt6; do
  for module in "${modules[@]}"; do
    file=${DIR}/$root_dir/${module}/${module}_auto.sip
    echo "Creating $root_dir/${module}/${module}_auto.sip"
    echo "// Include auto-generated SIP files" > $file

    headers=$(
      for source in "${sources[@]}"; do
        echo "QGIS_${module^^}_${source}"
        ${GP}sed -r -n -e "/^\s*set\s*\(QGIS_${module^^}_${source}/,/\)\$/{ /^\s*set\s*\(QGIS_${module^^}_${source}/d; /\)\$/d; p; }" src/${module}/CMakeLists.txt | \
          ${GP}sed -r -e '/\.cc?$/d'     `# remove c and cc extensions` \
               -e 's/\.cpp$/.h/'  `# rename cpp file as headers` \
               -e '/^\s*\$\{CMAKE_(CURRENT_)?BINARY_DIR\}/d' \
               -e '/^\s*#/d'      `# remove commented lines` \
               -e 's/\$\{.*\}//g' `# remove CMake variable append` \
               -e 's/^\s+//'      `# remove leading spaces` \
               -e '/^\s*$/d'      `# remove blank lines`
      done | cat -n | sort -uk2 | sort -nk1 | cut -f2-  # remove duplicated lines without sorting
           )
    for header in ${headers}; do
      if [ ! -f src/${module}/$header ]; then
        # if no header, no sip file!
        #echo "src/${module}/$header not found"
        continue
      fi
      if ! grep -xq -E '^(#define +)?SIP_NO_FILE' src/${module}/${header}; then
        sip=$(${GP}sed -r 's/(.*)\.h$/\1.sip/' <<< ${header})
        if_cond=$(grep -x -E '^(#define +)?SIP_IF_MODULE\((.*)\)$' src/${module}/${header} | \
                    ${GP}sed -r -e 's/(#define +)?SIP_IF_MODULE\((.*)\)/%If (\2)/')
        if [[ -n $if_cond ]]; then
          echo "$if_cond" >> $file
        fi
        if [[ "$sip" == [0-9]* ]]; then
          # unfortunately SIP parser does not accept relative paths starting with a number
          # so "%Include 3d/xxxx.sip" is a syntax error but everything works with "%Include ./3d/xxxx.sip"
          sip="./$sip"
        fi
        echo "%Include auto_generated/$sip" >> $file
        if [[ -n $if_cond ]]; then
          echo "%End" >> $file
        fi
      fi
    done
  done
done

popd > /dev/null