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"
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,
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")