[gentoo-dev] RFC: intel-sdp.eclass check user license

2012-11-27 Thread justin
Hi,

next patch for intel-sdp.eclass

Problem:
If the intel compiler are installed but no valid license is present,
several buildsystem including cmake generate sandbox violations.

Solution:
Do not let the user install the package without valid license. Its
useless anyway without.
Realized in two checks, first in pkg_pretend check for simple existence
of a license file; second check in pkg_postinst calls for version
informations from compiler (runtime test).
First test is deadly; Second not, because user already intervened
manually to bypass first check and we consider this as
he-knows-what-he-is-doing.

Thanks justin

+# @ECLASS-FUNCTION: big-warning
+# @INTERNAL
+# warn user that we really require a license
+big-warning() {
+case ${1} in
+			pre-check )
+echo 
+ewarn License file not found!
+;;
+test-failed )
+echo
+ewarn Function test failed. Most probably due to an invalid license.
+ewarn This means you already tried to bypass the license check once.
+;;
+esac
+
+echo 
+ewarn Make sure you have recieved the an Intel license.
+ewarn To receive a non-commercial license, you need to register at:
+ewarn http://software.intel.com/en-us/articles/non-commercial-software-development/;
+ewarn Install the license file into ${INTEL_SDP_EDIR}/licenses/
+
+case ${1} in
+pre-check )
+ewarn before proceeding with installation of ${P}
+echo 
+;;
+* )
+echo 
+;;
+esac
+}
+
+# @ECLASS-FUNCTION: _version_test
+# @INTERNAL
+# Testing for valid license by asking for version information of the compiler
+_version_test() {
+local _comp _comp_full _arch _file _warn
+case ${PN} in
+ifc )
+debug-print Testing ifort
+_comp=ifort
+;;
+icc )
+debug-print Testing icc
+_comp=icc
+;;
+*)
+die ${PN} is not supported for testing
+;;
+esac
+
+for _arch in ${INTEL_ARCH}; do
+case ${EBUILD_PHASE} in
+install )
+_comp_full=${ED}/${INTEL_SDP_DIR}/bin/${_arch}/${_comp}
+;;
+postinst )
+_comp_full=${INTEL_SDP_EDIR}/bin/${_arch}/${_comp}
+;;
+* )
+ewarn Compile test not supported in ${EBUILD_PHASE}
+continue
+;;
+esac
+
+debug-print LD_LIBRARY_PATH=\${INTEL_SDP_EDIR}/bin/${_arch}/\ \${_comp_full}\ -V
+
+LD_LIBRARY_PATH=${INTEL_SDP_EDIR}/bin/${_arch}/ ${_comp_full} -V /dev/null
+[[ $? -ne 0 ]]  _warn=yes
+done
+[[ ${_warn} == yes ]]  big-warning test-failed
+}
+
+# @ECLASS-FUNCTION: run-test
+# @INTERNAL
+# Test if installed compiler is working
+run-test() {
+case ${PN} in
+ifc | icc )
+_version_test ;;
+* )
+debug-print No test available for ${PN}
+;;
+esac
+}
+
+# @ECLASS-FUNCTION: intel-sdp_pkg_pretend
+# @DESCRIPTION:
+# * Check that the user has a (valid) license file before going on.
+#
+# * Check for space requirements being fullfilled
+intel-sdp_pkg_pretend() {
+	local _warn=1 _dirs i _ret arch a p
+
+	: ${CHECKREQS_DISK_BUILD:=256M}
+	check-reqs_pkg_pretend
+
+	_dirs=(
+		${INTEL_SDP_EDIR}/licenses
+		${INTEL_SDP_EDIR}/Licenses
+		${EPREFIX}/opt/intel/licenses
+		)
+	for ((i = 0; i  ${#_dirs[@]}; i++)); do
+		ebegin Checking for a license in: ${_dirs[$i]}
+		[[ $( ls ${_dirs[$i]}/*lic 2/dev/null ) ]]; _ret=$?
+		eend ${_ret}
+		if [[ ${_ret} == 0 ]]; then
+			_warn=${_ret}
+			break
+		fi
+	done
+	if [[ ${_warn} == 1 ]]; then
+		big-warning pre-check
+		die Could not find license file
+	fi
+}

@@ -238,8 +390,12 @@ intel-sdp_pkg_postinst() {
 		echo  ${INTEL_SDP_DB} \
 			:${r%-${_INTEL_PV4}*}-${_INTEL_PV4}:${r}:${INTEL_SDP_EDIR}:${l}:
 	done
+	run-test
 }


signature.asc
Description: OpenPGP digital signature


Re: [gentoo-dev] RFC: intel-sdp.eclass check user license

2012-11-27 Thread Mike Frysinger
On Tuesday 27 November 2012 07:26:50 justin wrote:
 next patch for intel-sdp.eclass

your code has a lot of whitespace damage (leading spaces instead of tabs).  
you should fix that up.

 +# @ECLASS-FUNCTION: big-warning
 +# @INTERNAL
 +# warn user that we really require a license

there should be @DESCRIPTION line before the description

you can run /usr/portage/app-portage/eclass-manpages/files/eclass-to-manpage.sh 
against the eclass to check for errors.

also, just because they're @INTERNAL doesn't mean short names like big-
warning and run-test are OK.  your eclass is putting funcs into global 
scope which can collide with other eclasses/ebuilds and possibly things in 
$PATH (dejagnu provides a standard program called `runtest`).  best to give 
them a unique prefix like _isdp_big_warning().

 +_version_test() {
 +local _comp _comp_full _arch _file _warn

you've declared the vars all local.  there's no need for the _ prefix.

 +   for ((i = 0; i  ${#_dirs[@]}; i++)); do

for dir in ${dirs[@]} ; do

that avoids indexing dirs constantly
-mike


signature.asc
Description: This is a digitally signed message part.


Re: [gentoo-dev] RFC: intel-sdp.eclass check user license

2012-11-27 Thread justin
On 28/11/12 00:04, Mike Frysinger wrote:
 On Tuesday 27 November 2012 07:26:50 justin wrote:
 next patch for intel-sdp.eclass
 
 your code has a lot of whitespace damage (leading spaces instead of tabs).  
 you should fix that up.

I am sorry for that and we fix it up. Did some writing on mac where the
editor did magic tab - whitespace conversion.

 
 +# @ECLASS-FUNCTION: big-warning
 +# @INTERNAL
 +# warn user that we really require a license
 
 there should be @DESCRIPTION line before the description
 

I have overlooked that. Fixed now.

 you can run 
 /usr/portage/app-portage/eclass-manpages/files/eclass-to-manpage.sh 
 against the eclass to check for errors.

Didn't know, that you can run it on single files. Nice to know, Thanks.

 
 also, just because they're @INTERNAL doesn't mean short names like big-
 warning and run-test are OK.  your eclass is putting funcs into global 
 scope which can collide with other eclasses/ebuilds and possibly things in 
 $PATH (dejagnu provides a standard program called `runtest`).  best to give 
 them a unique prefix like _isdp_big_warning().

You are right. I will prefix and name them correctly.

 
 +_version_test() {
 +local _comp _comp_full _arch _file _warn
 
 you've declared the vars all local.  there's no need for the _ prefix.
 
 +   for ((i = 0; i  ${#_dirs[@]}; i++)); do
 
 for dir in ${dirs[@]} ; do

I can't remember what was my problem, but somehow I didn't manage to
iterate properly over the array. So I looked that up and found this syntax.
But maybe something else was wrong too.


 
 that avoids indexing dirs constantly
 -mike
 

thanks for your comments mike,

Jusitn



signature.asc
Description: OpenPGP digital signature