Fixed sdk from local file installation 21/14721/1
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Wed, 27 Jun 2018 13:52:14 +0000 (15:52 +0200)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Wed, 27 Jun 2018 13:52:14 +0000 (15:52 +0200)
Rework sdk uuid management because previous code prevented to install
local sdk using following command:
 xds-cli sdks install --file $HOME/xds-workspace/my_local_sdk.sh

Change-Id: I20bac8a76d32b005a6775e936756c96048651766
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
lib/xdsserver/sdk.go
lib/xdsserver/sdks.go
lib/xsapiv1/sdks.go
scripts/sdks/README.md
scripts/sdks/agl/add
scripts/sdks/agl/db-dump
scripts/sdks/agl/get-sdk-info

index 7c912c4..68c92b4 100644 (file)
@@ -92,7 +92,7 @@ func ListCrossSDK(scriptDir string, update bool, log *logrus.Logger) ([]xsapiv1.
 }
 
 // GetSDKInfo Used get-sdk-info script to extract SDK get info from a SDK file/tarball
-func GetSDKInfo(scriptDir, url, filename, md5sum string, log *logrus.Logger) (xsapiv1.SDK, error) {
+func GetSDKInfo(scriptDir, url, filename, md5sum, uuid string, log *logrus.Logger) (xsapiv1.SDK, error) {
        sdk := xsapiv1.SDK{}
 
        args := []string{}
@@ -106,6 +106,9 @@ func GetSDKInfo(scriptDir, url, filename, md5sum string, log *logrus.Logger) (xs
        } else {
                return sdk, fmt.Errorf("url of filename must be set")
        }
+       if uuid != "" {
+               args = append(args, "--uuid", uuid)
+       }
 
        cmd := exec.Command(path.Join(scriptDir, scriptGetSdkInfo), args...)
        stdout, err := cmd.CombinedOutput()
@@ -327,7 +330,7 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
                        // (see sdks.go / monitorSDKInstallation )
                        // Update SetupFile when n
                        if s.sdk.SetupFile == "" {
-                               sdkDef, err := GetSDKInfo(s.sdk.FamilyConf.ScriptsDir, s.sdk.URL, "", "", s.Log)
+                               sdkDef, err := GetSDKInfo(s.sdk.FamilyConf.ScriptsDir, s.sdk.URL, "", "", s.sdk.UUID, s.Log)
                                if err != nil || sdkDef.SetupFile == "" {
                                        s.Log.Errorf("GetSDKInfo error: %v", err)
                                        code = 1
index 4a7ba84..ee6a269 100644 (file)
@@ -340,7 +340,7 @@ func (s *SDKs) Install(id, filepath string, force bool, timeout int, args []stri
 
                // Update path when not set
                if sdk.Path == "" {
-                       sdkDef, err := GetSDKInfo(scriptDir, sdk.URL, "", "", s.Log)
+                       sdkDef, err := GetSDKInfo(scriptDir, sdk.URL, "", "", sdk.UUID, s.Log)
                        if err != nil || sdkDef.Path == "" {
                                return nil, fmt.Errorf("cannot retrieve sdk path %v", err)
                        }
@@ -356,7 +356,7 @@ func (s *SDKs) Install(id, filepath string, force bool, timeout int, args []stri
                }
 
                for _, sf := range s.SdksFamilies {
-                       sdkDef, err := GetSDKInfo(sf.ScriptsDir, "", sdkFilename, "", s.Log)
+                       sdkDef, err := GetSDKInfo(sf.ScriptsDir, "", sdkFilename, "", "", s.Log)
                        if err == nil {
                                // OK, sdk found
                                sdk = &sdkDef
index abb5d4a..54b941b 100644 (file)
@@ -30,6 +30,7 @@ const (
 type SDK struct {
        ID          string `json:"id" binding:"required"`
        Name        string `json:"name"`
+       UUID        string `json:"uuid"`
        Description string `json:"description"`
        Profile     string `json:"profile"`
        Version     string `json:"version"`
index 97bae21..c887293 100644 (file)
@@ -35,6 +35,7 @@ Returned the list all SDKs (available and installed) using JSON format.
 [
   {
     "name":         "My SDK name",
+    "uuid":         "a-unique-id",
     "description":  "A description",
     "profile":      "profile",
     "version":      "version",
@@ -102,6 +103,7 @@ returned the following JSON structure:
 ```json
 {
     "name":         "My SDK name",
+    "uuid":         "a-unique-id",
     "description":  "A description",
     "profile":      "profile",
     "version":      "version",
index 839d647..f602fa9 100755 (executable)
@@ -93,6 +93,8 @@ fi
 # Compute uuid when needed
 if [ "$UUID" = "" ] && [ "$URL" != "" ]; then
     UUID=$(echo "$URL" | md5sum |cut -d' ' -f1)
+elif [ "$SDK_FILE" != "" ]; then
+    UUID=$(echo $(basename $SDK_FILE) | md5sum |cut -d' ' -f1)
 else
     echo "UUID value must be specify using --uuid option."
     exit 1
index 027fdcf..ec2b1d8 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 #
-#/**************************************************************************
+# /**************************************************************************
 # * Copyright 2017-2018 IoT.bzh
 # *
 # * author: Romain Forlot <romain.forlot@iot.bzh>
@@ -46,7 +46,7 @@ SCRIPT_PATH = os.path.dirname(os.path.abspath(
 ENV = subprocess.check_output(
     [os.path.join(SCRIPT_PATH, './_env-init.sh'), '-print']).splitlines()
 
-SDK_ROOT_DIR=None
+SDK_ROOT_DIR = None
 for elt in ENV:
     k, v = elt.decode().split('=', 1)
     if k == 'SDK_ROOT_DIR':
@@ -71,6 +71,7 @@ SDK_DB_JSON = json.load(open(SDK_DB_FILEPATH, 'r'))
 
 for one_sdk in SDK_DB_JSON:
     one_sdk['status'] = 'Not Installed'
+    one_sdk['uuid'] = ''
 
 INSTALLED_SDK = []
 for root, dirs, files in os.walk(SDK_ROOT_DIR):
@@ -106,6 +107,8 @@ for one_sdk in INSTALLED_SDK:
         logging.debug('Path not compliant, skipping')
         continue
 
+    UUID = os.path.basename(os.path.normpath(DIR))
+
     SDK_DATE = ''
     for line in open(one_sdk['VERSION_FILE']).readlines():
         if line.startswith('Timestamp'):
@@ -126,6 +129,7 @@ for one_sdk in INSTALLED_SDK:
             sdk['date'] = SDK_DATE
             sdk['setupFile'] = one_sdk['ENV_FILE']
             sdk['path'] = DIR
+            sdk['uuid'] = UUID
             break
 
     if not found:
@@ -133,6 +137,7 @@ for one_sdk in INSTALLED_SDK:
                       PROFILE + '-' + ARCH + '-' + VERSION)
         NEW_SDK = {
             'name': PROFILE + '-' + ARCH + '-' + VERSION,
+            'uuid': UUID,
             'description': 'AGL SDK ' + ARCH + ' (version ' + VERSION + ')',
             'profile': PROFILE,
             'version': VERSION,
index c28f2e4..485d5fe 100755 (executable)
@@ -131,6 +131,8 @@ if [ "${UUID}" = "" ]; then
         UUID="basename ${curInstDir}"
     elif [ "$URL" != "" ]; then
         UUID=$(echo "$URL" | md5sum |cut -d' ' -f1)
+    elif [ "$filename" != "" ]; then
+        UUID=$(echo $(basename $filename) | md5sum |cut -d' ' -f1)
     else
         echo "UUID value must be specify using --uuid option."
         exit 1
@@ -147,6 +149,7 @@ fi
 read -r -d '' res <<- EndOfMessage
 {
     "name":         "${profile}_${arch}_${version}",
+    "uuid":         "${UUID}",
     "description":  "AGL SDK ${arch} (version ${version})",
     "profile":      "${profile}",
     "version":      "${version}",