create_nuget.py 4.54 KB
Newer Older
1
2
# coding: utf-8
"""Script for generating files with NuGet package metadata."""
3
import datetime
Guolin Ke's avatar
Guolin Ke committed
4
5
import os
import sys
Guolin Ke's avatar
Guolin Ke committed
6
7
8
9
10
from distutils.file_util import copy_file

if __name__ == "__main__":
    source = sys.argv[1]
    current_dir = os.path.abspath(os.path.dirname(__file__))
11
12
13
14
15
16
17
18
19
    linux_folder_path = os.path.join(current_dir, "runtimes", "linux-x64", "native")
    if not os.path.exists(linux_folder_path):
        os.makedirs(linux_folder_path)
    osx_folder_path = os.path.join(current_dir, "runtimes", "osx-x64", "native")
    if not os.path.exists(osx_folder_path):
        os.makedirs(osx_folder_path)
    windows_folder_path = os.path.join(current_dir, "runtimes", "win-x64", "native")
    if not os.path.exists(windows_folder_path):
        os.makedirs(windows_folder_path)
Guolin Ke's avatar
Guolin Ke committed
20
21
22
    build_folder_path = os.path.join(current_dir, "build")
    if not os.path.exists(build_folder_path):
        os.makedirs(build_folder_path)
23
24
25
    copy_file(os.path.join(source, "lib_lightgbm.so"), os.path.join(linux_folder_path, "lib_lightgbm.so"))
    copy_file(os.path.join(source, "lib_lightgbm.dylib"), os.path.join(osx_folder_path, "lib_lightgbm.dylib"))
    copy_file(os.path.join(source, "lib_lightgbm.dll"), os.path.join(windows_folder_path, "lib_lightgbm.dll"))
Guolin Ke's avatar
Guolin Ke committed
26
    copy_file(os.path.join(source, "lightgbm.exe"), os.path.join(windows_folder_path, "lightgbm.exe"))
Guolin Ke's avatar
Guolin Ke committed
27
    version = open(os.path.join(current_dir, os.path.pardir, 'VERSION.txt')).read().strip().replace('rc', '-rc')
28
    nuget_str = r"""<?xml version="1.0"?>
Guolin Ke's avatar
Guolin Ke committed
29
30
31
32
33
34
    <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
    <metadata>
        <id>LightGBM</id>
        <version>%s</version>
        <authors>Guolin Ke</authors>
        <owners>Guolin Ke</owners>
35
36
        <licenseUrl>https://github.com/microsoft/LightGBM/blob/master/LICENSE</licenseUrl>
        <projectUrl>https://github.com/microsoft/LightGBM</projectUrl>
Guolin Ke's avatar
Guolin Ke committed
37
38
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>A fast, distributed, high performance gradient boosting framework</description>
39
        <copyright>Copyright %d @ Microsoft</copyright>
Guolin Ke's avatar
Guolin Ke committed
40
41
42
43
        <tags>machine-learning data-mining distributed native boosting gbdt</tags>
        <dependencies> </dependencies>
    </metadata>
        <files>
Guolin Ke's avatar
Guolin Ke committed
44
        <file src="build\**" target="build"/>
Guolin Ke's avatar
Guolin Ke committed
45
46
47
        <file src="runtimes\**" target="runtimes"/>
        </files>
    </package>
48
49
    """ % (version, datetime.datetime.now().year)
    prop_str = r"""
Guolin Ke's avatar
Guolin Ke committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup Condition="Exists('packages.config') OR
                            Exists('$(MSBuildProjectName).packages.config') OR
                            Exists('packages.$(MSBuildProjectName).config')">
        <Content Include="$(MSBuildThisFileDirectory)/../runtimes/win-x64/native/*.dll"
                Condition="'$(PlatformTarget)' == 'x64'">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <Visible>false</Visible>
        </Content>
        <Content Include="$(MSBuildThisFileDirectory)/../runtimes/win-x64/native/*.exe"
                Condition="'$(PlatformTarget)' == 'x64'">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <Visible>false</Visible>
        </Content>
    </ItemGroup>
    </Project>
66
67
    """
    target_str = r"""
Guolin Ke's avatar
Guolin Ke committed
68
69
70
71
72
73
74
75
76
77
78
79
80
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <EnableLightGBMUnsupportedPlatformTargetCheck Condition="'$(EnableLightGBMUnsupportedPlatformTargetCheck)' == ''">true</EnableLightGBMUnsupportedPlatformTargetCheck>
    </PropertyGroup>
    <Target Name="_LightGBMCheckForUnsupportedPlatformTarget"
            Condition="'$(EnableLightGBMUnsupportedPlatformTargetCheck)' == 'true'"
            AfterTargets="_CheckForInvalidConfigurationAndPlatform">
        <Error Condition="'$(PlatformTarget)' != 'x64' AND
                        ('$(OutputType)' == 'Exe' OR '$(OutputType)'=='WinExe') AND
                        !('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(PlatformTarget)' == '')"
            Text="LightGBM currently supports 'x64' processor architectures. Please ensure your application is targeting 'x64'." />
    </Target>
    </Project>
81
    """
Guolin Ke's avatar
Guolin Ke committed
82
83
    with open(os.path.join(current_dir, "LightGBM.nuspec"), "w") as nuget_file:
        nuget_file.write(nuget_str)
Guolin Ke's avatar
Guolin Ke committed
84
85
86
87
    with open(os.path.join(current_dir, "build", "LightGBM.props"), "w") as prop_file:
        prop_file.write(prop_str)
    with open(os.path.join(current_dir, "build", "LightGBM.targets"), "w") as target_file:
        target_file.write(target_str)