build: Refactor JSON scanner for UserInstall 71/23671/4
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Thu, 7 Dec 2017 13:14:26 +0000 (14:14 +0100)
committerMats Wichmann <mats@linux.com>
Mon, 1 Jan 2018 15:23:38 +0000 (15:23 +0000)
This was tested using poky master,
after scon install was introduced.

Change-Id: I5e154eff8b5e669f0dc0992b93f32c1d595bb322
Bug: https://jira.iotivity.org/browse/IOT-524
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
build_common/SConscript

index 9eeef29..f937815 100755 (executable)
@@ -875,9 +875,9 @@ builder = Builder(generator = generate_actions,
 env.Append(BUILDERS = {'Cbor' : builder})
 
 
-def ScanJSON(env, directory='.'):
+def ScanJSON(env, directory=None):
     targets = []
-    if '.' == directory:
+    if not directory:
         directory = Dir('.').srcnode().path
     if env.GetOption('clean') or env.get('SECURED') != '1':
         return targets
@@ -888,16 +888,20 @@ def ScanJSON(env, directory='.'):
         src = src_dir + filename
         dst = dst_dir + filename
         targets += Command(dst, src, Copy("$TARGET", "$SOURCE"))
-        if env.get('CROSS_COMPILE') != None:
-            cbor_file = src_dir + re.sub('\.json$', '.dat', str(json_file))
-            targets += Install(dst_dir, cbor_file)
-        else:
+        if env.get('CROSS_COMPILE') == None:
+            # Copy back compiled files to sources (to be used when compilation is not possible)
             cbor_file = env.Cbor(json_file)
             targets.append(cbor_file)
             cbor_file = Flatten(cbor_file)[0].name
             src = dst_dir + cbor_file
             dst = src_dir + cbor_file
             Command(dst, src, Copy("$TARGET", "$SOURCE"))
+        else:
+            # Can compile files at build time, so rely on previous generated files
+            cbor_file = re.sub('\.json$', '.dat', filename)
+            src = src_dir + cbor_file
+            dst = dst_dir + cbor_file
+            targets += Command(dst, src, Copy("$TARGET", "$SOURCE"))
     return targets
 
 AddMethod(env, ScanJSON)