Created
February 29, 2016 19:12
-
-
Save swgillespie/f9eb6765518578ddc015 to your computer and use it in GitHub Desktop.
CoreCLR Test Porting Useful Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import subprocess | |
import sys | |
copyright_notice = r'''// Licensed to the .NET Foundation under one or more agreements. | |
// The .NET Foundation licenses this file to you under the MIT license. | |
// See the LICENSE file in the project root for more information. | |
''' | |
csproj = r'''<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> | |
<PropertyGroup> | |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |
<AssemblyName>$(MSBuildProjectName)</AssemblyName> | |
<SchemaVersion>2.0</SchemaVersion> | |
<ProjectGuid>{{95DFC527-4DC1-495E-97D7-E94EE1F7140D}}</ProjectGuid> | |
<OutputType>Exe</OutputType> | |
<AppDesignerFolder>Properties</AppDesignerFolder> | |
<FileAlignment>512</FileAlignment> | |
<ProjectTypeGuids>{{786C830F-07A1-408B-BD7F-6EE04809D6DB}};{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}</ProjectTypeGuids> | |
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> | |
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> | |
<RestorePackages>true</RestorePackages> | |
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> | |
<CLRTestExecutionArguments>{1}</CLRTestExecutionArguments> | |
</PropertyGroup> | |
<!-- Default configurations to help VS understand the configurations --> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |
</PropertyGroup> | |
<ItemGroup> | |
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> | |
<Visible>False</Visible> | |
</CodeAnalysisDependentAssemblyPaths> | |
</ItemGroup> | |
<PropertyGroup> | |
<!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. --> | |
<DebugType>PdbOnly</DebugType> | |
<NoLogo>True</NoLogo> | |
<DefineConstants>$(DefineConstants)</DefineConstants> | |
</PropertyGroup> | |
<ItemGroup> | |
<Compile Include="{0}" /> | |
</ItemGroup> | |
<ItemGroup> | |
<None Include="app.config" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Service Include="{{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}}" /> | |
</ItemGroup> | |
<PropertyGroup> | |
<ProjectJson>project.json</ProjectJson> | |
<ProjectLockJson>project.lock.json</ProjectLockJson> | |
</PropertyGroup> | |
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> | |
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> | |
</PropertyGroup> | |
</Project> | |
''' | |
qa_clr = r'F:\E\NetFXDev1\src\QA\CLR\testsrc' | |
coreclr = r'C:\Users\segilles\Documents\GitHub\coreclr\tests\src' | |
def copy_file(smarty_column): | |
command, *args = smarty_column.split(' ') | |
pre = os.path.splitext(command)[0] | |
cs = pre + '.cs' | |
*unused, cs_last = cs.split(os.sep) | |
qa_path = os.path.join(qa_clr, cs) | |
coreclr_path = os.path.join(coreclr, cs) | |
if not os.path.isfile(coreclr_path): | |
print('Copying {} to {}'.format(qa_path, coreclr_path)) | |
copy_with_copyright(qa_path, coreclr_path) | |
else: | |
print('{} already exists, not copying'.format(coreclr_path)) | |
csproj_path = os.path.join(coreclr, pre + '.csproj') | |
print('Generating {}'.format(csproj_path)) | |
actual_path = generate_csproj(csproj_path, cs_last, args) | |
print('Building csproj just to see how it goes...') | |
try: | |
subprocess.check_output('msbuild {}'.format(actual_path)) | |
except: | |
print('Msbuild failed! You should check that out.') | |
else: | |
print('Msbuild was clean') | |
def copy_with_copyright(src, dest): | |
with open(src, 'r') as s: | |
with open(dest, 'w+') as d: | |
d.write(copyright_notice) | |
d.write(s.read()) | |
def generate_csproj(csproj_path, csfile, arguments): | |
print('csproj arguments: {}'.format(' '.join(arguments))) | |
original_path, original_ext = os.path.splitext(csproj_path) | |
x = 1 | |
while os.path.isfile(csproj_path): | |
print('csproj exists. trying numeric suffixes') | |
csproj_path = original_path + '_{}'.format(x) + original_ext | |
x += 1 | |
print('settled on name: {}'.format(csproj_path)) | |
with open(csproj_path, 'w+') as f: | |
f.write(csproj.format(csfile, ' '.join(arguments))) | |
return csproj_path | |
def main(smarty_path): | |
copy_file(smarty_path) | |
if __name__ == '__main__': | |
main(sys.argv[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def parse_smarty(smarty_file): | |
with open(smarty_file, 'r') as f: | |
lines = f.readlines() | |
for line in lines: | |
if r'C:\USERS\SEGILLES\DESKTOP\SMARTY\TESTS.LST' in line: | |
yield parse_line(line) | |
def parse_line(line): | |
first_split = line.split('#')[1] | |
second_split = first_split.split('CATS:') | |
name = second_split[0].strip() | |
categories = second_split[1].split('UA:')[0].split(';') | |
return { 'name': name, 'categories': categories } | |
def to_csv(smarty_generator): | |
header = 'TestName,Categories\n' | |
for test in smarty_generator: | |
header += '"{}","{}"\n'.format(test['name'], ','.join(test['categories'])) | |
with open('smarty.csv', 'w+') as f: | |
f.write(header) | |
if __name__ == '__main__': | |
to_csv(parse_smarty(sys.argv[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment