From Fedora Project Wiki

< User:Kalev

Revision as of 13:18, 11 August 2011 by Kalev (talk | contribs) (moved rpm macros the the end)

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Warning.png
This page is a draft only
It is still under construction and content may change. Do not rely on the information on this page.

Draft for Packaging Mozilla Extensions

This is a draft for packaging extensions for Mozilla applications: Firefox, Thunderbird, Seamonkey, and others.

Naming

Packages of Mozilla extensions should take into account the upstream name of the extension. All Mozilla extensions MUST follow the scheme of mozilla-<extension>, where <extension> is the name of the extension. Examples include mozilla-adblockplus, mozilla-noscript.

XXX: Debian uses xul-ext-<extension> and openSUSE has an add-on repo with packages following mozilla-ext-<extension> naming. In Fedora, however, the existing packages have so far used mozilla-<extension>, and changing it now would create too much additional work.

Rationale: Following a common naming scheme makes it easier for users to locate the extensions. mozilla- prefix creates a visually separate group in package lists and makes it easier to browse through available extension packages. Using e.g. firefox- or thunderbird- prefix for some packages would create visual clutter in package lists and is therefore not recommended.

Installation Directories

Packages for Mozilla extensions should place unpacked files in %{_datadir}/mozilla/extensions/common/<package_name>/ directory. This is just a directory for keeping the files in and it's worth pointing out that Mozilla apps don't look in there on their own. The convenience macro %{_mozilla_common_extdir} expands to either %{_datadir}/mozilla/extensions/common or %{_libdir}/mozilla/extensions/common, depending on whether the package is noarch.

The macro %xpi_unpack -f <filename.xpi> takes care of unpacking the .xpi in the correct directory.

To register the extension for Mozilla applications, the extension packages use symlinks which point back to the directory in %{_mozilla_common_extdir}. The symlinks need to be dropped to %{_datadir}/mozilla/extensions/<app_guid>/ directory.

The macro %xpi_symlink -a <app_guid> registers the extension for the Mozilla application that uses <app_guid> identifier.

For an example, to register the extension for Mozilla and Thunderbird, the package should:

# The identifier for this extension, taken from install.rdf;
# used by the rpm macros for registering the extension.
%global _mozilla_extension_id \{12345678-9876-5432-abcd-123456789012\}
# Unpack the .xpi in _mozilla_common_extdir:
%xpi_unpack -f myextension.xpi
# Register for Firefox
%xpi_symlink -a %{firefox_app_id}
# Register for Thunderbird
%xpi_symlink -a %{thunderbird_app_id}

Directory Ownership

Mozilla extension packages should Require mozilla-filesystem for common directories, but avoid depending on specific Mozilla applications. Each of the %{_<appname>_extdir} directory where the extension package drops symlinks in, should also be owned by the same extension package.

XXX: What to do with %{_mozilla_common_extdir}? Is mozilla-filesystem going to own it or should the extension packages own it?

Sample %files section:

%files
%{_mozilla_common_extdir}/%{name}/
%{_firefox_extdir}/
%{_seamonkey_extdir}/
%{_thunderbird_extdir}/

Rationale: RPM needs to keep track of the installed directories, so that it could remove them on uninstall. When installing extensions, we drop symlinks to multiple application directories and want to avoid depending on these apps just to satisfy directory ownership requirements. Because of that, Mozilla extension packages need to own all the %{_<appname>_extdir} directories they drop symlinks in, so rpm could track these directories and remove them when the extension package is uninstalled.

Macros

Macro Usage
_mozilla_common_extdir Directory where extension packages should install actual files.
_chatzilla_extdir Chatzilla extension directory for dropping symlinks in
_firefox_extdir Firefox extension directory for dropping symlinks in
_seamonkey_extdir Seamonkey extension directory for dropping symlinks in
_sunbird_extdir Sunbird extension directory for dropping symlinks in
_thunderbird_extdir Thunderbird extension directory for dropping symlinks in

Sample Spec File

# The identifier for this extension, taken from install.rdf;
# used by the rpm macros later on.
%global _mozilla_extension_id \{12345678-9876-5432-abcd-123456789012\}

