diff --git a/pkgs/README.rst b/pkgs/README.rst --- a/pkgs/README.rst +++ b/pkgs/README.rst @@ -47,6 +47,14 @@ Bower dependencies nix-shell pkgs/shell-generate.nix --command "bower2nix bower.json pkgs/bower-packages.nix" +Generate license data +===================== + +.. code:: shell + + nix-build pkgs/license-generate.nix -o result-license && cat result-license/licenses.json | python -m json.tool > rhodecode/config/licenses.json + + .. Links .. _RhodeCode Enterprise CE: https://code.rhodecode.com/rhodecode-enterprise-ce diff --git a/license.nix b/pkgs/license-generate.nix rename from license.nix rename to pkgs/license-generate.nix --- a/license.nix +++ b/pkgs/license-generate.nix @@ -2,9 +2,9 @@ # # Usage: # -# nix-build -I ~/dev license.nix -A result +# nix-build license.nix -o result-license # -# Afterwards ./result will contain the license information as JSON files. +# Afterwards ./result-license will contain the license information as JSON files. # # # Overview @@ -19,7 +19,7 @@ # dependencies. The results from step 1 are then limited to the ones which # are in this list. # -# The result is then available in ./result/license.json. +# The result is then available in ./result-license/license.json. # @@ -32,20 +32,20 @@ let # Enterprise as simple as possible, goal here is just to identify the runtime # dependencies. Ideally we could avoid building Enterprise at all and somehow # figure it out without calling into nix-store. - enterprise = import ./default.nix { + enterprise = import ../default.nix { doCheck = false; }; # For a given derivation, return the list of all dependencies drvToDependencies = drv: nixpkgs.lib.flatten [ - drv.nativeBuildInputs or [] - drv.propagatedNativeBuildInputs or [] + drv.buildInputs or [] + drv.propagatedBuildInputs or [] ]; # Transform the given derivation into the meta information which we need in # the resulting JSON files. drvToMeta = drv: { - name = drv.name or "UNNAMED"; + name = drv.name or drv; license = if drv ? meta.license then drv.meta.license else "UNKNOWN"; }; @@ -70,10 +70,8 @@ let rawStorePaths = nixpkgs.lib.removeSuffix "\n" ( builtins.readFile srcPath); storePaths = nixpkgs.lib.splitString "\n" rawStorePaths; - # TODO: johbo: Would be nice to use some sort of utility here to convert - # the path to a derivation name. storePathPrefix = ( - builtins.stringLength "/nix/store/zwy7aavnif9ayw30rya1k6xiacafzzl6-"); + builtins.stringLength "/nix/store/afafafafafafafafafafafafafafafaf-"); storePathToName = path: builtins.substring storePathPrefix (builtins.stringLength path) path; in (map storePathToName storePaths); @@ -147,6 +145,7 @@ in rec { cat > build/licenses.json < + % if isinstance(license_data, dict): + ${license_data.get('spdxId') or license_data.get('fullName')} + % else: + ${license_data} + % endif + +

${_('Licenses of Third Party Packages')}

@@ -7,24 +15,29 @@ RhodeCode Enterprise uses various third party packages, many of them provided by the open source community.

- % if c.opensource_licenses: - %for product, licenses in c.opensource_licenses.items(): - - - - - %endfor + % for lib in c.opensource_licenses: + + + + + % endfor
Product License
${product} - ${h.literal(', '.join([ - '%(name)s' % {'link':link, 'name':name} - if link else name - for name,link in licenses.items()]))} -
${lib["name"]} +
    + % if isinstance(lib["license"], list): + % for license_data in lib["license"]: +
  1. ${show_license(license_data)}
  2. + % endfor + % else: + <% license_data = lib["license"] %> +
  3. ${show_license(license_data)}
  4. + % endif +
+
% endif
diff --git a/rhodecode/tests/lib/test_utils.py b/rhodecode/tests/lib/test_utils.py --- a/rhodecode/tests/lib/test_utils.py +++ b/rhodecode/tests/lib/test_utils.py @@ -302,7 +302,7 @@ class TestPasswordChanged(object): assert result is True -class TestReadOpensourceLicenses(object): +class TestReadOpenSourceLicenses(object): def test_success(self): utils._license_cache = None json_data = ''' @@ -343,10 +343,14 @@ class TestReadOpensourceLicenses(object) def test_licenses_file_contains_no_unknown_licenses(self): utils._license_cache = None result = utils.read_opensource_licenses() - license_names = [] - for licenses in result.values(): - license_names.extend(licenses.keys()) - assert 'UNKNOWN' not in license_names + + for license_data in result: + if isinstance(license_data["license"], list): + for lic_data in license_data["license"]: + assert 'UNKNOWN' not in lic_data["fullName"] + else: + full_name = license_data.get("fullName") or license_data + assert 'UNKNOWN' not in full_name class TestMakeDbConfig(object):