AOSC-Archive / autobuild3

AOSC OS package maintenance toolkit (version 3)
https://aosc.io
GNU General Public License v2.0
24 stars 17 forks source link

Epoch ":" handling #21

Closed MingcongBai closed 9 years ago

Artoria2e5 commented 9 years ago

There are some TO-Discuss in autobuild.

Which way shall we treat as the standard?

How shall we rewrite the PKGREL integer when it was splitted from the PKGVER string?

# Pseudocode is always the most realistic thing.
_ext_done verlint || warn VERSION not linted.

# when pkgver stuffs is default..
dump_pkgver(){
    echo -n PKGVER=
    (( PKGEPOCH )) && echo -n $PKGEPOCH:
    echo -n $PKGVER
    (( PKGREL )) && echo -n $PKGREL
}

# and when splitting is the default:
dump_verinfo(){
    (( PKGREL )) && echo -n PKGREL=$PKGREL
    echo -n PKGVER=$PKGVER
    (( PKGEPOCH )) && echo -n PKGEPOCH=$PKGEPOCH
}

# START PROCESSING
buf="$(dump_$_ab_formatset)"

read_since(){ local buf="$(cat)"; grep -A99999 -m 1 -E "$i" <<< "$buf" || echo "$buf"; }
read_until(){ local buf="$(cat)"; grep -B99999 -m 1 -E "$i" <<< "$buf" || echo "$buf"; }

# Warning: control-char-unsafe.
# Doing grep -A -B is faster, but we would like to keep outputing even if we didn't find any candidate.
# Well now we figured out a way.
_bash_read_until(){ local i e BASH_REMATCH; while read i; do ((e)) || { [[ "$i" =~ $1 ]] && e=1 || echo "$i"; }; done; }
_bash_read_since(){ local i e BASH_REMATCH; while read i; do ((e)) || { [[ "$i" =~ $1 ]] && e=1 } && echo "$i"; done; }
# grep version, safe

# guess format
if ((_ext_versplit_orig_noepoch)); then
  if ((_ext_versplit_orig_norelease)); then # PKGVER ONLY
    head="$(read_until '^PKGVER=' < autobuild/defines | head -n +1)"
    tail="$(read_since '^PKGVER=' < autobuild/defines | tail -n +1)"
  else                              # HAS RELEASE, 
    head=
  fi
else                                    # NEWTYPE, 

fi
echo "$head
$buf
$tail" > autobuild/defines

Current Problems

The current grep method may look fine for regular human-written scripts, with orders like [EPOCH]\nVER\n[REL]. However, this can never be assumed easily.

One way is to import it using show_differences_from_to "$(bash --norc -c '. autobuild/defines; set)" "$(bash --norc -c set)", so we know what variables are added to the file. However, just like the declare -f method in pkg2ab, we lose sorting and comments in the original file.

There may be a better solution by using some triple-pass read_until things, if we assume there are no extra variables among those three variables.

MingcongBai commented 9 years ago

It works as far as now. Closing, please open a new one with upcoming issues.