Skip to content

Commit

Permalink
update_engine: Remove dependency on libupdate_engine from the client.
Browse files Browse the repository at this point in the history
The update_engine_client is a very small DBus client that only
depends on a single utils:: function from the update_engine daemon
codebase. Because of this, it was forced to be linked against many
libraries that it didn't use.

This patch factors out this glib helper function to a new
glib_utils.{cc,h} file and includes only that in the
update_engine_client binary.

BUG=chromium:396440
TEST=FEATURES=test emerge-link update_engine

Change-Id: Icf8d8b3c6ebd22cdb39e6674fb3d9071071ec941
Reviewed-on: https://chromium-review.googlesource.com/209472
Reviewed-by: David Zeuthen <[email protected]>
Tested-by: Alex Deymo <[email protected]>
Commit-Queue: Alex Vakulenko <[email protected]>
  • Loading branch information
deymo authored and chrome-internal-fetch committed Jul 25, 2014
1 parent 44cab30 commit 44666f9
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 31 deletions.
1 change: 1 addition & 0 deletions chrome_browser_proxy_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <google/protobuf/stubs/common.h>

#include "update_engine/dbus_constants.h"
#include "update_engine/glib_utils.h"
#include "update_engine/utils.h"

namespace chromeos_update_engine {
Expand Down
1 change: 1 addition & 0 deletions filesystem_copier_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <gio/gunixoutputstream.h>
#include <glib.h>

#include "update_engine/glib_utils.h"
#include "update_engine/hardware_interface.h"
#include "update_engine/subprocess.h"
#include "update_engine/system_state.h"
Expand Down
28 changes: 28 additions & 0 deletions glib_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "update_engine/glib_utils.h"

#include <base/strings/stringprintf.h>

using std::string;

namespace chromeos_update_engine {
namespace utils {

string GetAndFreeGError(GError** error) {
if (!*error) {
return "Unknown GLib error.";
}
string message =
base::StringPrintf("GError(%d): %s",
(*error)->code,
(*error)->message ? (*error)->message : "(unknown)");
g_error_free(*error);
*error = NULL;
return message;
}

} // namespace utils
} // namespace chromeos_update_engine
22 changes: 22 additions & 0 deletions glib_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UPDATE_ENGINE_GLIB_UTILS_H_
#define UPDATE_ENGINE_GLIB_UTILS_H_

#include <string>

#include <glib.h>

namespace chromeos_update_engine {
namespace utils {

// Returns the error message, if any, from a GError pointer. Frees the GError
// object and resets error to NULL.
std::string GetAndFreeGError(GError** error);

} // namespace utils
} // namespace chromeos_update_engine

#endif // UPDATE_ENGINE_GLIB_UTILS_H_
3 changes: 2 additions & 1 deletion main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
#include <gflags/gflags.h>
#include <glib.h>
#include <metrics/metrics_library.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "update_engine/certificate_checker.h"
#include "update_engine/dbus_constants.h"
#include "update_engine/dbus_service.h"
#include "update_engine/dbus_wrapper_interface.h"
#include "update_engine/glib_utils.h"
#include "update_engine/real_system_state.h"
#include "update_engine/subprocess.h"
#include "update_engine/terminator.h"
Expand Down
1 change: 1 addition & 0 deletions p2p_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <base/logging.h>
#include <base/strings/stringprintf.h>

#include "update_engine/glib_utils.h"
#include "update_engine/utils.h"

using base::FilePath;
Expand Down
2 changes: 1 addition & 1 deletion subprocess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>

#include "update_engine/utils.h"
#include "update_engine/glib_utils.h"

using std::shared_ptr;
using std::string;
Expand Down
3 changes: 2 additions & 1 deletion update_attempter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <memory>
#include <set>
#include <string>
#include <vector>
#include <utility>
#include <vector>

#include <base/file_util.h>
#include <base/logging.h>
Expand All @@ -30,6 +30,7 @@
#include "update_engine/dbus_wrapper_interface.h"
#include "update_engine/download_action.h"
#include "update_engine/filesystem_copier_action.h"
#include "update_engine/glib_utils.h"
#include "update_engine/hardware_interface.h"
#include "update_engine/libcurl_http_fetcher.h"
#include "update_engine/metrics.h"
Expand Down
34 changes: 30 additions & 4 deletions update_engine.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
'type': 'static_library',
'dependencies': [
'update_metadata-protos',
'update_engine-dbus-client',
'update_engine-dbus-server',
],
'variables': {
'exported_deps': [
Expand Down Expand Up @@ -152,6 +150,7 @@
'file_descriptor.cc',
'file_writer.cc',
'filesystem_copier_action.cc',
'glib_utils.cc',
'hardware.cc',
'http_common.cc',
'http_fetcher.cc',
Expand Down Expand Up @@ -199,7 +198,10 @@
{
'target_name': 'update_engine',
'type': 'executable',
'dependencies': ['libupdate_engine'],
'dependencies': [
'libupdate_engine',
'update_engine-dbus-server',
],
'sources': [
'main.cc',
]
Expand All @@ -208,8 +210,32 @@
{
'target_name': 'update_engine_client',
'type': 'executable',
'dependencies': ['libupdate_engine'],
'dependencies': [
'update_engine-dbus-client',
],
'variables': {
'exported_deps': [
'dbus-1',
'dbus-glib-1',
'glib-2.0',
'gthread-2.0',
'libchrome-<(libbase_ver)',
'libchromeos-<(libbase_ver)',
],
'deps': ['<@(exported_deps)'],
},
'link_settings': {
'variables': {
'deps': [
'<@(exported_deps)',
],
},
'libraries': [
'-lgflags',
],
},
'sources': [
'glib_utils.cc',
'update_engine_client.cc',
]
},
Expand Down
11 changes: 5 additions & 6 deletions update_engine_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@

#include <string>

#include <base/logging.h>
#include <chromeos/dbus/service_constants.h>
#include <dbus/dbus.h>
#include <gflags/gflags.h>
#include <glib.h>

#include "update_engine/dbus_constants.h"
#include "update_engine/subprocess.h"
#include "update_engine/utils.h"
#include "update_engine/glib_utils.h"

extern "C" {
#include "update_engine/update_engine.dbusclient.h"
}

using chromeos_update_engine::kUpdateEngineServiceName;
using chromeos_update_engine::kUpdateEngineServicePath;
using chromeos_update_engine::kUpdateEngineServiceInterface;
using chromeos_update_engine::AttemptUpdateFlags;
using chromeos_update_engine::kAttemptUpdateFlagNonInteractive;
using chromeos_update_engine::kUpdateEngineServiceInterface;
using chromeos_update_engine::kUpdateEngineServiceName;
using chromeos_update_engine::kUpdateEngineServicePath;
using chromeos_update_engine::utils::GetAndFreeGError;
using std::string;

Expand Down Expand Up @@ -535,7 +535,6 @@ int main(int argc, char** argv) {
// Boilerplate init commands.
g_type_init();
dbus_threads_init_default();
chromeos_update_engine::Subprocess::Init();
google::ParseCommandLineFlags(&argc, &argv, true);

// Update the status if requested.
Expand Down
2 changes: 1 addition & 1 deletion update_manager/real_shill_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <base/strings/stringprintf.h>
#include <chromeos/dbus/service_constants.h>

#include "update_engine/utils.h"
#include "update_engine/glib_utils.h"

using std::string;

Expand Down
13 changes: 0 additions & 13 deletions utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,19 +773,6 @@ bool GetBootloader(BootLoader* out_bootloader) {
return true;
}

string GetAndFreeGError(GError** error) {
if (!*error) {
return "Unknown GLib error.";
}
string message =
base::StringPrintf("GError(%d): %s",
(*error)->code,
(*error)->message ? (*error)->message : "(unknown)");
g_error_free(*error);
*error = NULL;
return message;
}

namespace {
// Do the actual trigger. We do it as a main-loop callback to (try to) get a
// consistent stack trace.
Expand Down
4 changes: 0 additions & 4 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ enum BootLoader {
// param. Returns true on success.
bool GetBootloader(BootLoader* out_bootloader);

// Returns the error message, if any, from a GError pointer. Frees the GError
// object and resets error to NULL.
std::string GetAndFreeGError(GError** error);

// Schedules a Main Loop callback to trigger the crash reporter to perform an
// upload as if this process had crashed.
void ScheduleCrashReporterUpload();
Expand Down

0 comments on commit 44666f9

Please sign in to comment.