Bug 1318258 - Link libical and backend with libxul after binary components have been removed. r=aleth
authorPhilipp Kewisch <mozilla@kewis.ch>
Sat, 19 Nov 2016 20:54:33 +0100
changeset 20730 c957f6a30b9e7e1e544194de244da1d6a1cea083
parent 20729 6e7067af19ca683b85b5860776f803704baa0fdb
child 20731 09ec3012ff3d5d3ea84338b2d7707046046bdcbc
push id12550
push useraleth@instantbird.org
push dateSun, 20 Nov 2016 13:34:52 +0000
treeherdercomm-central@09ec3012ff3d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth
bugs1318258
Bug 1318258 - Link libical and backend with libxul after binary components have been removed. r=aleth MozReview-Commit-ID: 2fIa2mYxVTl
calendar/base/backend/calBackendLoader.js
calendar/base/backend/libical/build/libical-manifest
calendar/base/backend/libical/build/moz.build
calendar/base/backend/libical/calICSService.cpp
calendar/base/backend/libical/moz.build
calendar/libical/moz.build
calendar/libical/src/libical/moz.build
calendar/libical/src/moz.build
calendar/lightning/build/universal.mk
calendar/test/unit/xpcshell-libical.ini
--- a/calendar/base/backend/calBackendLoader.js
+++ b/calendar/base/backend/calBackendLoader.js
@@ -33,29 +33,49 @@ calBackendLoader.prototype = {
         // Nothing to do here, just need the entry so this is instanciated
     },
 
     loadBackend: function() {
         if (this.loaded) {
             return;
         }
 
-        let backend = Services.prefs.getBoolPref("calendar.icaljs") ? "icaljs" : "libical";
+        if (Services.prefs.getBoolPref("calendar.icaljs")) {
+            let contracts = [
+                "@mozilla.org/calendar/datetime;1",
+                "@mozilla.org/calendar/duration;1",
+                "@mozilla.org/calendar/ics-service;1",
+                "@mozilla.org/calendar/period;1",
+                "@mozilla.org/calendar/recurrence-rule;1"
+            ];
 
-        let uri = Services.io.getProtocolHandler("resource")
-                          .QueryInterface(Components.interfaces.nsIResProtocolHandler)
-                          .getSubstitution("calendar");
+            // Unregister libical components
+            let registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+            for (let contractId of contracts) {
+                let classobj = Components.classes[contractId];
+                let factory = Components.manager.getClassObject(classobj, Components.interfaces.nsIFactory);
+                let classId = registrar.contractIDToCID(contractId);
+                registrar.unregisterFactory(classId, factory);
+            }
 
-        let file = Services.io.getProtocolHandler("file")
-                           .QueryInterface(Components.interfaces.nsIFileProtocolHandler)
-                           .getFileFromURLSpec(uri.spec);
+            // Now load ical.js backend
+            let uri = Services.io.getProtocolHandler("resource")
+                              .QueryInterface(Components.interfaces.nsIResProtocolHandler)
+                              .getSubstitution("calendar");
 
-        file.append("components");
-        file.append(backend + "-manifest");
+            let file = Services.io.getProtocolHandler("file")
+                               .QueryInterface(Components.interfaces.nsIFileProtocolHandler)
+                               .getFileFromURLSpec(uri.spec);
+            file.append("components");
+            file.append("icaljs-manifest");
 
-        Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
-                  .autoRegister(file);
-        dump("[calBackendLoader] Using " + backend + " backend at " + file.path + "\n");
+            Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
+                      .autoRegister(file);
+            dump("[calBackendLoader] Using icaljs backend at " + file.path + "\n");
+        } else {
+            dump("[calBackendLoader] Using Thunderbird's builtin libical backend\n");
+        }
+
         this.loaded = true;
     }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([calBackendLoader]);
deleted file mode 100644
--- a/calendar/base/backend/libical/build/libical-manifest
+++ /dev/null
@@ -1,1 +0,0 @@
-#expand binary-component __SHARED_LIBRARY__
--- a/calendar/base/backend/libical/build/moz.build
+++ b/calendar/base/backend/libical/build/moz.build
@@ -2,22 +2,13 @@
 # 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 http://mozilla.org/MPL/2.0/.
 
 SOURCES += [
     'calBaseModule.cpp',
 ]
 
-XPCOMBinaryComponent('calbasecomps')
-
 LOCAL_INCLUDES += [
     '..'
 ]
 
-if CONFIG['JS_SHARED_LIBRARY']:
-    USE_LIBS += [
-        'js',
-    ]
-
-EXTRA_PP_COMPONENTS += ['libical-manifest']
-
-NO_COMPONENTS_MANIFEST = True
+FINAL_LIBRARY = "xul"
--- a/calendar/base/backend/libical/calICSService.cpp
+++ b/calendar/base/backend/libical/calICSService.cpp
@@ -106,18 +106,17 @@ calIcalProperty::SetValue(const nsACStri
     icalvalue_kind kind = icalproperty_kind_to_value_kind(icalproperty_isa(mProperty));
     if (kind == ICAL_TEXT_VALUE) {
         icalvalue *v = icalvalue_new_text(PromiseFlatCString(str).get());
         icalproperty_set_value(mProperty, v);
     } else if (kind == ICAL_X_VALUE) {
         icalvalue *v = icalvalue_new_x(PromiseFlatCString(str).get());
         icalproperty_set_value(mProperty, v);
     } else if (kind == ICAL_ATTACH_VALUE) {
-        const char *strdata = PromiseFlatCString(str).get();
-        icalattach *v = icalattach_new_from_data(strdata, nullptr, nullptr);
+        icalattach *v = icalattach_new_from_data(PromiseFlatCString(str).get(), nullptr, nullptr);
         icalproperty_set_attach(mProperty, v);
     } else {
         icalproperty_set_value_from_string(mProperty,
                                            PromiseFlatCString(str).get(),
                                            icalvalue_kind_to_string(kind));
     }
     return NS_OK;
 }
