Skip to content

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Feb 7, 2024

Rather than hardcode the build numbers, use named parameters to locate them during the build process.

@compnerd
Copy link
Member Author

compnerd commented Feb 7, 2024

CC: @hyp @hjyamauchi @tristanlabelle

@compnerd
Copy link
Member Author

compnerd commented Feb 7, 2024

@swift-ci please test Windows platform

return "$BinaryCache\" + ($Arch.BuildID + $Project.value__)
}

enum HostComponent {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this renumber the directory names at all? Would it be useful to add the corresponding numbers next to each enum elements as comments like

BuildToosl # 0
Compilers  # 1
...

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the numbers should be left in tact (but, the beauty is that we don't need to synchronize those after this - everything should be left in a consistent state.

utils/build.ps1 Outdated
$Targets = @("default", "test-llbuild")
$TestingDefines = @{
FILECHECK_EXECUTABLE = "$BinaryCache\0\bin\FileCheck.exe";
FILECHECK_EXECUTABLE = (Join-Path -Path (Join-Path -Path (Get-HostProjectBinaryCache BuildTools) -ChildPath "bin") -ChildPath "FileCheck.exe");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Join-Path seem a little overkill throughout?

Suggested change
FILECHECK_EXECUTABLE = (Join-Path -Path (Join-Path -Path (Get-HostProjectBinaryCache BuildTools) -ChildPath "bin") -ChildPath "FileCheck.exe");
FILECHECK_EXECUTABLE = "$(Get-HostProjectBinaryCache BuildTools)\bin\FileCheck.exe";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to be able to support other platforms some day (e.g. Linux)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a Join-Path variant that takes an arbitrary number of components and doesn't require labels so it's tidier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or use [IO.Path]::Combine($foo, $bar, $baz)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try switching to [IO.Path]::Combine ... if we can use builtins, I'd prefer that.

}

function Get-HostProjectCMakeModules([HostComponent]$Project) {
return "$BinaryCache\$($Project.value__)\cmake\modules"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All remaining instances of hard-coded values in this file are to $BinaryCache\1 or $BinaryCache\7, so how about defining two globals after this function definition:

$CompilersBinaryCache = Get-HostProjectBinaryCache Compilers
$DriverBinaryCache = Get-HostProjectBinaryCache Driver

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't catch that they were in the same function - totally seems reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the usages are in the same function, I was suggesting creating global variables for them. (but even better if they can be locals)

BUILD_SHARED_LIBS = "NO";
SwiftASN1_DIR = "$BinaryCache\10\cmake\modules";
SwiftCrypto_DIR = "$BinaryCache\8\cmake\modules";
SwiftCrypto_DIR = (Get-HostProjectCMakeModules Crypto);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parens are probably not necessary on the RHS of an assignment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it shouldn't confuse things to have Get-HostProjectCMakeModules Crypto;? I definitely would prefer to remove the parenthesis then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that they are needed :( - maybe you can try to clean them up subsequently? I'd love to get that noise removed.

function Get-ProjectBinaryCache($Arch, [Target]$Target) {
return "$BinaryCache\" + ($Arch.BuildID + $Target.value__)
function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
return "$BinaryCache\" + ($Arch.BuildID + $Project.value__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, value__ is the name of the hidden field that .NET generates in structs derived from System.Enum per standard. Cool trick!

Copy link
Contributor

@tristanlabelle tristanlabelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

Rather than hardcode the build numbers, use named parameters to locate
them during the build process.
@compnerd
Copy link
Member Author

compnerd commented Feb 7, 2024

@swift-ci please test Windows platform

@compnerd
Copy link
Member Author

compnerd commented Feb 8, 2024

@swift-ci please test Linux platform

@compnerd
Copy link
Member Author

compnerd commented Feb 8, 2024

@swift-ci please test macOS platform

@compnerd compnerd merged commit c25f4ee into swiftlang:main Feb 9, 2024
@compnerd compnerd deleted the enumerated branch February 9, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants