author Jan-Erik Rediger <>
Mon, 17 Jan 2022 16:26:33 +0000
changeset 604713 352dec7d8c1349d30c72fdefea648d47ad7cab08
parent 600576 5fa7ec49d934e5194282364226d23d593b75f455
permissions -rw-r--r--
Bug 1750544 - Upgrade to Glean v43.0.2. r=chutten Differential Revision:

#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

import json

import buildconfig
import mozpack.path as mozpath

def get_last_modified(full_path_to_remote_settings_dump_file):
    Get the last_modified for the given file name.
    - File must exist
    - Must be a JSON dictionary with a data list, e.g. `{"data": []}`
    - Every element in `data` should contain a "last_modified" key.
    - The first element must have the highest "last_modified" value.
    with open(full_path_to_remote_settings_dump_file, "r") as f:
        records = json.load(f)["data"]
        assert isinstance(records, list)

    # Various RemoteSettings client code default to 0 when the set of
    # records is empty (-1 is reserved for failures / non-existing files).
    last_modified = 0
    if records:
        # Records in dumps are sorted by last_modified, newest first:
        # # NOQA: E501
        last_modified = records[0]["last_modified"]

    assert isinstance(last_modified, int)
    return last_modified

def main(output):
    Generates a JSON file that maps "bucket/collection" to the last_modified
    value within.

    Returns a set of the file locations of the recorded RemoteSettings dumps,
    so that the build backend can invoke this script again when needed.

    The validity of the JSON file is verified through unit tests at
    # The following build targets currently use RemoteSettings dumps:
    # Firefox             # NOQA: E501
    # Firefox for Android   # NOQA: E501
    # Thunderbird               # NOQA: E501
    # SeaMonkey                # NOQA: E501
    assert buildconfig.substs["MOZ_BUILD_APP"] in (

    remotesettings_dumps = {}

    # For simplicity, let's hardcode the path of the RemoteSettings dumps whose
    # last_modified date is looked up.
    # TODO bug 1719560: Replace hardcoded values with something more generic.
    if buildconfig.substs["MOZ_BUILD_APP"] != "mobile/android":
        # Until bug 1639050 is resolved, the dump isn't packaged with Android.
        remotesettings_dumps["blocklists/addons-bloomfilters"] = mozpath.join(
    if buildconfig.substs["MOZ_BUILD_APP"] == "browser":
        # This is only packaged with browser.
        remotesettings_dumps["main/search-config"] = mozpath.join(
    if buildconfig.substs["MOZ_BUILD_APP"] == "comm/mail":
        # This is only packaged with Thunderbird.
        remotesettings_dumps["main/search-config"] = mozpath.join(

    output_dict = {}
    input_files = set()

    for key, input_file in remotesettings_dumps.items():
        output_dict[key] = get_last_modified(input_file)

    json.dump(output_dict, output, sort_keys=True)
    return input_files