Name:           mozilla-awesomeextension
Version:        0.1
Release:        1%{?dist}
Summary:        Awesome extension for Mozilla browsers

License:        ...
URL:            ...
Source0:        ...

# XXX: do we want the rpm macros in mozilla-filesystem or somewhere else?
BuildRequires:  mozilla-filesystem
Requires:       mozilla-filesystem
BuildArch:      noarch

%description
Awesome extension for Mozilla browsers.

%prep
%setup -q -n awesomeextension-%{version}

%build
%configure
make %{?_smp_mflags}

%install
# Install the Mozilla extension
%xpi_unpack -f myawesomeextension-*.xpi
# Register the extension for the apps
%xpi_symlink -a %{firefox_app_id}
%xpi_symlink -a %{seamonkey_app_id}
%xpi_symlink -a %{thunderbird_app_id}

%files
%doc COPYING
%{_mozilla_common_extdir}/%{name}/
%{_firefox_extdir}/
%{_seamoney_extdir}/
%{_thunderbird_extdir}/

%changelog
* Wed Aug 10 2011 Kalev Lember <kalevlember@gmail.com> - 0.1-1
- Initial RPM release


Appendix A: RPM macros

XXX: the macros are here just for demonstration purposes and are to be removed in the final text. The macros are most likely to end up in mozilla-filesystem or redhat-rpm-config package.

%chatzilla_app_id   \{59c81df5-4b7a-477b-912d-4e0fdf64e5f2\}
%firefox_app_id     \{ec8030f7-c20a-464f-9b0e-13a3a9e97384\}
%seamonkey_app_id   \{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a\}
%sunbird_app_id     \{718e30fb-e89b-41dd-9da7-e25a45638b28\}
%thunderbird_app_id \{3550f703-e582-4d05-9a08-453d09bdfdc6\}

# If the package is noarch, put the files in /usr/share, otherwise use the libdir.
%_mozilla_extdir %( \
    if [ x"%{_target_cpu}" = x"noarch" ] || [ -n "%{?_mozilla_extension_force_noarch}" ]; then \
        echo "%{_datadir}/mozilla/extensions"; \
    else \
        echo "%{_libdir}/mozilla/extensions"; \
    fi \
)

%_mozilla_common_extdir %{_mozilla_extdir}/common
%_chatzilla_extdir      %{_mozilla_extdir}/%{chatzilla_app_id}
%_firefox_extdir        %{_mozilla_extdir}/%{firefox_app_id}
%_seamonkey_extdir      %{_mozilla_extdir}/%{seamonkey_app_id}
%_sunbird_extdir        %{_mozilla_extdir}/%{sunbird_app_id}
%_thunderbird_extdir    %{_mozilla_extdir}/%{thunderbird_app_id}

%xpi_unpack(f:n:) \
    %{!-f: %{error:Missing parameter -f <file> for macro xpi_unpack} exit 1} \
\
    %define xpi %{-f*} \
    %define extension_name %{-n*}%{!-n:%{name}} \
\
    mkdir -p "$RPM_BUILD_ROOT%{_mozilla_common_extdir}/%{extension_name}" \
    unzip "%xpi" -d "$RPM_BUILD_ROOT%{_mozilla_common_extdir}/%{extension_name}" \
%{nil}

%xpi_symlink(a:n:) \
    %{!-a: %{error:Missing parameter -a <app_id> for macro xpi_symlink} exit 1} \
    %{!?_mozilla_extension_id: %{error:Define _mozilla_extension_id before invoking macro xpi_symlink} exit 1 } \
\
    %define app_id %{-a*} \
    %define extension_name %{-n*}%{!-n:%{name}} \
\
    mkdir -p "$RPM_BUILD_ROOT%{_mozilla_extdir}/%{app_id}" \
    pushd "$RPM_BUILD_ROOT%{_mozilla_extdir}/%{app_id}" \
        ln -s "%{_mozilla_common_extdir}/%{extension_name}" "%{_mozilla_extension_id}" \
    popd \
%{nil}