licensing: support per package build time licensing generation.

Removed gather-licenses.sh process-pkg.py (unfinished prototypes) now
that they are replaced by this script.

- updated documentation in comments

- cleaned up yaml import as recommended by David.

- ebuild_dir and description were unused in PackageInfo. Removed them.

- build_source_tree is used to create a PackageInfo from an unpackage
  package (as opposed to the other way that queries an ebuild).

- _BuildInfo was added to retrieve package information from the
  build-info fork present at package build time when called as a hook.

- Licensing object can now be initialized without visibility on the
  template files (when run as a hook), which is fine since they are not
  used anyway.

- Per package license bits are now saved/loaded in
  /var/db/pkg/cat/name/license.yaml to match the location we get from
  portage when we install a prebuilt.

- HookPackageProcess is a new simpler way to enter/generate a license
  object and output a per package license bit in its build-info
  directory.

- If a licensing run realizes that per package licensing bits are
  missing, it creates them on the fly, but only if it is run under sudo
  (of course that also slows down image generation from <20sec to
  minutes).

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

TEST=(cr) (license-generation) merlin@polgara ~/trunk/chromite/licensing $ FEATURES='noclean' emerge-x86-alex libc-bench
Calculating dependencies... done!

>>> Emerging (1 of 1) dev-util/libc-bench-0.0.1-r8 from chromiumos for /build/x86-alex/
(...)
File not built with -Wl,-z,now: /build/x86-alex/tmp/portage/dev-util/libc-bench-0.0.1-r8/image/usr/local/libc-bench/libc-bench
Generating license for dev-util/libc-bench-0.0.1-r8 in /build/x86-alex/tmp/portage/dev-util/libc-bench-0.0.1-r8
13:34:39: INFO: Read licenses for dev-util/libc-bench-0.0.1-r8: MIT
13:34:39: INFO: dev-util/libc-bench-0.0.1-r8: can't use MIT, will scan source code for copyright
13:34:39: INFO: License(s) for dev-util/libc-bench-0.0.1-r8: COPYRIGHT
13:34:39: INFO: Adding License /build/x86-alex/tmp/portage/dev-util/libc-bench-0.0.1-r8/work/libc-bench/COPYRIGHT (UTF-8)
strip: i686-pc-linux-gnu-strip --strip-unneeded -R .comment -R .GCC.command.line
(...)
>>> Auto-cleaning packages...

>>> Using system located in ROOT tree /build/x86-alex/

>>> No outdated packages were found on your system.
(cr) (license-generation) merlin@polgara ~/trunk/chromite/licensing $ qtbz2 -x -O  /build/x86-alex/packages/dev-util/libc-bench-0.0.1-r8.tbz2 | qxpak -x -O - license.yaml
- [category, !!python/unicode 'dev-util']
- [licensing_failed, false]
- [name, !!python/unicode 'libc-bench']
- - ebuild_license_names
  - [!!python/unicode 'MIT']
- - homepages
  - [!!python/unicode 'http://www.etalabs.net/libc-bench.html', !!python/unicode 'http://git.musl-libc.org/cgit/libc-bench/']
- [ebuild_path, null]
- [need_copyright_attribution, true]
- - license_names
  - !!set {}
- [version, !!python/unicode '0.0.1']
- [board, /build/x86-alex]
- [skip, false]
- [scan_source_for_licenses, true]
- - license_text_scanned
  - ["Scanned Source License COPYRIGHT:\n\nlibc-bench, a performance and memory usage\
      \ benchmark for comparing\nlibc implementations\n\nCopyright \xA9 2011 Rich\
      \ Felker\n\nPermission is hereby granted, free of charge, to any person obtaining\n\
      a copy of this software and associated documentation files (the\n\"Software\"\
      ), to deal in the Software without restriction, including\nwithout limitation\
      \ the rights to use, copy, modify, merge, publish,\ndistribute, sublicense,\
      \ and/or sell copies of the Software, and to\npermit persons to whom the Software\
      \ is furnished to do so, subject to\nthe following conditions:\n\nThe above\
      \ copyright notice and this permission notice shall be\nincluded in all copies\
      \ or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS\
      \ IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT\
      \ LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE\
      \ AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\
      \ LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF\
      \ CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\
      SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"]
- [build_source_tree, /build/x86-alex/tmp/portage/dev-util/libc-bench-0.0.1-r8]
- [revision, '8']
(cr) (license-generation) merlin@polgara ~/trunk/chromite/licensing $ ls -l /build/x86-alex/var/db/pkg/dev-util/libc-bench-0.0.1-r8/license.yaml
-rw-r--r-- 1 root root 1983 Apr 10 13:34 /build/x86-alex/var/db/pkg/dev-util/libc-bench-0.0.1-r8/license.yaml

Change-Id: I787edaaf63c848e0e2dd76dcd687c8358c92152a
Reviewed-on: https://chromium-review.googlesource.com/194178
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Marc MERLIN <merlin@chromium.org>
Tested-by: Marc MERLIN <merlin@chromium.org>
3 files changed