Coder Social home page Coder Social logo

Comments (3)

mm1ke avatar mm1ke commented on August 16, 2024

Thank you, you're example and your script are really nice.

I've tried to adept my script and added ^(?!.*#).*(?<!-) in order to reduce the false positive.
Luckily in case of dev-util/bazel and also others it correctly removed them from the output. However i still have a problem with dev-util/strace (haven't checked others, but there might be more)

As far as i understand your code only outputs a result if a function is used and the inherit is missing.
However, i'm also checking the opposite and look if a ebuild inherits a eclass and doesn't use any function of it (which is then presented in the unused_eclasses report).
Now with the updated code i get a false positive for dev-utils/strace, as it finds flag-o-matic to be unused. (only in the versions 5.8, 5.9 and 9999)
For some reason the script doesn't find the filter-lfs-flags call in the ebuild. However, there is a comment after the call, which i think is the reason why it gets ignored. But as far as i understand the regex, comments should only be ignored when it's preceding a possible function.

I'll definitely look into it as it never the less would remove a lot of false positives. But maybe you have an idea why this might happen?

from gentoo-scripts.

telans avatar telans commented on August 16, 2024

I'll definitely look into it as it never the less would remove a lot of false positives. But maybe you have an idea why this might happen?

It was defintely the .* in the negative lookahead causing that. This should work: ^(?!#).*(?<!-)

from gentoo-scripts.

telans avatar telans commented on August 16, 2024

The script got a bit of an upgrade. Excluding all python and eapi7-ver eclasses, it seems to fix everything nicely. Doesn't check unused eclasses yet though...

#! /usr/bin/env bash

N=16
TREE="/home/telans/src/guru"
ECLASS_DIR="/home/telans/src/gentoo_local/eclass"

case "${1}" in
	"eapi") # EAPI checking
		for EBUILD in $(find "${TREE}" -mindepth 3 -maxdepth 3 -type f -name "*.ebuild"); do
			EAPI=4567; EAPI_CHOICE="${2}"
			! grep -qP "EAPI=[\"]?[${EAPI/${EAPI_CHOICE}/}][\"]?" "${EBUILD}" && echo "${EBUILD}"
		done;;
	"eclass") # Inherit checking
		inherit_eclass() {
			INHERIT=$(grep "^inherit" "${EBUILD}")
			INHERIT_NEW=$(echo "${INHERIT/inherit } ${ECLASS%.*}" | tr " " "\n" | sort | tr "\n" " " | sed -e 's:^:inherit :' -e 's: $::')
			if [ -n "${INHERIT}" ]; then
				sed -i "0,/^${INHERIT}/s//${INHERIT_NEW}/" "${EBUILD}"
			else
				echo "No current inherit for ${EBUILD}"
			fi
		}
		
		for ECLASS_PATH in $(find "${ECLASS_DIR}" -type f -name "*.eclass" -not -name "*python*.eclass" -not -name "*eapi7-ver.eclass" -not -name "*multilib*.eclass"); do
			[ -n "${2}" ] && ECLASS_PATH="${ECLASS_DIR}/${2}.eclass"
			ECLASS="${ECLASS_PATH##*/}"
			FUNC_LIST=$(sed -n 's:# @FUNCTION\: ::p' "${ECLASS_PATH}" | sed ':a;N;$!ba;s/\n/|/g')
			
			if [ -n "${FUNC_LIST}" ]; then
				for EBUILD in $(find "${TREE}" -mindepth 3 -maxdepth 3 -type f -name "*.ebuild"); do ((i=i%N)); ((i++==0)) && wait; ( \
					grep -qP "^(?!#).*[\s-\(](${FUNC_LIST})" "${EBUILD}" && \
						! grep -qP "^inherit.* ${ECLASS%.*}" "${EBUILD}" && \
						inherit_eclass && echo "Adding ${ECLASS} to ${EBUILD}"
					#grep -qP "^(?!#).*inherit.* ${ECLASS%.*}(?!-)" "${EBUILD}" && ! grep -qP "^(?!#).*[\s-\(](${FUNC_LIST})" "${EBUILD}" && echo "${ECLASS} ${EBUILD}" && MISSING="true"
				) &	done
			fi

			[ -n "${2}" ] && break
		done;;
esac

I imagine it spawns quite a few processes though

from gentoo-scripts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.