@@ -1272,18 +1271,17 @@ calICSService::ParseICS(const nsACString
     }
     NS_ADDREF(*component = comp);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 calICSService::ParserWorker::Run()
 {
-    icalcomponent *ical =
-        icalparser_parse_string(PromiseFlatCString(mString).get());
+    icalcomponent *ical = icalparser_parse_string(mString.get());
     nsresult status = NS_OK;
     calIIcalComponent *comp = nullptr;
 
     if (ical) {
         comp = new calIcalComponent(ical, nullptr, mProvider);
         if (!comp) {
             icalcomponent_free(ical);
             status = NS_ERROR_OUT_OF_MEMORY;
--- a/calendar/base/backend/libical/moz.build
+++ b/calendar/base/backend/libical/moz.build
@@ -12,9 +12,9 @@ SOURCES += [
     'calDuration.cpp',
     'calICSService.cpp',
     'calPeriod.cpp',
     'calRecurrenceRule.cpp',
     'calTimezone.cpp',
     'calUtils.cpp',
 ]
 
-FINAL_LIBRARY = 'calbasecomps'
+FINAL_LIBRARY = 'xul'
--- a/calendar/libical/moz.build
+++ b/calendar/libical/moz.build
@@ -1,12 +1,9 @@
 # vim: set filetype=python:
 # 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 http://mozilla.org/MPL/2.0/.
 
-DIRS += ['src']
-
-# We allow warnings for third-party code that can be updated from upstream.
-ALLOW_COMPILER_WARNINGS = True
+DIRS += ['src/libical']
 
 with Files('**'):
     BUG_COMPONENT = ('Calendar', 'Internal Components')
--- a/calendar/libical/src/libical/moz.build
+++ b/calendar/libical/src/libical/moz.build
@@ -26,13 +26,13 @@ SOURCES += [
     'pvl.c',
     'sspm.c',
     'vsnprintf.c',
 ]
 
 # We allow warnings for third-party code that can be updated from upstream.
 ALLOW_COMPILER_WARNINGS = True
 
-FINAL_LIBRARY = 'calbasecomps'
+FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '../..'
 ]
deleted file mode 100644
--- a/calendar/libical/src/moz.build
+++ /dev/null
@@ -1,7 +0,0 @@
-# vim: set filetype=python:
-# 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 http://mozilla.org/MPL/2.0/.
-
-DIRS += ['libical']
-
--- a/calendar/lightning/build/universal.mk
+++ b/calendar/lightning/build/universal.mk
@@ -23,30 +23,16 @@ XPI_PKGNAME = lightning-$(LIGHTNING_VERS
 
 STANDALONE_MAKEFILE := 1
 include $(TOPSRCDIR)/config/config.mk
 
 define unify_lightning
 mkdir -p $(DIST_UNI)/$1
 rm -rf $(DIST_UNI)/$1/$2*
 cp -R $(DIST_ARCH_1)/$1/$2 $(DIST_UNI)/$1
-grep -v binary-component $(DIST_ARCH_1)/$1/$2/components/libical-manifest > \
-	$(DIST_UNI)/$1/$2/components/libical-manifest || true
-platform=`$(PYTHON) $(TOPSRCDIR)/calendar/lightning/build/get-platform.py \
-	$(DIST_ARCH_1)/$1/$2`; \
-mkdir -p $(DIST_UNI)/$1/$2/components/$$platform; \
-mv $(DIST_UNI)/$1/$2/components/*.dylib \
-	$(DIST_UNI)/$1/$2/components/$$platform; \
-$(foreach dylib,$(wildcard $(DIST_ARCH_1)/$1/$2/components/*.dylib),echo binary-component $$platform/$(notdir $(dylib)) abi=$$platform >> $(DIST_UNI)/$1/$2/components/libical-manifest)
-platform=`$(PYTHON) $(TOPSRCDIR)/calendar/lightning/build/get-platform.py \
-	$(DIST_ARCH_2)/$1/$2`; \
-mkdir -p $(DIST_UNI)/$1/$2/components/$$platform; \
-cp $(DIST_ARCH_2)/$1/$2/components/*.dylib \
-	$(DIST_UNI)/$1/$2/components/$$platform; \
-$(foreach dylib,$(wildcard $(DIST_ARCH_2)/$1/$2/components/*.dylib),echo binary-component $$platform/$(notdir $(dylib)) abi=$$platform >> $(DIST_UNI)/$1/$2/components/libical-manifest)
 grep -v em:targetPlatform $(DIST_ARCH_1)/$1/$2/install.rdf > $(DIST_UNI)/$1/$2/install.rdf
 endef
 
 define unify_lightning_repackage
 $(call py_action,zip,-C $(DIST_UNI)/$1/$2 ../$(XPI_PKGNAME).xpi '*')
 endef
 
 postflight_all:
--- a/calendar/test/unit/xpcshell-libical.ini
+++ b/calendar/test/unit/xpcshell-libical.ini
@@ -1,9 +1,8 @@
 [DEFAULT]
 tags = calendar libical
 head = head_libical.js head_consts.js
 tail =
 dupe-manifest =
 support-files = data/**
-skip-if = true
 
 [include:xpcshell-shared.ini]