Fix to parse frameworks in project.json
authorWonYoung Choi <wy80.choi@samsung.com>
Thu, 1 Sep 2016 01:50:43 +0000 (10:50 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Thu, 1 Sep 2016 01:50:43 +0000 (10:50 +0900)
Change-Id: I5cec4b0a309cf4bb9bde8cd65e971e4342b76105

packaging/dotnet-build-tools.spec
targets/Tizen.Build.GBS.Targets
tools/dotnet-gbs/dotnet-gbs.py

index cfffe17..ac8e6e4 100644 (file)
@@ -7,9 +7,13 @@ License:    Apache-2.0
 URL:        https://www.tizen.org
 Source0:    %{name}-%{version}.tar.gz
 
+AutoReqProv: no
+
 Requires:   python
 Requires:   mono-core
 Requires:   mono-compat
+Requires:   mono-devel
+Requires:   mono-compiler
 
 %description
 Build target files (.Targets) and Tools (including NuGet.exe) for building
index 41c4de1..a5ec1fc 100644 (file)
@@ -18,7 +18,7 @@
   </PropertyGroup>
 
   <PropertyGroup>
-    <AdditionalLibPaths>$(CoreFxPath);$(TizenAPIPath)</AdditionalLibPaths>
+    <AdditionalLibPaths>$(CoreFxPath);$(DotnetAssemblyPath)</AdditionalLibPaths>
   </PropertyGroup>
 
   <ItemGroup Condition=" '$(CoreFxPath)' != '' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">
     <ReferencePath Include="@(CoreFXAssemblies->'%(Filename).dll')" />
   </ItemGroup>
 
-  <ItemGroup Condition=" '$(TizenAPIPath)' != '' ">
-    <TizenAPIDir Include="$(TizenAPIPath)" Condition="Exists('$(TizenAPIPath)')"/>
-    <TizenAPIAssemblies Include="@(TizenAPIDir->'%(FullPath)/*.dll')"/>
-    <ReferencePath Include="@(TizenAPIAssemblies->'%(Filename).dll')"/>
+  <ItemGroup Condition=" '$(DotnetAssemblyPath)' != '' ">
+    <DotnetAssemblyDir Include="$(DotnetAssemblyPath)" Condition="Exists('$(DotnetAssemblyPath)')"/>
+    <DotnetAssemblies Include="@(DotnetAssemblyDir->'%(FullPath)/*.dll')"/>
+    <ReferencePath Include="@(DotnetAssemblies->'%(Filename).dll')"/>
   </ItemGroup>
 
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
index a4966d5..15a4451 100755 (executable)
@@ -13,8 +13,35 @@ BUILD_TEMPLATE_CSPROJ = os.path.join(SCRIPTDIR, "build-template.csproj")
 BUILD_GENERATED_CSPROJ = "__Autogenerated_Project.Targets"
 NUGET_EXE = "/usr/bin/nuget.exe"
 
-def parse_build_options(obj):
+TARGET_FRAMEWORK_NETCOREAPP = "netcoreapp1.0"
+
+def find_output(asm, framework):
+  confs = ["Release", "Debug"]
+  for conf in confs:
+    asmfile = os.path.join(asm, "bin", conf, framework, asm + ".dll")
+    if os.path.isfile(asmfile):
+      return asmfile
+  return None
+
+def parse_project_json(asm):
+  jsonfile = os.path.join(asm, 'project.json')
+  jsondata = None
+  if os.path.isfile(jsonfile):
+    fp = open(jsonfile)
+    jsondata = json.load(fp)
+    fp.close()
+  return jsondata
+
+def get_frameworks(asm):
+  frameworks = []
+  obj = parse_project_json(asm)
+  if obj is not None and "frameworks" in obj:
+    frameworks = obj["frameworks"]
+  return frameworks
+
+def convert_build_options(obj):
   elPropertyGroup = ET.Element("PropertyGroup")
+
   if "keyFile" in obj:
     elSignAssembly = ET.Element("SignAssembly")
     elSignAssembly.text = "true"
@@ -22,100 +49,105 @@ def parse_build_options(obj):
     elAssemblyOriginatorKeyFile = ET.Element("AssemblyOriginatorKeyFile")
     elAssemblyOriginatorKeyFile.text = obj["keyFile"]
     elPropertyGroup.append(elAssemblyOriginatorKeyFile)
+
+  if "allowUnsafe" in obj:
+    elAllowUnsafeBlocks = ET.Element("AllowUnsafeBlocks")
+    elAllowUnsafeBlocks.text = str(obj["allowUnsafe"])
+    elPropertyGroup.append(elAllowUnsafeBlocks)
+
   return elPropertyGroup
 
-def parse_compile_items(target):
+def convert_compile_items(target):
   elItemGroup = ET.Element("ItemGroup")
+
   for root, dirnames, filenames in os.walk(target):
     if not root.startswith(os.path.join(target, "obj")):
       for filename in filenames:
         if filename.endswith(".cs"):
           elCompile = ET.Element("Compile", {"Include" : os.path.join(os.path.relpath(root, target), filename)})
           elItemGroup.append(elCompile)
+
   return elItemGroup
 
-def parse_project_json(target, json):
+def convert_project_json(target, obj):
   elProject = ET.Element("Project", {"xmlns": "http://schemas.microsoft.com/developer/msbuild/2003"})
-  if "buildOptions" in json:
-    elBuildOptions = parse_build_options(json["buildOptions"])
+
+  if "buildOptions" in obj:
+    elBuildOptions = convert_build_options(obj["buildOptions"])
     elProject.append(elBuildOptions)
+
   if os.path.isdir(target):
-    elCompileItems = parse_compile_items(target)
+    elCompileItems = convert_compile_items(target)
     elProject.append(elCompileItems)
+
   return elProject
 
 def ready_csproj(asm, csproj):
+  obj = parse_project_json(asm)
+  elProject = convert_project_json(asm, obj)
+  tree = ET.ElementTree(elProject)
+  tree.write(os.path.join(asm, BUILD_GENERATED_CSPROJ), encoding = "utf-8", xml_declaration = True)
   shutil.copy(BUILD_TEMPLATE_CSPROJ, csproj)
-  jsonfile = os.path.join(asm, 'project.json')
-  if os.path.isfile(jsonfile):
-    with open(jsonfile) as jsondata:
-      el = parse_project_json(asm, json.load(jsondata))
-      tree = ET.ElementTree(el)
-      tree.write(os.path.join(asm, BUILD_GENERATED_CSPROJ), encoding = "utf-8", xml_declaration = True)
-      jsondata.close()
 
 def build(csproj, framework, args):
+  if framework == TARGET_FRAMEWORK_NETCOREAPP and args.CoreFxPath is None:
+    return
+
   cmd = ["xbuild", csproj, "/p:TargetFrameworkAlias=" + framework]
+
   if args.Configuration is not None:
     cmd.append("/p:Configuration=" + args.Configuration)
+
   if args.CoreFxPath is not None:
     cmd.append("/p:CoreFxPath=" + args.CoreFxPath)
-  if args.TizenAPIPath is not None:
-    cmd.append("/p:TizenAPIPath=" + args.TizenAPIPath)
+
+  if args.DotnetAssemblyPath is not None:
+    cmd.append("/p:DotnetAssemblyPath=" + os.path.join(args.DotnetAssemblyPath, "devel", framework))
+
   subprocess.check_call(cmd)
 
 def cmd_build(args):
   for asm in args.targets:
     csproj = os.path.join(asm, asm + ".gbsproj")
     ready_csproj(asm, csproj)
-    build(csproj, "net45", args)
-    if args.CoreFxPath is not None:
-      build(csproj, "netcoreapp1.0", args)
-
-def find_output(asm, alias):
-  paths = [
-    [asm, "bin", "Release", alias, asm + ".dll"],
-    [asm, "bin", "Debug", alias, asm + ".dll"]
-  ];
-  for path in paths:
-    asmfile = os.path.join(*path)
-    if os.path.isfile(asmfile):
-      return asmfile
-  return None
+    for fw in get_frameworks(asm):
+      build(csproj, fw, args)
 
 def cmd_install(args):
   for asm in args.targets:
-    asmfile = find_output(asm, "netcoreapp1.0")
-    if asmfile is not None:
-      shutil.copy(asmfile, args.InstallPath)
-      break;
-    asmfile = find_output(asm, "net45")
-    if asmfile is not None:
-      shutil.copy(asmfile, args.InstallPath)
+    skipRuntimeInstall = False
+    for fw in get_frameworks(asm):
+      output = find_output(asm, fw)
+      if output is not None:
+        develdir = os.path.join(args.InstallPath, "devel", fw)
+        os.makedirs(develdir)
+        shutil.copy(output, develdir)
+        if not skipRuntimeInstall:
+          shutil.copy(output, args.InstallPath)
+          if fw == TARGET_FRAMEWORK_NETCOREAPP:
+            skipRuntimeInstall = True
 
 def cmd_pack(args):
     for asm in args.targets:
-        nuspec = os.path.join(asm, asm + ".nuspec")
-        output = ".nuget"
+      nuspec = os.path.join(asm, asm + ".nuspec")
+      output = ".nuget"
+      if os.path.isfile(nuspec):
         # Ready nuspec file
-        if os.path.isfile(nuspec):
-          if not os.path.isdir(output):
-            os.mkdir(output)
-          elPackage = ET.parse(nuspec).getroot()
-          elFiles = elPackage.find("files")
-          if elFiles is None:
-            elFiles = ET.Element("files")
-            asmfile = find_output(asm, "netcoreapp1.0")
-            if asmfile is not None:
-              elFile = ET.Element("file", {"src": asmfile, "target": "lib/netstandard1.6"})
-              elFiles.append(elFile)
-            asmfile = find_output(asm, "net45")
+        if not os.path.isdir(output):
+          os.mkdir(output)
+        elPackage = ET.parse(nuspec).getroot()
+        elFiles = elPackage.find("files")
+        if elFiles is None:
+          elFiles = ET.Element("files")
+          for fw in get_frameworks(asm):
+            asmfile = find_output(asm, fw)
             if asmfile is not None:
-              elFile = ET.Element("file", {"src": asmfile, "target": "lib/net45"})
+              nugetfw = "netstandard1.6" if fw == TARGET_FRAMEWORK_NETCOREAPP else fw
+              elFile = ET.Element("file", {"src": asmfile, "target": "lib/" + nugetfw})
               elFiles.append(elFile)
-            elPackage.append(elFiles)
-          tree = ET.ElementTree(elPackage)
-          tree.write(os.path.join(output, asm + ".nuspec"), encoding = "utf-8", xml_declaration = True)
+          elPackage.append(elFiles)
+        tree = ET.ElementTree(elPackage)
+        tree.write(os.path.join(output, asm + ".nuspec"), encoding = "utf-8", xml_declaration = True)
         # Packaging
         cmd = ["mono", NUGET_EXE, "pack", os.path.join(output, asm + ".nuspec"),
                "-BasePath", ".", "-Version", args.PackageVersion,
@@ -129,7 +161,7 @@ if __name__ == "__main__":
   parser.add_argument("targets", nargs='+')
   parser.add_argument("--Configuration")
   parser.add_argument("--CoreFxPath")
-  parser.add_argument("--TizenAPIPath")
+  parser.add_argument("--DotnetAssemblyPath")
   parser.add_argument("--InstallPath")
   parser.add_argument("--PackageVersion")