Skip to content

Commit b677107

Browse files
committed
Merged PR 728582: Add scripts for running unit tests and preparing the native package for macOS
- Add scripts for producing a public package for the native runtime. - Add scripts to run unit tests under macOS. - Created a new package here instead of re-using the existing one to avoid removing the old kext code in case we want to use it in the future. We'll have code that references the kext in dscript once I finish making the changes here but they won't be used for anything. Related work items: #2082091
1 parent 47c2c05 commit b677107

File tree

6 files changed

+498
-0
lines changed

6 files changed

+498
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# Prepares the BuildXL macOS native library into the nuget package template
3+
# After running this script, call nuget pack on the output directory to create the nuget package
4+
5+
# 'Microsoft.BuildXL' prefix used here because this library does not have any microsoft internal dependencies
6+
# so a separate internal version is not needed.
7+
readonly PKG_BASE_NAME=Microsoft.BuildXL.Interop.Runtime.osx-x64
8+
readonly INTEROP_DYLIB_NAME=libBuildXLInterop.dylib
9+
10+
arg_packageVersion=""
11+
arg_interopBuildDirectory=""
12+
arg_outputDirectory=""
13+
14+
parseArgs() {
15+
while [[ $# -gt 0 ]]; do
16+
cmd="$1"
17+
case $cmd in
18+
--packageVersion)
19+
arg_packageVersion="$2"
20+
shift
21+
;;
22+
--interopBuildDirectory)
23+
arg_interopBuildDirectory="$2"
24+
shift
25+
;;
26+
--outputDirectory)
27+
arg_outputDirectory="$2"
28+
shift
29+
;;
30+
*)
31+
shift
32+
;;
33+
esac
34+
done
35+
}
36+
37+
parseArgs $@
38+
39+
if [[ "$arg_packageVersion" == "" || "$arg_interopBuildDirectory" == "" || "$arg_outputDirectory" == "" ]]; then
40+
echo "Usage: $0 --packageVersion <version> --interopBuildDirectory <path> --outputDirectory <path>"
41+
exit 1
42+
fi
43+
44+
# Create the output directory (and any intermediate directories) if it doesn't already exist (-p flag will not error if it already exists)
45+
mkdir -p $arg_outputDirectory
46+
47+
# Clean output directory if it already contains files
48+
rm -rf $arg_outputDirectory/*
49+
50+
# Create directory structure
51+
mkdir -p $arg_outputDirectory/runtimes/osx-x64/native/debug
52+
mkdir -p $arg_outputDirectory/runtimes/osx-x64/native/release
53+
54+
# Copy the interop dylib to the output directory
55+
cp $arg_interopBuildDirectory/Build/Products/debug/$INTEROP_DYLIB_NAME $arg_outputDirectory/runtimes/osx-x64/native/debug/$INTEROP_DYLIB_NAME
56+
cp $arg_interopBuildDirectory/Build/Products/release/$INTEROP_DYLIB_NAME $arg_outputDirectory/runtimes/osx-x64/native/release/$INTEROP_DYLIB_NAME
57+
58+
# Write nuspec file
59+
tee $arg_outputDirectory/$PKG_BASE_NAME.nuspec <<EOF
60+
<?xml version="1.0" encoding="utf-8"?>
61+
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
62+
<metadata minClientVersion="2.12">
63+
<id>$PKG_BASE_NAME</id>
64+
<version>$arg_packageVersion</version>
65+
<title>$PKG_BASE_NAME</title>
66+
<authors>Microsoft</authors>
67+
<owners>microsoft,buildxl,bxl</owners>
68+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
69+
<description>The BuildXL interop runtime library for macOS. The package contains debug and release binaries.</description>
70+
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
71+
<serviceable>true</serviceable>
72+
</metadata>
73+
</package>
74+
EOF

Private/macOS/xcodebuild.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Copyright (c) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
5+
### Builds the macOS native library using xcode
6+
7+
arg_projectPath=""
8+
arg_scheme=""
9+
arg_configuration=""
10+
arg_outputDirectory=""
11+
arg_bundlePath=""
12+
13+
parseArgs() {
14+
while [[ $# -gt 0 ]]; do
15+
cmd="$1"
16+
case $cmd in
17+
--projectPath)
18+
arg_projectPath="$2"
19+
shift
20+
;;
21+
--scheme)
22+
arg_scheme="$2"
23+
shift
24+
;;
25+
--configuration)
26+
arg_configuration="$2"
27+
shift
28+
;;
29+
--outputDirectory)
30+
arg_outputDirectory="$2"
31+
shift
32+
;;
33+
--bundlePath)
34+
arg_bundlePath="$2"
35+
shift
36+
;;
37+
*)
38+
shift
39+
;;
40+
esac
41+
done
42+
}
43+
44+
parseArgs $@
45+
46+
if [[ "$arg_projectPath" == "" || "$arg_scheme" == "" || "$arg_configuration" == "" || "$arg_outputDirectory" == "" || "$arg_bundlePath" == "" ]]; then
47+
echo "Usage: $0 --projectPath <path> --scheme <scheme> --configuration <configuration> --outputDirectory <path> --bundlePath <path>"
48+
exit 1
49+
fi
50+
51+
/usr/bin/xcodebuild build -project $arg_projectPath -scheme $arg_scheme -configuration $arg_configuration -derivedDataPath $arg_outputDirectory -xcconfig $arg_bundlePath -UseModernBuildSystem=YES

Public/Src/Cache/Logging/Test/MdmOperationLoggerTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
namespace BuildXL.Cache.Logging.Test
2020
{
21+
// Microsoft.Cloud.InstrumentationFramework requires Windows.
22+
[Trait("Category", "WindowsOSOnly")]
2123
public class MdmOperationLoggerTests
2224
{
2325
[Fact]
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
import {Transformer} from "Sdk.Transformers";
5+
import * as Deployment from "Sdk.Deployment";
6+
import * as BuildXLSdk from "Sdk.BuildXL";
7+
8+
namespace Tests.MacOS {
9+
export declare const qualifier : { configuration: "debug" | "release", targetFramework: BuildXLSdk.TargetFrameworks.CoreClrTargetFrameworks, targetRuntime: "osx-x64" };
10+
11+
const sharedBinFolderName = a`sharedbin`;
12+
const tests = createAllDefs();
13+
14+
function createAllDefs() : TestDeploymentDefinition[] {
15+
return [
16+
// Utilities
17+
createDef(importFrom("BuildXL.Utilities.Instrumentation.UnitTests").Core.withQualifier({ targetFramework: "net6.0" }).dll, true),
18+
createDef(importFrom("BuildXL.Utilities.UnitTests").Collections.withQualifier({ targetFramework: "net6.0" }).dll, true),
19+
createDef(importFrom("BuildXL.Utilities.UnitTests").Configuration.withQualifier({ targetFramework: "net6.0" }).dll, true),
20+
createDef(importFrom("BuildXL.Utilities.UnitTests").Ipc.withQualifier({ targetFramework: "net6.0" }).dll, true),
21+
createDef(importFrom("BuildXL.Utilities.UnitTests").KeyValueStoreTests.withQualifier({ targetFramework: "net6.0" }).dll, true),
22+
createDef(importFrom("BuildXL.Utilities.UnitTests").Storage.withQualifier({ targetFramework: "net6.0" }).dll, true),
23+
createDef(importFrom("BuildXL.Utilities.UnitTests").Storage.Untracked.withQualifier({ targetFramework: "net6.0" }).dll, true),
24+
createDef(importFrom("BuildXL.Utilities.UnitTests").ToolSupport.withQualifier({ targetFramework: "net6.0" }).dll, true),
25+
createDef(importFrom("BuildXL.Utilities.UnitTests").Core.withQualifier({ targetFramework: "net6.0" }).dll, true),
26+
27+
// Cache
28+
createDef(importFrom("BuildXL.Cache.ContentStore").Test.withQualifier({ targetFramework: "net6.0" }).dll, true),
29+
createDef(importFrom("BuildXL.Cache.ContentStore").GrpcTest.withQualifier({ targetFramework: "net6.0" }).dll, true),
30+
createDef(importFrom("BuildXL.Cache.ContentStore").InterfacesTest.withQualifier({ targetFramework: "net6.0" }).dll, true),
31+
createDef(importFrom("BuildXL.Cache.ContentStore").DistributedTest.withQualifier({ targetFramework: "net6.0" }).dll, true),
32+
createDef(importFrom("BuildXL.Cache.MemoizationStore").Test.withQualifier({ targetFramework: "net6.0" }).dll, true),
33+
createDef(importFrom("BuildXL.Cache.MemoizationStore").InterfacesTest.withQualifier({ targetFramework: "net6.0" }).dll, true),
34+
createDef(importFrom("BuildXL.Cache.DistributedCache.Host").Test.withQualifier({ targetFramework: "net6.0" }).dll, true),
35+
createDef(importFrom("BuildXL.Cache.Core.UnitTests").Analyzer.withQualifier({ targetFramework: "net6.0" }).dll, true),
36+
createDef(importFrom("BuildXL.Cache.Core.UnitTests").BasicFilesystem.withQualifier({ targetFramework: "net6.0" }).dll, true),
37+
createDef(importFrom("BuildXL.Cache.Core.UnitTests").InputListFilter.withQualifier({ targetFramework: "net6.0" }).dll, true),
38+
createDef(importFrom("BuildXL.Cache.Core.UnitTests").Interfaces.withQualifier({ targetFramework: "net6.0" }).dll, true),
39+
createDef(importFrom("BuildXL.Cache.Core.UnitTests").MemoizationStoreAdapter.withQualifier({ targetFramework: "net6.0" }).dll, true),
40+
createDef(importFrom("BuildXL.Cache.Core.UnitTests").VerticalAggregator.withQualifier({ targetFramework: "net6.0" }).dll, true),
41+
...addIfLazy(BuildXLSdk.Flags.isMicrosoftInternal, () => [
42+
createDef(importFrom("BuildXL.Cache.Logging").Test.withQualifier({ targetFramework: "net6.0" }).dll, true)
43+
]),
44+
createDef(importFrom("BuildXL.Cache.MemoizationStore").Test.withQualifier({ targetFramework: "net6.0" }).dll, true)
45+
];
46+
}
47+
48+
interface TestDeploymentDefinition extends Deployment.NestedDefinition {
49+
assembly: File;
50+
enabled: boolean;
51+
testClasses: string[];
52+
categoriesToRunInParallel: string[];
53+
categoriesToNeverRun: string[];
54+
runSuppliedCategoriesOnly: boolean;
55+
}
56+
57+
function createDef(testResult: BuildXLSdk.TestResult, enabled: boolean) : TestDeploymentDefinition {
58+
let assembly = testResult.testDeployment.primaryFile;
59+
return <TestDeploymentDefinition>{
60+
subfolder: sharedBinFolderName,
61+
contents: [
62+
testResult.testDeployment.deployedDefinition
63+
],
64+
65+
assembly: assembly,
66+
testAssemblies: [],
67+
enabled: enabled,
68+
testClasses: undefined,
69+
categoriesToRunInParallel: undefined,
70+
categoriesToNeverRun: undefined,
71+
runSuppliedCategoriesOnly: false
72+
};
73+
}
74+
75+
function genXUnitExtraArgs(definition: TestDeploymentDefinition): string {
76+
return [
77+
...(definition.testClasses || []).map(testClass => `-class ${testClass}`),
78+
...(definition.categoriesToNeverRun || []).map(cat => `-notrait "Category=${cat}"`)
79+
].join(" ");
80+
}
81+
82+
function getRunXunitCommands(def: TestDeploymentDefinition): string[] {
83+
const base: string = `run_xunit "\${MY_DIR}/tests/${def.subfolder}"${' '}${def.assembly.name}${' '}${genXUnitExtraArgs(def)}`;
84+
const traits: string[] = (def.categoriesToRunInParallel || [])
85+
.map(cat => `${base} -trait "Category=${cat}"`);
86+
const rest: string = [
87+
base,
88+
...(def.categoriesToRunInParallel || []).map(cat => `-notrait "Category=${cat}"`)
89+
].join(" ");
90+
return def.runSuppliedCategoriesOnly
91+
? traits
92+
: [...traits, rest];
93+
}
94+
95+
function createUnixTestRunnerScript(definitions: TestDeploymentDefinition[]): string {
96+
const runTestCommands = tests
97+
.filter(def => def.enabled)
98+
.mapMany(getRunXunitCommands);
99+
100+
return [
101+
"#!/bin/bash",
102+
"",
103+
"MY_DIR=$(cd `dirname ${BASH_SOURCE[0]}` && pwd)",
104+
"source $MY_DIR/xunitrunner.sh",
105+
"",
106+
"find . \\( -name SandboxedProcessExecutor -o -name Test.BuildXL.Executables.InfiniteWaiter -o -name Test.BuildXL.Executables.TestProcess \\) -print0 | xargs -0 chmod +x",
107+
"",
108+
"numTestFailures=0",
109+
"trap \"((numTestFailures++))\" ERR",
110+
"",
111+
...runTestCommands,
112+
"",
113+
"exit $numTestFailures"
114+
].join("\n");
115+
}
116+
117+
function writeFile(fileName: PathAtom, content: string): DerivedFile {
118+
return Transformer.writeAllText({
119+
outputPath: p`${Context.getNewOutputDirectory("standalone-tests")}/${fileName}`,
120+
text: content
121+
});
122+
}
123+
124+
/*
125+
Folder layout:
126+
127+
├── [tests]
128+
│ └── [sharedbin]
129+
| └── ... (BuildXL core drop + test deployments)
130+
├── bashrunner.sh
131+
├── env.sh
132+
└── xunitrunner.sh
133+
*/
134+
@@public
135+
export const deployment : Deployment.Definition = {
136+
contents: [
137+
f`xunitrunner.sh`,
138+
writeFile(a`bashrunner.sh`, createUnixTestRunnerScript(tests)),
139+
f`${Context.getMount("Sandbox").path}/MacOs/scripts/env.sh`,
140+
{
141+
subfolder: r`tests`,
142+
contents: [
143+
// BuildXL core drop (Contains test dependencies)
144+
{
145+
subfolder: sharedBinFolderName,
146+
contents: [ BuildXL.deployment ]
147+
},
148+
// Test dlls
149+
...tests,
150+
]
151+
152+
}
153+
]
154+
};
155+
156+
@@public
157+
export const deployed = BuildXLSdk.DeploymentHelpers.deploy({
158+
definition: deployment,
159+
targetLocation: r`${qualifier.configuration}/tests/${qualifier.targetRuntime}`,
160+
});
161+
}

0 commit comments

Comments
 (0)