licensing: new hook that calls per package licensing.

BUG=chromium:197970 chromium:271832 chromium:207004 chromium:356539

TEST=emerge-x86-alex libc-bench
>>> Completed installing libc-bench-0.0.1-r8 into /build/x86-alex/tmp/portage/dev-util/libc-bench-0.0.1-r8/image/

/build/x86-alex/etc/portage/hooks/install/gen-package-licenses.sh disabled for now
File not built with -fstack-protector: /build/x86-alex/tmp/portage/dev-util/libc-bench-0.0.1-r8/image/usr/local/libc-bench/libc-bench

Change-Id: I40c124983ac3d12bb9bba2494b1f3a96c9ad6a70
Reviewed-on: https://chromium-review.googlesource.com/194191
Commit-Queue: Marc MERLIN <merlin@chromium.org>
Tested-by: Marc MERLIN <merlin@chromium.org>
Reviewed-by: Yu-Ju Hong <yjhong@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/hooks/install/gen-package-licenses.sh b/hooks/install/gen-package-licenses.sh
new file mode 100755
index 0000000..dedbd49
--- /dev/null
+++ b/hooks/install/gen-package-licenses.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# Copyright 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+generate_licensing()
+{
+  local PKG="${CATEGORY}/${PF}"
+
+  if [[ -z "${ENABLE_LICENSING}" ]]; then
+    ewarn "$0 disabled. export ENABLE_LICENSING=y to run"
+    return
+  fi
+
+  # This expands to something like
+  # /build/x86-alex/tmp/portage/dev-util/libc-bench-0.0.1-r6
+  # Run FEATURES='noclean' emerge-x86-alex libc-bench to prevent having the
+  # directory cleaned up if you are debugging.
+  einfo "Generating license for ${PKG} in ${PORTAGE_BUILDDIR}"
+  /mnt/host/source/chromite/licensing/licenses \
+      --hook "${PORTAGE_BUILDDIR}" || die "
+Failed Generating Licensing for ${PKG}
+Note that many/most open source licenses require that you distribute the license
+with the code, therefore you should fix this instead of overridding this check.
+
+Note too that you need to bundle the license with binary packages too, even
+if they are not part of ChromeOS proper since all packages are available as
+prebuilts to anyone and therefore must include a license.
+
+If you need help resolving the licensing error you just got, please have a
+look at
+http://www.chromium.org/chromium-os/licensing-for-chromiumos-package-owners
+"
+}
+
+generate_licensing