-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[csharp] Port csharp scripts in src/ to .NET projects. (#21498)
- Loading branch information
1 parent
e581020
commit f11253b
Showing
22 changed files
with
256 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Scripts | ||
|
||
This directory contains numerous short C# scripts, each in their own directory | ||
with its own project file. | ||
|
||
To create a new script, the easy way is to run the `new-script.sh` script. | ||
|
||
The harder way is to copy an existing script directory, and: | ||
|
||
* Rename the csproj file to match the directory name. | ||
* Add your C# code, and document what it's supposed to do in a README.md file. | ||
* Edit the arguments to the `TemplateScript` template in the `fragment.mk` | ||
file according to how you named your script (directory). The first argument | ||
will be used in other makefiles that use the script, the second is the name | ||
of the script (directory). Say your script is `my-script`, then that would be: | ||
|
||
```make | ||
$(eval $(call TemplateScript,MY_SCRIPT,my-script)) | ||
|
||
To use the new script: | ||
|
||
1. In the consuming `Makefile`, import the `fragment.mk` file from the script directory: | ||
|
||
```make | ||
include $(TOP)/scripts/my-script/fragment.mk | ||
``` | ||
|
||
2. In the target where you want to execute the script, depend on the script executable, which is named `MY_SCRIPT` (from the call to the `TemplateScript` template): | ||
|
||
```make | ||
dostuff: $(MY_SCRIPT) | ||
echo "Doing stuff" | ||
``` | ||
|
||
This makes sure the script is actually built before you want to execute it. | ||
|
||
3. The actual invocation to call the script, is the same variable, but with `_EXEC` appended: | ||
|
||
```make | ||
dostuff: $(MY_SCRIPT) | ||
$(MY_SCRIPT_EXEC) --arguments to/my/script | ||
``` | ||
|
||
Sidenote: if https://github.com/dotnet/designs/pull/296 were ever implemented, | ||
we could dispense with the project file, making these C# files actual 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# generate-defines | ||
|
||
This script takes the list of frameworks that are supported for a given | ||
platform, and generates a response file for the C# compiler with a | ||
`HAS_<framework>` define for each framework. | ||
|
||
Example output file for iOS: | ||
|
||
``` | ||
-d:HAS_ACCELERATE | ||
-d:HAS_ACCESSIBILITY | ||
-d:HAS_ACCESSORYSETUPKIT | ||
-d:HAS_ACCOUNTS | ||
[...] | ||
-d:HAS_WEBKIT | ||
-d:HAS_XKIT | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include $(TOP)/scripts/template.mk | ||
$(eval $(call TemplateScript,GENERATE_DEFINES,generate-defines)) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# generate-errors | ||
|
||
This script takes a resource resx as input, and generates a C# file with constants for each resource string (which won't be localizable, because they're constant strings). | ||
|
||
Example input: | ||
|
||
```xml | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<data name="BI0000" xml:space="preserve"> | ||
<value>Unexpected error - Please fill a bug report at https://github.com/xamarin/xamarin-macios/issues/new</value> | ||
</data> | ||
</root> | ||
``` | ||
|
||
Example output: | ||
|
||
```cs | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool: generate-errors.csharp | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
namespace Xamarin.Bundler { | ||
internal class Errors { | ||
internal const string MT0000 = "Unexpected error - Please fill a bug report at https://github.com/xamarin/xamarin-macios/issues/new"; | ||
} | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include $(TOP)/scripts/template.mk | ||
$(eval $(call TemplateScript,GENERATE_ERRORS,generate-errors)) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# generate-frameworks | ||
|
||
This script takes the list of frameworks that are supported for all platforms, | ||
and generates a C# file with a hashtable of all the frameworks for each | ||
platform. | ||
|
||
Example output file for iOS: | ||
|
||
```cs | ||
using System.Collections.Generic; | ||
|
||
partial class Frameworks { | ||
internal readonly HashSet<string> iosframeworks = new HashSet<string> { | ||
"Accelerate", | ||
"Accessibility", | ||
"AccessorySetupKit", | ||
/// ... | ||
"WebKit", | ||
"XKit", | ||
}; | ||
internal readonly HashSet<string> macosframeworks = new HashSet<string> { | ||
"Accelerate", | ||
"Accessibility", | ||
/// ... | ||
"WebKit", | ||
"XKit", | ||
}; | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include $(TOP)/scripts/template.mk | ||
$(eval $(call TemplateScript,GENERATE_FRAMEWORKS,generate-frameworks)) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# generate-sourcelink-json | ||
|
||
This script generates a SourceLink.json file that maps paths of local source | ||
code into links to GitHub source code. | ||
|
||
This SourceLink.json file is then passed to the C# compiler, which embeds it | ||
in the pdb file, and which is then consumed by debuggers or IDEs to find the | ||
source code online for any given source file the pdb refers to. | ||
|
||
Example output file: | ||
|
||
```json | ||
{ | ||
"documents": { | ||
"/local/path/to/xamarin-macios/src*": "https://raw.githubusercontent.com/xamarin/xamarin-macios/c2c617bf000c4ff864cbba9d65421f915941136b/src*" | ||
} | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include $(TOP)/scripts/template.mk | ||
$(eval $(call TemplateScript,GENERATE_SOURCELINK_JSON,generate-sourcelink-json)) |
15 changes: 15 additions & 0 deletions
15
scripts/generate-sourcelink-json/generate-sourcelink-json.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.IO; | ||
using System.Text; | ||
|
||
var idx = 0; | ||
var latestCommit = args [idx++]; | ||
var src = args [idx++]; | ||
var outputPath = args [idx++]; | ||
|
||
using (var writer = new StreamWriter (outputPath)) { | ||
writer.WriteLine ("{"); | ||
writer.WriteLine (" \"documents\": {"); | ||
writer.WriteLine ($" \"{src}*\": \"https://raw.githubusercontent.com/xamarin/xamarin-macios/{latestCommit}/src*\""); | ||
writer.WriteLine (" }"); | ||
writer.WriteLine ("}"); | ||
} |
5 changes: 5 additions & 0 deletions
5
scripts/generate-sourcelink-json/generate-sourcelink-json.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash -e | ||
|
||
echo 'Run this script to create a new script!' | ||
|
||
echo "" | ||
if test -z "$SCRIPT_NAME"; then | ||
read -p "What's the name of your new script? " SCRIPT_NAME | ||
if test -z "$SCRIPT_NAME"; then | ||
echo "Exiting, no script name provided" | ||
exit 0 | ||
fi | ||
fi | ||
|
||
echo "Name of the new script: $SCRIPT_NAME" | ||
|
||
UPPER_NAME=$(echo "$SCRIPT_NAME" | tr 'a-z' "A-Z" | tr '-' '_') | ||
echo "Variable name: $UPPER_NAME" | ||
|
||
mkdir -p "$SCRIPT_NAME" | ||
|
||
printf 'include $(TOP)/scripts/template.mk\n' > "$SCRIPT_NAME/fragment.mk" | ||
printf "\$(eval \$(call TemplateScript,$UPPER_NAME,$SCRIPT_NAME))\n" >> "$SCRIPT_NAME/fragment.mk" | ||
|
||
printf '<Project Sdk="Microsoft.NET.Sdk">\n' > "$SCRIPT_NAME/$SCRIPT_NAME.csproj" | ||
printf ' <PropertyGroup>\n' >> "$SCRIPT_NAME/$SCRIPT_NAME.csproj" | ||
printf ' <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework>\n' >> "$SCRIPT_NAME/$SCRIPT_NAME.csproj" | ||
printf ' </PropertyGroup>\n' >> "$SCRIPT_NAME/$SCRIPT_NAME.csproj" | ||
printf '</Project>\n' >> "$SCRIPT_NAME/$SCRIPT_NAME.csproj" | ||
|
||
printf "Console.WriteLine (\"Hello $SCRIPT_NAME\");\n" > "$SCRIPT_NAME/$SCRIPT_NAME.cs" | ||
|
||
printf "# $SCRIPT_NAME\n" > "$SCRIPT_NAME/README.md" | ||
|
||
echo "Your new script is located in ./$SCRIPT_NAME. Read the README.md in this directory for how to use it." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# versions-check | ||
|
||
This script verifies the OS versions listed in `xamarin-macios/builds/Versions-<platform>.list.in`: | ||
|
||
* No versions below the minimum deployment target. | ||
* Both minimum deployment target and current deployment target must be listed. | ||
* That the `SupportedTargetPlatformVersions` list is coherent with the | ||
`KnownVersions` list (all versions in `KnownVersions` must also be in | ||
`SupportedTargetPlatformVersions`). |
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
Oops, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.