User:Kalev/MozillaExtensionsDraft

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

XXX: The lines marked with XXX throughout the text are comments for the draft and to be removed in the final version.

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

XXX: Debian uses xul-ext- and openSUSE has an add-on repo with packages following mozilla-ext- naming. In Fedora, however, the existing packages have so far used mozilla-, 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// 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  expands to either %{_datadir}/mozilla/extensions/common or %{_libdir}/mozilla/extensions/common, depending on whether the package is noarch.

The macro  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. The symlinks need to be dropped to %{_datadir}/mozilla/extensions// directory.

The macro  takes care of creating the symlinks and registering the extension.

For an example, to register the extension for Mozilla and Thunderbird, the package should: %global _mozilla_extension_id \{12345678-9876-5432-abcd-123456789012\}
 * 1) The identifier for this extension, taken from install.rdf;
 * 2) used by the rpm macros for registering the extension.

%xpi_unpack -f myextension.xpi
 * 1) Unpack the .xpi in _mozilla_common_extdir:

%xpi_symlink -a %{firefox_app_id}
 * 1) Register for Firefox

%xpi_symlink -a %{thunderbird_app_id}
 * 1) Register for Thunderbird

Directory Ownership
Mozilla extension packages should Require mozilla-filesystem for common directories, but avoid depending on specific Mozilla applications. Each of the  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  directories they drop symlinks in, so rpm could track these directories and remove them when the extension package is uninstalled.

Sample Spec File
%global _mozilla_extension_id \{12345678-9876-5432-abcd-123456789012\}
 * 1) The identifier for this extension, taken from install.rdf;
 * 2) used by the rpm macros later on.

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

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

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

%description Awesome extension for Mozilla browsers.

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

%build %configure make %{?_smp_mflags}

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

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

%changelog - Initial RPM release
 * Wed Aug 10 2011 Kalev Lember  - 0.1-1

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

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

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