diff --git a/Makefile b/Makefile index 89e64655..554b09dc 100644 --- a/Makefile +++ b/Makefile @@ -81,10 +81,15 @@ endif # generate the changelog in this case, ensure that the current folder is # a git repository if git rev-parse HEAD && [ -e "/snap/$(SNAP_NAME)/current/usr/share/snappy/dpkg.yaml" ]; then \ + CHG_PARAMS=; \ + if [ -e /build/$(SNAP_NAME) ]; then \ + CHG_PARAMS=--launchpad; \ + fi; \ ./tools/generate-changelog.py \ "/snap/$(SNAP_NAME)/current" \ "$(DESTDIR)" \ - "$(SNAP_NAME)"; \ + "$(SNAP_NAME)" \ + $$CHG_PARAMS; \ else \ echo "WARNING: changelog will not be generated for this build"; \ fi diff --git a/tools/generate-changelog.py b/tools/generate-changelog.py index 8d9ff847..724c5221 100755 --- a/tools/generate-changelog.py +++ b/tools/generate-changelog.py @@ -74,12 +74,12 @@ def get_changelog_from_file(docs_d, pkg): else: raise FileNotFoundError("no supported changelog found for package " + pkg) -def get_changelog_from_url(pkg, new_v): +def get_changelog_from_url(pkg, new_v, on_lp): url = 'https://changelogs.ubuntu.com/changelogs/binary/' print(f"failed to resolve changelog for {pkg} locally, downloading from official repo") safe_name = package_name(pkg) - if safe_name not in pkg_allowed_list: + if not on_lp and safe_name not in pkg_allowed_list: raise Exception(f"{pkg} has not been whitelisted for changelog retrieval") if safe_name.startswith('lib'): @@ -97,14 +97,14 @@ def get_changelog_from_url(pkg, new_v): # Gets difference in changelog between old and new versions # Returns source package and the differences -def get_changes_for_version(docs_d, pkg, old_v, new_v, indent): +def get_changes_for_version(docs_d, pkg, old_v, new_v, indent, on_lp): # Try our best to resolve the changelog locally, if it does # not exist locally, then the package must be in the whitelisted # list of packages, when we try to resolve it from URL as backup. try: changelog = get_changelog_from_file(docs_d, pkg) except Exception: - changelog = get_changelog_from_url(pkg, new_v) + changelog = get_changelog_from_url(pkg, new_v, on_lp) source_pkg = changelog[0:changelog.find(' ')] @@ -138,7 +138,7 @@ def get_changes_for_version(docs_d, pkg, old_v, new_v, indent): # old_manifest_p: path to old manifest # new_manifest_p: path to newer manifest # docs_d: directory with docs from debian packages -def compare_manifests(old_manifest_p, new_manifest_p, docs_d): +def compare_manifests(old_manifest_p, new_manifest_p, docs_d, on_lp): old_packages = packages_from_manifest(old_manifest_p) new_packages = packages_from_manifest(new_manifest_p) changes = '' @@ -150,7 +150,7 @@ def compare_manifests(old_manifest_p, new_manifest_p, docs_d): old_v = old_packages[pkg] if old_v != new_v: src, pkg_change = get_changes_for_version(docs_d, pkg, old_v, - new_v, ' ') + new_v, ' ', on_lp) if src not in src_pkgs: src_pkgs[src] = SrcPkgData(old_v, new_v, pkg_change, [pkg]) else: @@ -214,6 +214,7 @@ def main(): parser.add_argument('old', metavar='previous-snap-root', help='Path to the root of the previous snap directory') parser.add_argument('new', metavar='new-snap-root', help='Path to the root of the new snap directory') parser.add_argument('name', help='The name of the snap') + parser.add_argument("--launchpad", action="store_true", help='Indicate we are building on LP, ignoring the whitelist') args = parser.parse_args() old_changelog = os.path.join(args.old, "usr", "share", "doc", "ChangeLog") @@ -242,7 +243,7 @@ def main(): changes += f'No detected changes for the {args.name} snap\n\n' changes += '[ Changes in primed packages ]\n\n' - pkg_changes = compare_manifests(old_manifest, new_manifest, docs_dir) + pkg_changes = compare_manifests(old_manifest, new_manifest, docs_dir, args.launchpad) if pkg_changes != '': changes += pkg_changes else: