Revert "update_engine: Migrate build system to gyp."

This reverts commit 0d98d921d1ba82dc496bb98e7dedd4f3baaf67de.

Several canary bot (at least link, ivybridge, peach, beltino) failed with the following:

Generating delta update
Patching kernel /tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/cros_generate_update_payload.dsXzrS
   into /tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/src_image.bin
/dev/loop19 has been unmounted
rmdir: removing directory, `/tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/state.MtVYXo'
md5sum of src kernel:
84f3098b6822080aa2101f7623a8ebec  /tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/cros_generate_update_payload.dsXzrS
md5sum of src root:
ed15fa4b6fab97b1d2704c109a95f366  /tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/cros_generate_update_payload.S3qwDy
Patching kernel /tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/cros_generate_update_payload.M1kqWN
   into /tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/tgt_image.bin
/dev/loop21 has been unmounted
rmdir: removing directory, `/tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/state.M80v7t'
Using rootfs partition size: 2147483648
ERROR: something wrong with flag 'old_dir' in file '../../../../../../tmp/portage/chromeos-base/update_engine-0.0.2-r646/work/update_engine-0.0.2/platform2/update_engine/payload_generator/generate_delta_main.cc'.  One possibility: file '../../../../../../dev/loop10 has been unmounted
rmdir: removing directory, `/tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/src_root.Amedwg'
/dev/loop5 has been unmounted
rmdir: removing directory, `/tmp/cbuildbot-tmpkZN69N/tmpXG3Fv3/paygen_payload.wqtif7/src_root.7rMVQV'
Cleanup success after an error.

This CL appears to be the only one related to the update_engine. Revert it first and see if the buildbot will recover.

