Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gen_wok_db()
- {
- report step "Generating wok database"
- report open-bloc
- report step "Removing old files"
- for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
- [ -f $file ] && rm $file
- done
- report step "Generating wok-wanted.txt"
- gen_wan_db
- report step "Generating wok-depends.txt"
- for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
- $INCOMING_REPOSITORY/packages.desc | sort -u); do
- RECEIPT=$WOK/$PACKAGE/receipt
- if [ -s $RECEIPT ]; then
- source_receipt
- echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
- fi
- done
- sort_db
- report close-bloc
- }
- gen_wan_db()
- {
- rm -f $wan_db
- for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
- WANTED=
- source $RECEIPT
- [ "$WANTED" ] || continue
- echo -e $PACKAGE"\t"$WANTED >> $wan_db
- done
- }
- update_wan_db()
- {
- local PACKAGE=$PACKAGE
- wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
- grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
- echo "$wanted_list" | fgrep -q /$wan/receipt && continue
- sed "/^$wan\t/d" -i $wan_db
- done
- for RECEIPT in $wanted_list; do
- unset WANTED PACKAGE
- source $RECEIPT
- [ "$WANTED" ] || continue
- sed "/^$PACKAGE\t/d" -i $wan_db
- echo -e $PACKAGE"\t"$WANTED >> $wan_db
- done
- unset wanted_list
- }
- update_dep_db()
- {
- sed "/^$PACKAGE\t/d" -i $dep_db
- echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
- }
- sort_db()
- {
- report step "Generating cookorder.txt"
- cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
- grep -q ^$PACKAGE$'\t' $wan_db && continue
- # Replace each BUILD_DEPENDS with a WANTED package by it's
- # WANTED package.
- replace_by_wanted()
- {
- for p in $BUILD_DEPENDS; do
- if grep -q ^$p$'\t' $wan_db; then
- echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
- else
- echo -n $p' '
- fi
- done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
- }
- echo -e $PACKAGE"\t $(replace_by_wanted) "
- done > $tmp/db
- while [ -s "$tmp/db" ]; do
- status=start
- for pkg in $(cut -f 1 $tmp/db); do
- if ! fgrep -q ' '$pkg' ' $tmp/db; then
- echo $pkg >> $tmp/cookorder
- sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
- status=proceed
- fi
- done
- if [ "$status" = start ]; then
- cp -f $tmp/db /tmp/remain-depends.txt
- echo "Can't go further because of dependency loop(s). The remaining packages will be commented in the cookorder and will be unbuilt in case of major updates until the problem is solved." >&2
- for blocked in $(cut -f 1 $tmp/db); do
- echo "$blocked" >> $PACKAGES_REPOSITORY/blocked
- done
- break
- fi
- done
- [ -s $tmp/cookorder ] || touch $tmp/cookorder
- # The toolchain packages are moved in first position.
- grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
- --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
- $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
- for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
- sed "/^$pkg$/d" -i $tmp/cookorder
- done
- tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
- report end-step
- }
- ########################################################################
- # SCAN CORE
- ########################
- # Includes various scan core-functions. It's not intended to be used
- # directly : prefer scan wrappers in next section.
- look_for_dep()
- {
- if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
- grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
- | cut -f 2
- else
- grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
- cut -f 2
- fi
- }
- look_for_bdep()
- {
- look_for_all
- }
- look_for_all()
- {
- if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
- grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
- | cut -f 2,3 | sed 's/ / /'
- else
- grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
- cut -f 2,3 | sed 's/ / /'
- fi
- }
- look_for_rdep()
- {
- fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
- if [ "$undigest" ]; then
- for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
- if [ ! -f "WOK$/$rdep/receipt" ]; then
- echo "$rdep"
- fi
- done
- fi
- }
- look_for_rbdep()
- {
- fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
- cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
- if [ "$undigest" ]; then
- for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
- | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
- if [ ! -f "WOK$/$rdep/receipt" ]; then
- echo "$rdep"
- fi
- done
- fi
- }
- # Return WANTED if it exists.
- look_for_wanted()
- {
- if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
- grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
- else
- grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
- fi
- }
- # Return packages which wants PACKAGE.
- look_for_rwanted()
- {
- grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
- if [ "$undigest" ]; then
- for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
- if [ ! -f "$WOK/$rwanted/receipt" ]; then
- echo "$rwanted"
- fi
- done
- fi
- }
- look_for_dev()
- {
- WANTED=$(look_for_wanted)
- if [ "$WANTED" ]; then
- if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
- [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
- else
- [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
- fi
- fi
- if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
- [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
- else
- [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
- fi
- }
- with_dev()
- {
- for PACKAGE in $(cat); do
- echo $PACKAGE
- look_for_dev
- done
- }
- with_wanted()
- {
- for PACKAGE in $(cat); do
- echo $PACKAGE
- look_for_wanted
- done
- }
- use_wanted()
- {
- for input in $(cat); do
- { grep ^$input$'\t' $wan_db || echo $input
- } | sed 's/.*\t//'
- done
- }
- ########################################################################
- # SCAN
- ########################
- # Use wok-wanted.txt and wok-depeds.txt to scan depends.
- # Option in command line (must be first arg) :
- # --look_for=bdep/rbdep - Look for depends or reverse depends.
- # --with_dev - Add development packages (*-dev) in the result.
- # --with_wanted - Add package+reverse wanted in the result.
- # --with_args - Include packages in argument in the result.
- scan()
- {
- # Get packages in argument.
- local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
- for arg in $@; do
- [ "$arg" = "${arg#--}" ] || continue
- pkg_list="$pkg_list $arg"
- done
- # Get options.
- [ "$pkg_list" ] || return
- local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
- get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
- get_options
- # Get db md5 to be able to check for changes latter.
- db_md5=$(md5sum $dep_db $wan_db)
- # Cooklist is a special case where we need to modify a little
- # scan behavior
- if [ "$cooklist" ]; then
- gen_wan_db
- look_for=all && with_args=yes && with_dev= && with_wanted=
- filter=use_wanted
- if [ "$COMMAND" = gen-cooklist ]; then
- for PACKAGE in $pkg_list; do
- grep -q ^$PACKAGE$'\t' $dep_db && continue
- [ -d "$WOK/$p" ] || continue
- check_for_missing
- done
- append_to_dep()
- {
- if ! grep -q ^$PACKAGE$'\t' $dep_db; then
- check_for_missing && echo $PACKAGE >> $tmp/dep
- else
- echo $PACKAGE >> $tmp/dep
- fi
- }
- else
- append_to_dep()
- {
- check_for_commit && echo $PACKAGE >> $tmp/dep
- }
- fi
- else
- append_to_dep()
- {
- echo $PACKAGE >> $tmp/dep
- }
- # If requested packages are not in dep_db, partial generation of this db is needed.
- for PACKAGE in $pkg_list; do
- grep -q ^$PACKAGE$'\t' $dep_db && continue
- [ -d "$WOK/$p" ] || continue
- plan_check_for_missing=yes
- check_for_missing
- done
- if [ "$plan_check_for_missing" ]; then
- append_to_dep()
- {
- if ! grep -q ^$PACKAGE$'\t' $dep_db; then
- check_for_missing && echo $PACKAGE >> $tmp/dep
- else
- echo $PACKAGE >> $tmp/dep
- fi
- }
- unset plan_check_for_missing
- fi
- fi
- [ "$with_dev" ] && filter=with_dev
- [ "$with_wanted" ] && filter=with_wanted
- if [ "$filter" ]; then
- pkg_list=$(echo $pkg_list | $filter | sort -u)
- scan_pkg()
- {
- look_for_$look_for | $filter
- }
- else
- scan_pkg()
- {
- look_for_$look_for
- }
- fi
- touch $tmp/dep
- for PACKAGE in $pkg_list; do
- [ "$with_args" ] && append_to_dep
- scan_pkg
- done | tr ' ' '\n' | sort -u > $tmp/list
- [ "$look_for" = bdep ] && look_for=dep
- while [ -s $tmp/list ]; do
- PACKAGE=$(sed 1!d $tmp/list)
- sed 1d -i $tmp/list
- append_to_dep
- for pkg in $(scan_pkg); do
- if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
- echo $pkg >> $tmp/list
- fi
- done
- done
- if [ "$cooklist" ]; then
- mv $tmp/dep $tmp/cooklist
- else
- cat $tmp/dep | sort -u
- fi
- rm -f $tmp/dep $tmp/list
- sort -o $dep_db $dep_db
- sort -o $wan_db $wan_db
- if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
- grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt ||
- sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
- fi
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement