Support globs in csproj includes

This commit is contained in:
Ignacio Etcheverry 2018-10-22 19:20:29 +02:00
parent 454b933106
commit 611a476224
6 changed files with 125 additions and 13 deletions

View File

@ -38,7 +38,7 @@ matrix:
- mono
packages:
- &linux_deps [libasound2-dev, libfreetype6-dev, libgl1-mesa-dev, libglu1-mesa-dev, libx11-dev, libxcursor-dev, libxi-dev, libxinerama-dev, libxrandr-dev]
- &linux_mono_deps [mono-devel, msbuild]
- &linux_mono_deps [mono-devel, msbuild, nuget]
coverity_scan:
project:

View File

@ -102,6 +102,75 @@ env_mono = conf.Finish()
import os
def find_nuget_unix():
import os.path
import sys
hint_dirs = ['/opt/novell/mono/bin']
if sys.platform == 'darwin':
hint_dirs = ['/Library/Frameworks/Mono.framework/Versions/Current/bin', '/usr/local/var/homebrew/linked/mono/bin'] + hint_dirs
for hint_dir in hint_dirs:
hint_path = os.path.join(hint_dir, 'nuget')
if os.path.isfile(hint_path):
return hint_path
elif os.path.isfile(hint_path + '.exe'):
return hint_path + '.exe'
for hint_dir in os.environ['PATH'].split(os.pathsep):
hint_dir = hint_dir.strip('"')
hint_path = os.path.join(hint_dir, 'nuget')
if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK):
return hint_path
if os.path.isfile(hint_path + '.exe') and os.access(hint_path + '.exe', os.X_OK):
return hint_path + '.exe'
return None
def find_nuget_windows():
import mono_reg_utils as monoreg
mono_root = ''
bits = env['bits']
if bits == '32':
if os.getenv('MONO32_PREFIX'):
mono_root = os.getenv('MONO32_PREFIX')
else:
mono_root = monoreg.find_mono_root_dir(bits)
else:
if os.getenv('MONO64_PREFIX'):
mono_root = os.getenv('MONO64_PREFIX')
else:
mono_root = monoreg.find_mono_root_dir(bits)
if mono_root:
mono_bin_dir = os.path.join(mono_root, 'bin')
nuget_mono = os.path.join(mono_bin_dir, 'nuget.bat')
if os.path.isfile(nuget_mono):
return nuget_mono
# Standalone NuGet
for hint_dir in os.environ['PATH'].split(os.pathsep):
hint_dir = hint_dir.strip('"')
hint_path = os.path.join(hint_dir, 'nuget.exe')
if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK):
return hint_path
if 'NUGET_PATH' in os.environ:
hint_path = os.environ['NUGET_PATH']
if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK):
return hint_path
hint_path = os.path.join(hint_path, 'nuget.exe')
if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK):
return hint_path
return None
def find_msbuild_unix(filename):
import os.path
import sys
@ -176,14 +245,17 @@ def mono_build_solution(source, target, env):
import mono_reg_utils as monoreg
from shutil import copyfile
framework_path = ''
sln_path = os.path.abspath(str(source[0]))
target_path = os.path.abspath(str(target[0]))
framework_path = ''
msbuild_env = os.environ.copy()
# Needed when running from Developer Command Prompt for VS
if 'PLATFORM' in msbuild_env:
del msbuild_env['PLATFORM']
# Find MSBuild
if os.name == 'nt':
msbuild_info = find_msbuild_windows()
if msbuild_info is None:
@ -213,11 +285,27 @@ def mono_build_solution(source, target, env):
print('MSBuild path: ' + msbuild_path)
# Find NuGet
nuget_path = find_nuget_windows() if os.name == 'nt' else find_nuget_unix()
if nuget_path is None:
raise RuntimeError('Cannot find NuGet executable')
print('NuGet path: ' + nuget_path)
# Do NuGet restore
try:
subprocess.check_call([nuget_path, 'restore', sln_path])
except subprocess.CalledProcessError:
raise RuntimeError('GodotSharpTools: NuGet restore failed')
# Build solution
build_config = 'Release'
msbuild_args = [
msbuild_path,
os.path.abspath(str(source[0])),
sln_path,
'/p:Configuration=' + build_config,
]
@ -227,20 +315,24 @@ def mono_build_solution(source, target, env):
try:
subprocess.check_call(msbuild_args, env=msbuild_env)
except subprocess.CalledProcessError:
raise RuntimeError('GodotSharpTools build failed')
raise RuntimeError('GodotSharpTools: Build failed')
src_dir = os.path.abspath(os.path.join(str(source[0]), os.pardir, 'bin', build_config))
dst_dir = os.path.abspath(os.path.join(str(target[0]), os.pardir))
# Copy files
src_dir = os.path.abspath(os.path.join(sln_path, os.pardir, 'bin', build_config))
dst_dir = os.path.abspath(os.path.join(target_path, os.pardir))
asm_file = 'GodotSharpTools.dll'
if not os.path.isdir(dst_dir):
if os.path.exists(dst_dir):
raise RuntimeError('Target directory is a file')
os.makedirs(dst_dir)
asm_file = 'GodotSharpTools.dll'
copyfile(os.path.join(src_dir, asm_file), os.path.join(dst_dir, asm_file))
# Dependencies
copyfile(os.path.join(src_dir, "DotNet.Glob.dll"), os.path.join(dst_dir, "DotNet.Glob.dll"))
if env['tools']:
output_dir = Dir('#bin').abspath
editor_tools_dir = os.path.join(output_dir, 'GodotSharp', 'Tools')

View File

@ -31,6 +31,9 @@
<Reference Include="System" />
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="DotNet.Glob, Version=2.1.1.0, Culture=neutral, PublicKeyToken=b68cc888b4f632d1, processorArchitecture=MSIL">
<HintPath>packages\DotNet.Glob.2.1.1\lib\net45\DotNet.Glob.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="StringExtensions.cs" />
@ -43,5 +46,8 @@
<Compile Include="Utils\OS.cs" />
<Compile Include="Editor\GodotSharpExport.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,4 +1,5 @@
using System;
using DotNet.Globbing;
using Microsoft.Build.Construction;
namespace GodotSharpTools.Project
@ -7,7 +8,10 @@ namespace GodotSharpTools.Project
{
public static bool HasItem(this ProjectRootElement root, string itemType, string include)
{
string includeNormalized = include.NormalizePath();
GlobOptions globOptions = new GlobOptions();
globOptions.Evaluation.CaseInsensitive = false;
string normalizedInclude = include.NormalizePath();
foreach (var itemGroup in root.ItemGroups)
{
@ -16,10 +20,14 @@ namespace GodotSharpTools.Project
foreach (var item in itemGroup.Items)
{
if (item.ItemType == itemType)
if (item.ItemType != itemType)
continue;
var glob = Glob.Parse(item.Include.NormalizePath(), globOptions);
if (glob.IsMatch(normalizedInclude))
{
if (item.Include.NormalizePath() == includeNormalized)
return true;
return true;
}
}
}

View File

@ -36,7 +36,9 @@ namespace GodotSharpTools
public static bool IsAbsolutePath(this string path)
{
return path.StartsWith("/") || path.StartsWith("\\") || path.StartsWith(driveRoot);
return path.StartsWith("/", StringComparison.Ordinal) ||
path.StartsWith("\\", StringComparison.Ordinal) ||
path.StartsWith(driveRoot, StringComparison.Ordinal);
}
public static string CsvEscape(this string value, char delimiter = ',')

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNet.Glob" version="2.1.1" targetFramework="net45" />
</packages>