SDK: Scripts to generate plugin's skeleton code

done:
- create plugin folder structure
- manifest.json + icon.png
- copyright header
- main.cpp
- choose number of functionalities and the api to each one of them
- create src files for each functionality (APIs skeleton .h and .cpp)
- create preferences.json
- put colors into prints and clear outputs when needed
- modify src files to set preferences code
- create pakage.json
- add helper files
- use library Cmd
- reorganize functions into classes define inherits stack
- add GNU GPL to python files
- jpl merge function
- pre and post assembles
- default options plugin build
- windows build with build-plugin.py
- add build option for windows build
- generate base CMakeLists.txt and build.sh

Change-Id: Id8eb5a97fa7a51e99a0f9215835c3d5ffea630ad
GitLab: #2
diff --git a/build-plugin.py b/build-plugin.py
index d96e575..6190afd 100644
--- a/build-plugin.py
+++ b/build-plugin.py
@@ -1,10 +1,32 @@
 #!/usr/bin/env python3
 #
+# Copyright (C) 2020 Savoir-faire Linux Inc.
+#
+# Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Creates packaging targets for a distribution and architecture.
+# This helps reduce the length of the top Makefile.
+#
+
 # This script must unify the Plugins build for
 # every project and Operational System
 
 import os
 import sys
+import json
 import platform
 import argparse
 import subprocess
@@ -28,6 +50,8 @@
     parser.add_argument('--distribution')
     parser.add_argument('--processor', type=str, default="GPU",
                         help='Runtime plugin CPU/GPU setting.')
+    parser.add_argument('--buildOptions', default='', type=str,
+                        help="Type all build optionsto pass to package.json 'defines' property.\nThis argument consider that you're using cmake.")
 
     dist = choose_distribution()
 
@@ -50,6 +74,10 @@
         args.processor *= len(args.projects)
 
     validate_args(args)
+
+    if dist != WIN32_DISTRIBUTION_NAME:
+        args.toolset = ''
+        args.sdk = ''
     return args
 
 
@@ -75,6 +103,9 @@
         if (processor not in ['GPU', 'CPU']):
             sys.exit('Processor can only be GPU or CPU.')
 
+    if (parsed_args.buildOptions):
+        parsed_args.buildOptions = parsed_args.buildOptions.split(',')
+
 
 def choose_distribution():
     system = platform.system().lower()
@@ -95,14 +126,32 @@
     return 'Unknown'
 
 
-def buildPlugin(pluginPath, processor, distribution):
+def buildPlugin(pluginPath, processor, distribution, toolset='', sdk='', buildOptions=''):
     if distribution == WIN32_DISTRIBUTION_NAME:
-        return subprocess.run([
+        if (buildOptions):
+            with open(f"{pluginPath}/package.json") as f:
+                defaultPackage = json.load(f)
+                package = defaultPackage.copy()
+                package['defines'] = []
+                for option in buildOptions:
+                    package['defines'].append(option)
+                f.close()
+            with open(f"{pluginPath}/package.json", 'w') as f:
+                json.dump(package, f, indent=4)
+                f.close()
+        subprocess.run([
             sys.executable, os.path.join(
-                os.getcwd(), pluginPath + "/build-windows.py"),
-            "--toolset", args.toolset,
-            "--sdk", args.sdk
+                os.getcwd(), "../../daemon/compat/msvc/winmake.py"),
+            "-P",
+            "--toolset", toolset,
+            "--sdk", sdk,
+            "-fb", pluginPath.split('/')[-1]
         ], check=True)
+        if (buildOptions):
+            with open(f"{pluginPath}/package.json", "w") as f:
+                json.dump(defaultPackage, f, indent=4)
+                f.close()
+        return
 
     environ = os.environ.copy()
 
@@ -117,6 +166,7 @@
     install_args.append('-p')
     install_args.append(str(multiprocessing.cpu_count()))
 
+    subprocess.check_call(['chmod', '+x', pluginPath + "/build.sh"])
     return subprocess.run([pluginPath + "/build.sh"] +
                           install_args, env=environ, check=True)
 
@@ -130,7 +180,10 @@
         buildPlugin(
             currentDir + "/" + plugin,
             args.processor[i],
-            args.distribution)
+            args.distribution,
+            args.toolset,
+            args.sdk,
+            args.buildOptions)
 
 
 if __name__ == "__main__":