From Fedora Project Wiki
(added a note about Debian and openSUSE)
(rationale about naming)
Line 10: Line 10:


Rationale:
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.


== RPM macros ==
== RPM macros ==

Revision as of 12:47, 11 August 2011

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.

RPM macros

XXX: the verbatim rpm macros are here just for demonstration purposes and should be removed in the final text.

%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}

Installation Directories

Packages for Mozilla extensions should place unpacked files in %{_datadir}/mozilla/extensions/common/<extension>/ directory, where <extension> is the name of the package without the mozilla- prefix. Packages that contain architecture specific files should instead use %{_libdir}/mozilla/extensions/<extension>/ directory.

To register an extension for a Mozilla application, the package should drop into the application's extension directory symlinks which point to the actual files in the %{_datadir}/mozilla/extensions/common/<extension>/ directory.

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

# Firefox
mkdir -p $RPM_BUILD_ROOT%{_firefox_extdir}
ln -s %{_moz_ext_commondir}/{extension_name} $RPM_BUILD_ROOT%{_firefox_extdir}/{extension_id}
# Thunderbird
mkdir -p $RPM_BUILD_ROOT%{_thunderbird_extdir}
ln -s %{_moz_ext_commondir}/{extension_name} $RPM_BUILD_ROOT%{_thunderbird_extdir}/{extension_id}

Rationale:

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