Skip to content

Commit

Permalink
semi trimmed olympus build first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Feb 10, 2025
1 parent e97ff0f commit d7153c2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
60 changes: 60 additions & 0 deletions SemiTrimmedOlympusBuild.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

// I hate PowerShell so here we are
public class SemiTrimmedOlympusBuild {
public static void main(String[] args) throws Exception {
Path outputFolder = Paths.get("sharp/bin/Release/net8.0/win-x86/publish");

// trimmed build
build(true);

// list files
List<Path> files;
try (Stream<Path> paths = Files.walk(outputFolder)) {
files = paths.filter(Files::isRegularFile).collect(Collectors.toList());
}
System.out.println("File list: " + formatFileList(files, outputFolder));

// purge the directory
try (Stream<Path> paths = Files.walk(outputFolder)) {
if (!paths.sorted(Comparator.reverseOrder()).map(Path::toFile).allMatch(File::delete)) {
throw new IOException("Failed cleaning up build directory: " + outputFolder);
}
}

// untrimmed build
build(false);

// prune files that weren't part of the trimmed build
List<Path> toDelete;
try (Stream<Path> paths = Files.walk(outputFolder)) {
toDelete = paths.filter(f -> Files.isRegularFile(f) && !files.contains(f)).collect(Collectors.toList());
}
System.out.println("Deleting files: " + formatFileList(toDelete, outputFolder));

if (!toDelete.stream().map(Path::toFile).allMatch(File::delete)) {
throw new IOException("Failed cleaning up build directory: " + outputFolder);
}
}

private static void build(boolean trimmed) throws Exception {
System.out.println("Building with trimming = " + trimmed + "...");
Process build = new ProcessBuilder("dotnet", "publish", "--self-contained", "--runtime", "win-x86", "-p:PublishTrimmed=" + trimmed, "sharp/Olympus.Sharp.csproj")
.inheritIO().start();
build.waitFor();
if (build.exitValue() != 0) throw new Exception("dotnet publish failed with exit code " + build.exitValue());
}

private static String formatFileList(List<Path> files, Path relativeTo) {
return "[\"" + files.stream().map(p -> relativeTo.relativize(p).toString())
.collect(Collectors.joining("\", \"")) + "\"]";
}
}
9 changes: 9 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,28 @@ steps:
# Build sharp.
- task: DotNetCoreCLI@2
displayName: 'Build: dotnet: restore sharp'
condition: and(succeeded(), ne(variables.agentArch, 'windows'))
inputs:
command: 'restore'
projects: 'sharp/*.csproj'

- task: DotNetCoreCLI@2
displayName: 'Build: dotnet: build sharp'
condition: and(succeeded(), ne(variables.agentArch, 'windows'))
inputs:
command: 'publish'
projects: 'sharp/*.csproj'
publishWebProjects: false
zipAfterPublish: false
arguments: '--runtime $(netBuildOS) --self-contained'

- task: CmdLine@2
displayName: 'Build: dotnet: build sharp with partial trimming'
condition: and(succeeded(), eq(variables.agentArch, 'windows'))
inputs:
script: |
javac SemiTrimmedOlympusBuild.java
java SemiTrimmedOlympusBuild
# Build launcher-winforms.
- task: UseDotNet@2
Expand Down

0 comments on commit d7153c2

Please sign in to comment.