Skip to content

Commit

Permalink
Move generator over to microsoft/typespec (#3175)
Browse files Browse the repository at this point in the history
Fixes #3173
  • Loading branch information
m-nash committed Apr 22, 2024
1 parent fa540a9 commit d2292f0
Show file tree
Hide file tree
Showing 381 changed files with 19,395 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,4 @@ docs/**/js-api/

# csharp emitter
!packages/http-client-csharp/package-lock.json
packages/http-client-csharp/generator/artifacts/
36 changes: 30 additions & 6 deletions eng/common/scripts/Analyze-Changes.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,51 @@ Describe 'Analyze-Changes' {
}

It 'Should return package variables if package specific changes are detected' {
$variables = Get-ActiveVariables @(
$actual = Get-ActiveVariables @(
"packages/http-client-csharp/src/constants.ts"
)

$variables | Should -Be 'RunCSharp'
$expected = @('RunCSharp')

$actual | ForEach-Object {
$_ | Should -BeIn $expected
}
}

It 'Should return RunCore if common files are changed' {
$variables = Get-ActiveVariables @(
$actual = Get-ActiveVariables @(
"packages/compiler/package.json"
)

$variables | Should -Be 'RunCore'
$expected = @('RunCore')

$actual | ForEach-Object {
$_ | Should -BeIn $expected
}
}

It 'Should return a combination of core and isolated packages' {
$variables = Get-ActiveVariables @(
$actual = Get-ActiveVariables @(
"packages/http-client-csharp/src/constants.ts",
"packages/compiler/package.json"
)

$variables | Should -Be 'RunCore', 'RunCSharp'
$expected = @('RunCore', 'RunCSharp')

$actual | ForEach-Object {
$_ | Should -BeIn $expected
}
}

It 'Should return RunCSharp and RunCore if .editorconfig is changed' {
$actual = Get-ActiveVariables @(
".editorconfig"
)

$expected = @('RunCore', 'RunCSharp')

$actual | ForEach-Object {
$_ | Should -BeIn $expected
}
}
}
21 changes: 13 additions & 8 deletions eng/common/scripts/Analyze-Changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ param(

# Represents an isolated package which has its own stages in typespec - ci pipeline
class IsolatedPackage {
[string] $Path
[string[]] $Paths
[string] $RunVariable
[bool] $RunValue

IsolatedPackage([string]$path, [string]$runVariable, [bool]$runValue) {
$this.Path = $path
IsolatedPackage([string[]]$paths, [string]$runVariable, [bool]$runValue) {
$this.Paths = $paths
$this.RunVariable = $runVariable
$this.RunValue = $runValue
}
}

# Emitter packages in the repo
$isolatedPackages = @{
"http-client-csharp" = [IsolatedPackage]::new("packages/http-client-csharp", "RunCSharp", $false)
"http-client-java" = [IsolatedPackage]::new("packages/http-client-java", "RunJava", $false)
"http-client-typescript" = [IsolatedPackage]::new("packages/http-client-typescript", "RunTypeScript", $false)
"http-client-python" = [IsolatedPackage]::new("packages/http-client-python", "RunPython", $false)
"http-client-csharp" = [IsolatedPackage]::new(@("packages/http-client-csharp", ".editorconfig"), "RunCSharp", $false)
"http-client-java" = [IsolatedPackage]::new(@("packages/http-client-java"), "RunJava", $false)
"http-client-typescript" = [IsolatedPackage]::new(@("packages/http-client-typescript"), "RunTypeScript", $false)
"http-client-python" = [IsolatedPackage]::new(@("packages/http-client-python"), "RunPython", $false)
}

# A tree representation of a set of files
Expand Down Expand Up @@ -125,7 +125,12 @@ function Get-ActiveVariables($changes) {
if (-not $runIsolated) {
# set each isolated package flag
foreach ($package in $isolatedPackages.Values) {
$package.RunValue = $root.PathExists($package.Path)
foreach ($path in $package.Paths) {
$package.RunValue = $package.RunValue -or $root.PathExists($path)
if ($package.RunValue) {
break
}
}
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, mergeConfig } from "vitest/config";
import { defaultTypeSpecVitestConfig } from "../../vitest.workspace.js";
import { defaultTypeSpecVitestConfig } from "../../../vitest.workspace.js";

export default mergeConfig(defaultTypeSpecVitestConfig, defineConfig({}));
217 changes: 217 additions & 0 deletions packages/http-client-csharp/eng/CodeAnalysis.ruleset

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/http-client-csharp/eng/scripts/Build-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ if ($BuildNumber) {
Push-Location "$packageRoot"
try {
Write-Host "Working in $PWD"

# TODO this is happening 4 times until ..... gets fixed
Invoke-LoggedCommand "dotnet build ./generator" -GroupOutput

Invoke-LoggedCommand "npm run build" -GroupOutput

if ($BuildNumber) {
Expand Down
13 changes: 13 additions & 0 deletions packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Requires -Version 7.0

Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force;

$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..' 'generator')
$mgcArtifactRoot = Join-Path $repoRoot 'artifacts' 'bin' 'Microsoft.Generator.CSharp' 'Debug' 'net8.0'
$clientModelTestProjectsDirectory = Join-Path $repoRoot 'Microsoft.Generator.CSharp.ClientModel.TestProjects'

Invoke "dotnet build $repoRoot"

$mgcPath = Join-Path $mgcArtifactRoot "Microsoft.Generator.CSharp"
$unbrandedTypespecTestProject = Join-Path $clientModelTestProjectsDirectory "Unbranded-TypeSpec"
Invoke "$mgcPath $unbrandedTypespecTestProject"
22 changes: 22 additions & 0 deletions packages/http-client-csharp/eng/scripts/Generation.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..')

function Invoke($command, $executePath=$repoRoot)
{
Write-Host "> $command"
Push-Location $executePath
if ($IsLinux -or $IsMacOs)
{
sh -c "$command 2>&1"
}
else
{
cmd /c "$command 2>&1"
}
Pop-Location

if($LastExitCode -ne 0)
{
Write-Error "Command failed to execute: $command"
}
}
Export-ModuleMember -Function "Invoke"
11 changes: 11 additions & 0 deletions packages/http-client-csharp/eng/scripts/Initialize-Repository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ try {
Remove-Item -Recurse -Force "./node_modules"
}

# install dotnet
if ($IsWindows) {
# download and run https://dot.net/v1/dotnet-install.ps1
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile 'dotnet-install.ps1'
./dotnet-install.ps1 -Version '8.0.204'
}
else {
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.sh' -OutFile 'dotnet-install.sh'
bash ./dotnet-install.sh --version 8.0.204
}

# install and list npm packages

if ($BuildArtifactsPath) {
Expand Down
5 changes: 4 additions & 1 deletion packages/http-client-csharp/eng/scripts/Test-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ Set-ConsoleEncoding
Push-Location $packageRoot
try {
if ($UnitTests) {
# test the emitter
Push-Location "$packageRoot"
try {
# test the emitter
Invoke-LoggedCommand "npm run build" -GroupOutput
Invoke-LoggedCommand "npm run test" -GroupOutput

# test the generator
Invoke-LoggedCommand "dotnet test ./generator" -GroupOutput
}
finally {
Pop-Location
Expand Down
13 changes: 13 additions & 0 deletions packages/http-client-csharp/eng/stylecop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} License.",
"companyName": "Microsoft Corporation",
"xmlHeader": false,
"variables": {
"licenseName": "MIT"
}
}
}
}
Loading

0 comments on commit d2292f0

Please sign in to comment.