puppetlabs/packaging — pull request #237 by MosesMendoza (2013-11-14 02:18:59+00:00)
Title: Restructure packaging repo data and lay foundation for librari-fying all functionality

This PR sets in place the future direction of the packaging repo as a library. The former all-encompassing top-level @build object is removed, as is the requirement of exporting all build instance variables as global rake variables. It introduces new modules, Pkg:, the top level module, Pkg::Config (where all configuration data lives), and Pkg::Util (where all utilities exist).

When a packaging task is invoked, the Pkg module is loaded, and the packaging libraries are added to the load path. The Pkg module loads the various libraries, and then loads various configuration data. Data loading is broken down into explicit areas of functionality, including loading from the default configs, loading default values, loading environment variables, etc. The awesome benefit here is much more clarity around what is happening and when, as well as greater ease of expansion and much safer change. All of the known parameters are moved into lib/packaging/config/params.rb, which includes data describing all of the known attributes, allowed environment variable overrides, various file renames, etc.

This PR lays the groundwork to be able to use the packaging repo outside of the context of `rake,` but rather as a library. At this point, doing `require packaging` will work to load the modules and configuration data. Pains were taken to sanely load expected defaults as if the packaging repo were inside a project (per current paradigm) while offering direction in the case that it is not. This includes the ability to set the packaging repo's project root to some external location/project, and then behave as if that's where operations were occurring. The 'tar' task functionality was split into a library under a rake task as an example for how we will proceed in migrating the other tasks. With this PR, a tarball can be produced by the packaging repo as a library external to a project, by doing:

```
$: << '.' ; require 'lib/packaging'
Pkg::Config.project_root = '/Users/moses/development/facter'
Pkg::Config.load_defaults
Pkg::Config.load_default_configs
Pkg::Config.load_versioning

tar = Pkg::Tar.new
tar.pkg!
```

Many of the utilities in 00_utils.rake have been moved out and into the Pkg::Util module - mostly those that were necessary to bootstrap the packaging repo and perform the tar library operations. All references to these utilities throughout the packaging repo have been updated to use their fully qualified counterparts, e.g. `Pkg::Util::Version.is_rc?` Likewise, all references to the @build object have been replaced with Pkg::Config.

Tar is the only task that has been migrated into a library. The others are ready to be tackled as time is available. Another benefit of this restructuring is that we can finally begin really testing our packaging automation as it should be tested.

In testing, after this PR, facter successfully ran through a jenkins uber_build, as well as various local builds. More extensive testing still needs to be done, particularly with the behavior of puppetdb/pe-puppetdb. It should be very closely reviewed. Changes to the top-level tasks are mostly superficial - e.g., swapping out @build with Pkg::Config. However, the new content in lib/ requires a close review, as well as a review of the higher-level load ordering and behavior.