Continue improving libcoap build script 93/23093/2
authorMats Wichmann <mats@linux.com>
Mon, 6 Nov 2017 15:36:01 +0000 (08:36 -0700)
committerMats Wichmann <mats@linux.com>
Wed, 15 Nov 2017 22:38:53 +0000 (22:38 +0000)
* The variable-substitution section in building the coap.h
  config file (for the "upstream" version) not working, repaired.
* Move the coap.h comment down to where the work is done for
  easier reading.
* Use "with" statement for file handling (conventions)
* Clean up the glob handling to generate the file lists: use
  scons internal Glob.
* Save the correct coap path into a construction var LIBCOAP_INC.
  Other scripts will later be modified to use this, but as of
  this patch it has no active effect.

Along the way, found build script in plugins was using
WITH_UNFORKED_LIBCOAP (which is never set in the environment)
rather than WITH_UPSTREAM_LIBCOAP - this is adjusted.

Change-Id: I0398b440c5318516578426253a653024f3277fe4
Signed-off-by: Mats Wichmann <mats@linux.com>
extlibs/libcoap/SConscript
plugins/src/SConscript

index ee34a75..b21681e 100644 (file)
@@ -25,8 +25,6 @@
 ##
 
 import os
-import glob
-import datetime
 import subprocess
 import SCons.Util
 
@@ -82,6 +80,7 @@ if with_upstream_libcoap == '1':
 * Automatically updating libcoap to version %s.
 *******************************************************************************
 ''' % (libcoap_version))
+            # TODO: we are not actually checking the output... fix
             subprocess.check_output(libcoap_update_command, shell=True)
         else:
             msg = '''
@@ -303,33 +302,43 @@ if with_upstream_libcoap == '1':
         # Generate the file
         if os.path.exists(config_h_file_path):
             os.remove(config_h_file_path)
-        config_h_file = open(config_h_file_path, "w")
-        config_h_file.write(config_h_header + config_h_body + config_h_footer)
-        config_h_file.close()
+        with open(config_h_file_path, "w") as config_h_file:
+            config_h_file.write(config_h_header + config_h_body + config_h_footer)
 
     # Sanity check to ensure that the above block created the file.
     if not os.path.exists(config_h_file_path) and not env.GetOption('clean'):
         msg = "Error: coap_config.h file not created!"
         Exit(msg)
 
+    # We also need to generate coap.h from coap.h.in
+    coap_h_pc_file = os.path.join(libcoap_dir, 'include', 'coap', 'coap.h.in')
+    # substitution table:
     pc_vars = {
-        '\@LIBCOAP_PACKAGE_NAME\@': lib_prefix + 'coap',
-        '\@LIBCOAP_PACKAGE_STRING\@': lib_prefix + 'coap-' + libcoap_version,
-        '\@LIBCOAP_PACKAGE_URL\@': libcoap_repo_url,
-        '\@LIBCOAP_PACKAGE_BUGREPORT\@': libcoap_repo_url + '/issues',
-        '\@LIBCOAP_PACKAGE_VERSION\@': libcoap_version
+        '@PACKAGE_NAME@': lib_prefix + 'coap',
+        '@PACKAGE_STRING@': lib_prefix + 'coap-' + libcoap_version,
+        '@PACKAGE_URL@': libcoap_repo_url,
+        '@PACKAGE_BUGREPORT@': libcoap_repo_url + '/issues',
+        '@PACKAGE_VERSION@': libcoap_version
     }
     libcoap_env.Substfile(coap_h_pc_file, SUBST_DICT=pc_vars)
 
-    libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
-    libcoap_src.remove(os.path.join(libcoap_src_root, 'coap_io_lwip.c'))
+    # redefine root to be relative to current dir for Glob check
+    libcoap_src_root = 'libcoap/src/'
+    libcoap_src = Glob(libcoap_src_root + '*.c',
+                       exclude=libcoap_src_root + 'coap_io_lwip.c')
 else:
     # For bring up purposes only, the forked version will live here.
-    libcoap_src_root = src_dir + '/resource/csdk/connectivity/lib/libcoap-4.1.1'
-    libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
+    libcoap_src_root = '#/resource/csdk/connectivity/lib/libcoap-4.1.1/'
+    libcoap_src = Glob(libcoap_src_root + '*.c')
 
 libcoap = libcoap_env.StaticLibrary('coap', libcoap_src, OBJPREFIX='libcoap_')
 
+# set for use by other scripts:
+if with_upstream_libcoap == '1':
+    env.AppendUnique(LIBCOAP_INC='#/extlibs/libcoap/libcoap/include')
+else:
+    env.AppendUnique(LIBCOAP_INC='#/resource/csdk/connectivity/lib/libcoap-4.1.1/include')
+
 Clean(libcoap, config_h_file_path)
 libcoap_env.InstallTarget([libcoap], 'coap')
 
index 0f9c57f..033a863 100644 (file)
@@ -30,8 +30,8 @@ target_os = env.get('TARGET_OS')
 ######################################################################
 # Build flags
 ######################################################################
-with_unforked_libcoap = env.get('WITH_UNFORKED_LIBCOAP')
-if with_unforked_libcoap == '1':
+with_upstream = env.get('WITH_UPSTREAM_LIBCOAP')
+if with_upstream == '1':
     env.PrependUnique(CPPPATH=['#extlibs/libcoap/libcoap/include'])
 else:
     env.PrependUnique(CPPPATH=['#/resource/csdk/connectivity/lib/libcoap-4.1.1/include'])