update engine: 32- and 64-bit compile
Review URL: http://codereview.chromium.org/1599029
diff --git a/SConstruct b/SConstruct
index 8854abc..41dc94f 100644
--- a/SConstruct
+++ b/SConstruct
@@ -40,8 +40,23 @@
suffix = '.pb.cc')
env = Environment()
+for key in Split('CC CXX AR RANLIB LD NM'):
+ value = os.environ.get(key)
+ if value != None:
+ env[key] = value
+for key in Split('CFLAGS CCFLAGS CPPPATH LIBPATH'):
+ value = os.environ.get(key)
+ if value != None:
+ env[key] = Split(value)
+
+for key in Split('PKG_CONFIG_LIBDIR PKG_CONFIG_PATH SYSROOT'):
+ if os.environ.has_key(key):
+ env['ENV'][key] = os.environ[key]
+
+
env['CCFLAGS'] = ' '.join("""-g
-fno-exceptions
+ -fno-strict-aliasing
-Wall
-Werror
-Wclobbered
@@ -51,10 +66,13 @@
-Wsign-compare
-Wtype-limits
-Wuninitialized
+ -D__STDC_FORMAT_MACROS=1
-D_FILE_OFFSET_BITS=64
-I/usr/include/libxml2""".split());
+env['CCFLAGS'] += (' ' + ' '.join(env['CFLAGS']))
env['LIBS'] = Split("""base
+ bz2
curl
gflags
glib-2.0
@@ -123,7 +141,6 @@
extent_mapper_unittest.cc
extent_writer_unittest.cc
file_writer_unittest.cc
- filesystem_copier_action_unittest.cc
filesystem_iterator_unittest.cc
graph_utils_unittest.cc
http_fetcher_unittest.cc
diff --git a/action_processor.cc b/action_processor.cc
index d58b5ee..e52cbcd 100644
--- a/action_processor.cc
+++ b/action_processor.cc
@@ -4,7 +4,7 @@
#include "update_engine/action_processor.h"
#include <string>
-#include "chromeos/obsolete_logging.h"
+#include "base/logging.h"
#include "update_engine/action.h"
using std::string;
diff --git a/bzip.cc b/bzip.cc
index 3ac15d8..833d273 100644
--- a/bzip.cc
+++ b/bzip.cc
@@ -20,9 +20,9 @@
// Returns true on success.
// Use one of BzipBuffToBuff*ompress as the template parameter to BzipData().
int BzipBuffToBuffDecompress(char* out,
- size_t* out_length,
+ uint32_t* out_length,
const char* in,
- size_t in_length) {
+ uint32_t in_length) {
return BZ2_bzBuffToBuffDecompress(out,
out_length,
const_cast<char*>(in),
@@ -32,9 +32,9 @@
}
int BzipBuffToBuffCompress(char* out,
- size_t* out_length,
+ uint32_t* out_length,
const char* in,
- size_t in_length) {
+ uint32_t in_length) {
return BZ2_bzBuffToBuffCompress(out,
out_length,
const_cast<char*>(in),
@@ -45,11 +45,11 @@
}
template<int F(char* out,
- size_t* out_length,
+ uint32_t* out_length,
const char* in,
- size_t in_length)>
+ uint32_t in_length)>
bool BzipData(const char* const in,
- const size_t in_size,
+ const int32_t in_size,
vector<char>* const out) {
TEST_AND_RETURN_FALSE(out);
out->clear();
@@ -61,7 +61,7 @@
out->resize(buf_size);
for (;;) {
- size_t data_size = buf_size;
+ uint32_t data_size = buf_size;
int rc = F(&(*out)[0], &data_size, in, in_size);
TEST_AND_RETURN_FALSE(rc == BZ_OUTBUFF_FULL || rc == BZ_OK);
if (rc == BZ_OK) {
@@ -79,7 +79,9 @@
} // namespace {}
bool BzipDecompress(const std::vector<char>& in, std::vector<char>* out) {
- return BzipData<BzipBuffToBuffDecompress>(&in[0], in.size(), out);
+ return BzipData<BzipBuffToBuffDecompress>(&in[0],
+ static_cast<int32_t>(in.size()),
+ out);
}
bool BzipCompress(const std::vector<char>& in, std::vector<char>* out) {
@@ -88,7 +90,7 @@
namespace {
template<bool F(const char* const in,
- const size_t in_size,
+ const int32_t in_size,
vector<char>* const out)>
bool BzipString(const std::string& str,
std::vector<char>* out) {
diff --git a/decompressing_file_writer_unittest.cc b/decompressing_file_writer_unittest.cc
index 1d689e7..c1666db 100644
--- a/decompressing_file_writer_unittest.cc
+++ b/decompressing_file_writer_unittest.cc
@@ -75,7 +75,8 @@
uncompressed_file.Close();
// compress the file
- system((string("cat ") + kPath + " | gzip > " + kPathgz).c_str());
+ EXPECT_EQ(0,
+ system((string("cat ") + kPath + " | gzip > " + kPathgz).c_str()));
// Now read the compressed file and put it into a DecompressingFileWriter
MockFileWriter mock_file_writer;
diff --git a/delta_diff_generator.cc b/delta_diff_generator.cc
index 4181057..74bcaa0 100644
--- a/delta_diff_generator.cc
+++ b/delta_diff_generator.cc
@@ -691,7 +691,6 @@
vector<Block> blocks(min(old_image_stbuf.st_size / kBlockSize,
new_image_stbuf.st_size / kBlockSize));
- LOG(INFO) << "blocks (orig): " << (uint32)(&blocks);
LOG(INFO) << "w:" << blocks[4097].writer;
LOG(INFO) << "invalid: " << Vertex::kInvalidIndex;
LOG(INFO) << "len: " << blocks.size();
@@ -826,7 +825,7 @@
// Write header
TEST_AND_RETURN_FALSE(writer.Write(kDeltaMagic, strlen(kDeltaMagic)) ==
- strlen(kDeltaMagic));
+ static_cast<ssize_t>(strlen(kDeltaMagic)));
// Write version number
TEST_AND_RETURN_FALSE(WriteUint64AsBigEndian(&writer, kVersionNumber));
diff --git a/extent_writer.h b/extent_writer.h
index cbb62fe..b250bab 100644
--- a/extent_writer.h
+++ b/extent_writer.h
@@ -29,7 +29,7 @@
// Returns true on success.
virtual bool Init(int fd,
const std::vector<Extent>& extents,
- size_t block_size) = 0;
+ uint32_t block_size) = 0;
// Returns true on success.
virtual bool Write(const void* bytes, size_t count) = 0;
@@ -57,7 +57,7 @@
next_extent_index_(0) {}
~DirectExtentWriter() {}
- bool Init(int fd, const std::vector<Extent>& extents, size_t block_size) {
+ bool Init(int fd, const std::vector<Extent>& extents, uint32_t block_size) {
fd_ = fd;
block_size_ = block_size;
extents_ = extents;
@@ -92,7 +92,7 @@
bytes_written_mod_block_size_(0) {}
~ZeroPadExtentWriter() {}
- bool Init(int fd, const std::vector<Extent>& extents, size_t block_size) {
+ bool Init(int fd, const std::vector<Extent>& extents, uint32_t block_size) {
block_size_ = block_size;
return underlying_extent_writer_->Init(fd, extents, block_size);
}
diff --git a/gzip.cc b/gzip.cc
index 9643724..5fbd043 100644
--- a/gzip.cc
+++ b/gzip.cc
@@ -93,7 +93,7 @@
Z_DEFAULT_STRATEGY) == Z_OK);
// guess that output will be roughly half the input size
- *out_size = max(1U, in_size / 2);
+ *out_size = max(static_cast<size_t>(1), in_size / 2);
*out = reinterpret_cast<char*>(malloc(*out_size));
TEST_AND_RETURN_FALSE(*out);
diff --git a/http_fetcher_unittest.cc b/http_fetcher_unittest.cc
index 8d9c3f8..a0e620b 100644
--- a/http_fetcher_unittest.cc
+++ b/http_fetcher_unittest.cc
@@ -61,6 +61,7 @@
}
bool IsMock() const { return true; }
typedef NullHttpServer HttpServer;
+ void IgnoreServerAborting(HttpServer* server) const {}
};
class PythonHttpServer {
@@ -69,6 +70,7 @@
char *argv[2] = {strdup("./test_http_server"), NULL};
GError *err;
started_ = false;
+ validate_quit_ = true;
if (!g_spawn_async(NULL,
argv,
NULL,
@@ -93,12 +95,15 @@
if (!started_)
return;
// request that the server exit itself
- system((string("wget --output-document=/dev/null ") +
- LocalServerUrlForPath("/quitquitquit")).c_str());
+ int rc = system((string("wget -t 1 --output-document=/dev/null ") +
+ LocalServerUrlForPath("/quitquitquit")).c_str());
+ if (validate_quit_)
+ EXPECT_EQ(0, rc);
waitpid(pid_, NULL, 0);
}
GPid pid_;
bool started_;
+ bool validate_quit_;
};
template <>
@@ -120,6 +125,10 @@
}
bool IsMock() const { return false; }
typedef PythonHttpServer HttpServer;
+ void IgnoreServerAborting(HttpServer* server) const {
+ PythonHttpServer *pyserver = reinterpret_cast<PythonHttpServer*>(server);
+ pyserver->validate_quit_ = false;
+ }
};
typedef ::testing::Types<LibcurlHttpFetcher, MockHttpFetcher>
@@ -277,6 +286,7 @@
fetcher->set_delegate(&delegate);
typename TestFixture::HttpServer server;
+ this->IgnoreServerAborting(&server);
ASSERT_TRUE(server.started_);
GSource* timeout_source_;
timeout_source_ = g_timeout_source_new(0); // ms
diff --git a/mock_http_fetcher.h b/mock_http_fetcher.h
index 2efd258..5b9f898 100644
--- a/mock_http_fetcher.h
+++ b/mock_http_fetcher.h
@@ -29,7 +29,6 @@
MockHttpFetcher(const char* data, size_t size)
: sent_size_(0), timeout_source_(NULL), timout_tag_(0), paused_(false) {
data_.insert(data_.end(), data, data + size);
- LOG(INFO) << "timeout_source_ = " << (int)timeout_source_;
}
// Cleans up all internal state. Does not notify delegate
diff --git a/subprocess.cc b/subprocess.cc
index 89b6cad..3a6597e 100644
--- a/subprocess.cc
+++ b/subprocess.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "chromeos/obsolete_logging.h"
#include "base/scoped_ptr.h"
+#include "base/string_util.h"
using std::string;
using std::vector;
@@ -18,7 +19,7 @@
void Subprocess::GChildExitedCallback(GPid pid, gint status, gpointer data) {
COMPILE_ASSERT(sizeof(guint) == sizeof(uint32),
guint_uint32_size_mismatch);
- guint *tag = reinterpret_cast<guint*>(data);
+ guint* tag = reinterpret_cast<guint*>(data);
const SubprocessCallbackRecord& record = Get().callback_records_[*tag];
if (record.callback)
record.callback(status, record.callback_data);
@@ -38,16 +39,22 @@
uint32 Subprocess::Exec(const std::vector<std::string>& cmd,
ExecCallback callback,
- void *p) {
+ void* p) {
GPid child_pid;
- GError *err;
- scoped_array<char *> argv(new char*[cmd.size() + 1]);
+ GError* err;
+ scoped_array<char*> argv(new char*[cmd.size() + 1]);
for (unsigned int i = 0; i < cmd.size(); i++) {
argv[i] = strdup(cmd[i].c_str());
}
argv[cmd.size()] = NULL;
- char *argp[1];
- argp[0] = NULL;
+
+ scoped_array<char*> argp(new char*[2]);
+ argp[0] = argp[1] = NULL;
+ const char* kLdLibraryPathKey = "LD_LIBRARY_PATH";
+ if (getenv(kLdLibraryPathKey)) {
+ argp[0] = strdup(StringPrintf("%s=%s", kLdLibraryPathKey,
+ getenv(kLdLibraryPathKey)).c_str());
+ }
SubprocessCallbackRecord callback_record;
callback_record.callback = callback;
@@ -55,7 +62,7 @@
bool success = g_spawn_async(NULL, // working directory
argv.get(),
- argp,
+ argp.get(),
G_SPAWN_DO_NOT_REAP_CHILD, // flags
NULL, // child setup function
NULL, // child setup data pointer
@@ -66,7 +73,7 @@
LOG(ERROR) << "g_spawn_async failed";
return 0;
}
- guint *tag = new guint;
+ guint* tag = new guint;
*tag = g_child_watch_add(child_pid, GChildExitedCallback, tag);
callback_records_[*tag] = callback_record;
return *tag;
@@ -80,13 +87,13 @@
bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd,
int* return_code) {
- GError *err = NULL;
- scoped_array<char *> argv(new char*[cmd.size() + 1]);
+ GError* err = NULL;
+ scoped_array<char*> argv(new char*[cmd.size() + 1]);
for (unsigned int i = 0; i < cmd.size(); i++) {
argv[i] = strdup(cmd[i].c_str());
}
argv[cmd.size()] = NULL;
- char *argp[1];
+ char* argp[1];
argp[0] = NULL;
bool success = g_spawn_sync(NULL, // working directory
diff --git a/test_http_server.cc b/test_http_server.cc
index 94c88fa..9fbe97f 100644
--- a/test_http_server.cc
+++ b/test_http_server.cc
@@ -14,6 +14,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <errno.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -98,7 +99,7 @@
string Itoa(off_t num) {
char buf[100] = {0};
- snprintf(buf, sizeof(buf), "%lld", num);
+ snprintf(buf, sizeof(buf), "%" PRIi64, num);
return buf;
}
@@ -120,6 +121,7 @@
}
void HandleQuitQuitQuit(int fd) {
+ WriteHeaders(fd, true, 0, 0);
exit(0);
}
@@ -142,14 +144,15 @@
void HandleFlaky(int fd, const HttpRequest& request) {
const off_t full_length = kBigLength;
WriteHeaders(fd, true, full_length, request.offset);
- const off_t content_length = min(9000LL, full_length - request.offset);
+ const off_t content_length =
+ min(static_cast<off_t>(9000), full_length - request.offset);
const bool should_sleep = (request.offset % (9000 * 7)) == 0;
string buf;
for (int i = request.offset; i % 10; i++)
buf.append(1, 'a' + (i % 10));
- while (buf.size() < content_length)
+ while (static_cast<off_t>(buf.size()) < content_length)
buf.append("abcdefghij");
buf.resize(content_length);
diff --git a/test_utils.cc b/test_utils.cc
index 1c2f895..6a86025 100644
--- a/test_utils.cc
+++ b/test_utils.cc
@@ -57,14 +57,15 @@
std::vector<char> GzipCompressData(const std::vector<char>& data) {
const char fname[] = "/tmp/GzipCompressDataTemp";
if (!WriteFileVector(fname, data)) {
- system((string("rm ") + fname).c_str());
+ EXPECT_EQ(0, system((string("rm ") + fname).c_str()));
return vector<char>();
}
- system((string("cat ") + fname + "|gzip>" + fname + ".gz").c_str());
- system((string("rm ") + fname).c_str());
+ EXPECT_EQ(0, system((string("cat ") + fname + "|gzip>" +
+ fname + ".gz").c_str()));
+ EXPECT_EQ(0, system((string("rm ") + fname).c_str()));
vector<char> ret;
EXPECT_TRUE(utils::ReadFile(string(fname) + ".gz", &ret));
- system((string("rm ") + fname + ".gz").c_str());
+ EXPECT_EQ(0, system((string("rm ") + fname + ".gz").c_str()));
return ret;
}
diff --git a/update_check_action.cc b/update_check_action.cc
index a9d303c..b92e788 100644
--- a/update_check_action.cc
+++ b/update_check_action.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "update_engine/update_check_action.h"
+#include <inttypes.h>
#include <sstream>
#include <libxml/parser.h>
@@ -172,8 +173,7 @@
// error.
off_t ParseInt(const string& str) {
off_t ret = 0;
-
- int rc = sscanf(str.c_str(), "%lld", &ret);
+ int rc = sscanf(str.c_str(), "%" PRIi64, &ret);
if (rc < 1) {
// failure
return 0;
diff --git a/update_check_action_unittest.cc b/update_check_action_unittest.cc
index 417a47e..c57e2cd 100644
--- a/update_check_action_unittest.cc
+++ b/update_check_action_unittest.cc
@@ -93,6 +93,7 @@
class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> {
public:
+ OutputObjectCollectorAction() : has_input_object_(false) {}
void PerformAction() {
// copy input object
has_input_object_ = HasInputObject();
@@ -249,7 +250,7 @@
"en-US",
"unittest_track");
UpdateCheckResponse response;
- ASSERT_TRUE(
+ ASSERT_FALSE(
TestUpdateCheckAction(params,
"invalid xml>",
false,
@@ -269,7 +270,7 @@
"en-US",
"unittest_track");
UpdateCheckResponse response;
- ASSERT_TRUE(TestUpdateCheckAction(
+ ASSERT_FALSE(TestUpdateCheckAction(
params,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
"xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
@@ -292,7 +293,7 @@
"en-US",
"unittest_track");
UpdateCheckResponse response;
- ASSERT_TRUE(TestUpdateCheckAction(
+ ASSERT_FALSE(TestUpdateCheckAction(
params,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
"xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
@@ -315,7 +316,7 @@
"en-US",
"unittest_track");
UpdateCheckResponse response;
- ASSERT_TRUE(TestUpdateCheckAction(
+ ASSERT_FALSE(TestUpdateCheckAction(
params,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
"xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
@@ -435,7 +436,7 @@
"en-US",
"unittest_track");
UpdateCheckResponse response;
- ASSERT_TRUE(
+ ASSERT_FALSE(
TestUpdateCheckAction(params,
"invalid xml>",
false,
diff --git a/utils.cc b/utils.cc
index e1ed874..ff3c9db 100644
--- a/utils.cc
+++ b/utils.cc
@@ -80,7 +80,7 @@
reinterpret_cast<const unsigned char* const>(arr);
LOG(INFO) << "Logging array of length: " << length;
const unsigned int bytes_per_line = 16;
- for (size_t i = 0; i < length; i += bytes_per_line) {
+ for (uint32_t i = 0; i < length; i += bytes_per_line) {
const unsigned int bytes_remaining = length - i;
const unsigned int bytes_per_this_line = min(bytes_per_line,
bytes_remaining);