Change-Id: Ia42b19a808ae9c95cd600e4f585adbf2e7511395
Reviewed-on: https://chromium-review.googlesource.com/208257
Reviewed-by: Chun-ta Lin <itspeter@chromium.org>
Commit-Queue: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
diff --git a/SConstruct b/SConstruct
new file mode 100644
index 0000000..9cc76e5
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,371 @@
+# Copyright (c) 2012 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.
+
+import os
+
+# Protobuffer compilation
+def ProtocolBufferEmitter(target, source, env):
+  """ Inputs:
+          target: list of targets to compile to
+          source: list of sources to compile
+          env: the scons environment in which we are compiling
+      Outputs:
+          target: the list of targets we'll emit
+          source: the list of sources we'll compile"""
+  output = str(source[0])
+  output = output[0:output.rfind('.proto')]
+  target = [
+    output + '.pb.cc',
+    output + '.pb.h',
+  ]
+  return target, source
+
+def ProtocolBufferGenerator(source, target, env, for_signature):
+  """ Inputs:
+          source: list of sources to process
+          target: list of targets to generate
+          env: scons environment in which we are working
+          for_signature: unused
+      Outputs: a list of commands to execute to generate the targets from
+               the sources."""
+  commands = [
+    '/usr/bin/protoc '
+    ' --proto_path . ${SOURCES} --cpp_out .']
+  return commands
+
+proto_builder = Builder(generator = ProtocolBufferGenerator,
+                        emitter = ProtocolBufferEmitter,
+                        single_source = 1,
+                        suffix = '.pb.cc')
+
+def DbusBindingsEmitter(target, source, env):
+  """ Inputs:
+          target: unused
+          source: list containing the source .xml file
+          env: the scons environment in which we are compiling
+      Outputs:
+          target: the list of targets we'll emit
+          source: the list of sources we'll process"""
+  output = str(source[0])
+  output = output[0:output.rfind('.xml')]
+  target = [
+    output + '.dbusserver.h',
+    output + '.dbusclient.h'
+  ]
+  return target, source
+
+def DbusBindingsGenerator(source, target, env, for_signature):
+  """ Inputs:
+          source: list of sources to process
+          target: list of targets to generate
+          env: scons environment in which we are working
+          for_signature: unused
+      Outputs: a list of commands to execute to generate the targets from
+               the sources."""
+  commands = []
+  for target_file in target:
+    if str(target_file).endswith('.dbusserver.h'):
+      mode_flag = '--mode=glib-server '
+    else:
+      mode_flag = '--mode=glib-client '
+    cmd = '/usr/bin/dbus-binding-tool %s --prefix=update_engine_service ' \
+          '%s > %s' % (mode_flag, str(source[0]), str(target_file))
+    commands.append(cmd)
+  return commands
+
+dbus_bindings_builder = Builder(generator = DbusBindingsGenerator,
+                                emitter = DbusBindingsEmitter,
+                                single_source = 1,
+                                suffix = 'dbusclient.h')
+
+# Public key generation
+def PublicKeyEmitter(target, source, env):
+  """ Inputs:
+          target: list of targets to compile to
+          source: list of sources to compile
+          env: the scons environment in which we are compiling
+      Outputs:
+          target: the list of targets we'll emit
+          source: the list of sources we'll compile"""
+  targets = []
+  for source_file in source:
+    output = str(source_file)
+    output = output[0:output.rfind('.pem')]
+    output += '.pub.pem'
+    targets.append(output)
+  return targets, source
+
+def PublicKeyGenerator(source, target, env, for_signature):
+  """ Inputs:
+          source: list of sources to process
+          target: list of targets to generate
+          env: scons environment in which we are working
+          for_signature: unused
+      Outputs: a list of commands to execute to generate the targets from
+               the sources."""
+  commands = []
+  for source_file in source:
+    output = str(source_file)
+    output = output[0:output.rfind('.pem')]
+    output += '.pub.pem'
+    cmd = '/usr/bin/openssl rsa -in %s -pubout -out %s' % (source_file, output)
+    commands.append(cmd)
+  return commands
+
+public_key_builder = Builder(generator = PublicKeyGenerator,
+                             emitter = PublicKeyEmitter,
+                             suffix = '.pub.pem')
+
+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 LDFLAGS 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['LINKFLAGS'] = Split("""
+    -Wl,--gc-sections""")
+env['LINKFLAGS'] += env.get('LDFLAGS', [])
+
+env['CCFLAGS'] = Split("""
+    -g
+    -ffunction-sections
+    -fno-exceptions
+    -fno-strict-aliasing
+    -std=gnu++11
+    -Wall
+    -Wextra
+    -Werror
+    -Wno-unused-parameter
+    -Wno-deprecated-register
+    -D__STDC_FORMAT_MACROS=1
+    -D_FILE_OFFSET_BITS=64
+    -D_POSIX_C_SOURCE=199309L""")
+env['CCFLAGS'] += env['CFLAGS']
+
+BASE_VER = os.environ.get('BASE_VER', '271506')
+env['LIBS'] = Split("""bz2
+                       gflags
+                       policy-%s
+                       rootdev
+                       rt
+                       vboot_host""" % (BASE_VER,))
+env['CPPPATH'] = ['..']
+env['BUILDERS']['ProtocolBuffer'] = proto_builder
+env['BUILDERS']['DbusBindings'] = dbus_bindings_builder
+env['BUILDERS']['PublicKey'] = public_key_builder
+
+# Fix issue with scons not passing pkg-config vars through the environment.
+for key in Split('PKG_CONFIG_LIBDIR PKG_CONFIG_PATH'):
+  if os.environ.has_key(key):
+    env['ENV'][key] = os.environ[key]
+
+pkgconfig = os.environ.get('PKG_CONFIG', 'pkg-config')
+
+env.ParseConfig(pkgconfig + ' --cflags --libs ' + ' '.join((
+                'dbus-1',
+                'dbus-glib-1',
+                'ext2fs',
+                'gio-2.0',
+                'gio-unix-2.0',
+                'glib-2.0',
+                'gthread-2.0',
+                'libchrome-%s' % BASE_VER,
+                'libchromeos-%s' % BASE_VER,
+                'libcrypto',
+                'libcurl',
+                'libmetrics-%s' % BASE_VER,
+                'libssl',
+                'libxml-2.0',
+                'protobuf')))
+env.ProtocolBuffer('update_metadata.pb.cc', 'update_metadata.proto')
+env.PublicKey('unittest_key.pub.pem', 'unittest_key.pem')
+env.PublicKey('unittest_key2.pub.pem', 'unittest_key2.pem')
+
+# Target name is derived from the source .xml filename. The passed name is
+# unused.
+env.DbusBindings(None, 'update_engine.xml')
+
+if ARGUMENTS.get('debug', 0):
+  env['CCFLAGS'] += ['-fprofile-arcs', '-ftest-coverage']
+  env['LIBS'] += ['bz2', 'gcov']
+
+sources = Split("""action_processor.cc
+                   bzip.cc
+                   bzip_extent_writer.cc
+                   certificate_checker.cc
+                   chrome_browser_proxy_resolver.cc
+                   clock.cc
+                   connection_manager.cc
+                   constants.cc
+                   dbus_service.cc
+                   delta_performer.cc
+                   download_action.cc
+                   extent_ranges.cc
+                   extent_writer.cc
+                   file_descriptor.cc
+                   file_writer.cc
+                   filesystem_copier_action.cc
+                   hardware.cc
+                   http_common.cc
+                   http_fetcher.cc
+                   hwid_override.cc
+                   install_plan.cc
+                   libcurl_http_fetcher.cc
+                   metrics.cc
+                   multi_range_http_fetcher.cc
+                   omaha_hash_calculator.cc
+                   omaha_request_action.cc
+                   omaha_request_params.cc
+                   omaha_response_handler_action.cc
+                   p2p_manager.cc
+                   payload_constants.cc
+                   payload_generator/cycle_breaker.cc
+                   payload_generator/delta_diff_generator.cc
+                   payload_generator/extent_mapper.cc
+                   payload_generator/filesystem_iterator.cc
+                   payload_generator/full_update_generator.cc
+                   payload_generator/graph_utils.cc
+                   payload_generator/metadata.cc
+                   payload_generator/tarjan.cc
+                   payload_generator/topological_sort.cc
+                   payload_signer.cc
+                   payload_state.cc
+                   postinstall_runner_action.cc
+                   prefs.cc
+                   proxy_resolver.cc
+                   real_system_state.cc
+                   simple_key_value_store.cc
+                   subprocess.cc
+                   terminator.cc
+                   update_attempter.cc
+                   update_check_scheduler.cc
+                   update_manager/boxed_value.cc
+                   update_manager/chromeos_policy.cc
+                   update_manager/evaluation_context.cc
+                   update_manager/event_loop.cc
+                   update_manager/policy.cc
+                   update_manager/real_config_provider.cc
+                   update_manager/real_device_policy_provider.cc
+                   update_manager/real_random_provider.cc
+                   update_manager/real_shill_provider.cc
+                   update_manager/real_system_provider.cc
+                   update_manager/real_time_provider.cc
+                   update_manager/real_updater_provider.cc
+                   update_manager/state_factory.cc
+                   update_manager/update_manager.cc
+                   update_metadata.pb.cc
+                   utils.cc""")
+main = ['main.cc']
+
+unittest_sources = Split("""action_pipe_unittest.cc
+                            action_processor_unittest.cc
+                            action_unittest.cc
+                            bzip_extent_writer_unittest.cc
+                            certificate_checker_unittest.cc
+                            chrome_browser_proxy_resolver_unittest.cc
+                            connection_manager_unittest.cc
+                            delta_performer_unittest.cc
+                            download_action_unittest.cc
+                            extent_ranges_unittest.cc
+                            extent_writer_unittest.cc
+                            fake_prefs.cc
+                            fake_system_state.cc
+                            file_writer_unittest.cc
+                            filesystem_copier_action_unittest.cc
+                            http_fetcher_unittest.cc
+                            hwid_override_unittest.cc
+                            mock_http_fetcher.cc
+                            omaha_hash_calculator_unittest.cc
+                            omaha_request_action_unittest.cc
+                            omaha_request_params_unittest.cc
+                            omaha_response_handler_action_unittest.cc
+                            p2p_manager_unittest.cc
+                            payload_generator/cycle_breaker_unittest.cc
+                            payload_generator/delta_diff_generator_unittest.cc
+                            payload_generator/extent_mapper_unittest.cc
+                            payload_generator/filesystem_iterator_unittest.cc
+                            payload_generator/full_update_generator_unittest.cc
+                            payload_generator/graph_utils_unittest.cc
+                            payload_generator/metadata_unittest.cc
+                            payload_generator/tarjan_unittest.cc
+                            payload_generator/topological_sort_unittest.cc
+                            payload_signer_unittest.cc
+                            payload_state_unittest.cc
+                            postinstall_runner_action_unittest.cc
+                            prefs_unittest.cc
+                            simple_key_value_store_unittest.cc
+                            subprocess_unittest.cc
+                            terminator_unittest.cc
+                            test_utils.cc
+                            update_attempter_unittest.cc
+                            update_check_scheduler_unittest.cc
+                            update_manager/boxed_value_unittest.cc
+                            update_manager/chromeos_policy_unittest.cc
+                            update_manager/evaluation_context_unittest.cc
+                            update_manager/event_loop_unittest.cc
+                            update_manager/generic_variables_unittest.cc
+                            update_manager/prng_unittest.cc
+                            update_manager/real_config_provider_unittest.cc
+                            update_manager/real_device_policy_provider_unittest.cc
+                            update_manager/real_random_provider_unittest.cc
+                            update_manager/real_shill_provider_unittest.cc
+                            update_manager/real_system_provider_unittest.cc
+                            update_manager/real_time_provider_unittest.cc
+                            update_manager/real_updater_provider_unittest.cc
+                            update_manager/umtest_utils.cc
+                            update_manager/update_manager_unittest.cc
+                            update_manager/variable_unittest.cc
+                            utils_unittest.cc
+                            zip_unittest.cc""")
+unittest_main = ['testrunner.cc']
+
+client_main = ['update_engine_client.cc']
+
+delta_generator_main = ['payload_generator/generate_delta_main.cc']
+
+# Hack to generate header files first. They are generated as a side effect
+# of generating other files (usually their corresponding .c(c) files),
+# so we make all sources depend on those other files.
+all_sources = []
+all_sources.extend(sources)
+all_sources.extend(unittest_sources)
+all_sources.extend(main)
+all_sources.extend(unittest_main)
+all_sources.extend(client_main)
+all_sources.extend(delta_generator_main)
+for source in all_sources:
+  if source.endswith('_unittest.cc'):
+    env.Depends(source, 'unittest_key.pub.pem')
+  if source.endswith('.pb.cc'):
+    continue
+  env.Depends(source, 'update_metadata.pb.cc')
+  env.Depends(source, 'update_engine.dbusclient.h')
+
+update_engine_core = env.Library('update_engine_core', sources)
+env.Prepend(LIBS=[update_engine_core])
+
+env.Program('update_engine', main)
+
+client_cmd = env.Program('update_engine_client', client_main);
+
+delta_generator_cmd = env.Program('delta_generator',
+                                  delta_generator_main)
+
+http_server_cmd = env.Program('test_http_server', 'test_http_server.cc')
+
+unittest_env = env.Clone()
+unittest_env.Append(LIBS=['gmock', 'gtest'])
+unittest_cmd = unittest_env.Program('update_engine_unittests',
+                           unittest_sources + unittest_main)
+Clean(unittest_cmd, Glob('*.gcda') + Glob('*.gcno') + Glob('*.gcov') +
+                    Split('html app.info'))