Skip to content

Commit

Permalink
Merge pull request #106 from giginet/add-option-to-enable-manifest-up…
Browse files Browse the repository at this point in the history
…date

Add option to enable manifest update closes #97
  • Loading branch information
giginet authored Oct 3, 2023
2 parents ba240dc + 066af40 commit 1d89d20
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 14 deletions.
11 changes: 9 additions & 2 deletions Sources/ScipioKit/DescriptionPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,14 @@ struct DescriptionPackage {
return workspace
}

init(packageDirectory: AbsolutePath, mode: Runner.Mode) throws {
/// Make DescriptionPackage from a passed package directory
/// - Parameter packageDirectory: A path for the Swift package to build
/// - Parameter mode: A Scipio running mode
/// - Parameter onlyUseVersionsFromResolvedFile: A boolean value if true disabling force updating of Package.resolved.
/// Then, use package versions only from existing Package.resolved.
/// If it is `true`, Package.resolved never be updated.
/// Instead, the resolving will fail if the Package.resolved is mis-matched with the workspace.
init(packageDirectory: AbsolutePath, mode: Runner.Mode, onlyUseVersionsFromResolvedFile: Bool) throws {
self.packageDirectory = packageDirectory
self.mode = mode

Expand All @@ -119,7 +126,7 @@ struct DescriptionPackage {
rootInput: PackageGraphRootInput(packages: [packageDirectory]),
// This option is same with resolver option `--disable-automatic-resolution`
// Never update Package.resolved of the package
forceResolvedVersions: true,
forceResolvedVersions: onlyUseVersionsFromResolvedFile,
observabilityScope: scope
)
self.manifest = try tsc_await {
Expand Down
9 changes: 8 additions & 1 deletion Sources/ScipioKit/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public struct Runner {

logger.info("🔁 Resolving Dependencies...")
do {
descriptionPackage = try DescriptionPackage(packageDirectory: packagePath, mode: mode)
descriptionPackage = try DescriptionPackage(
packageDirectory: packagePath,
mode: mode,
onlyUseVersionsFromResolvedFile: false
)
} catch {
throw Error.invalidPackage(packageDirectory)
}
Expand Down Expand Up @@ -218,13 +222,15 @@ extension Runner {
}

public var buildOptionsContainer: BuildOptionsContainer
public var shouldOnlyUseVersionsFromResolvedFile: Bool
public var cacheMode: CacheMode
public var overwrite: Bool
public var verbose: Bool

public init(
baseBuildOptions: BuildOptions = .init(),
buildOptionsMatrix: [String: TargetBuildOptions] = [:],
shouldOnlyUseVersionsFromResolvedFile: Bool = false,
cacheMode: CacheMode = .project,
overwrite: Bool = false,
verbose: Bool = false
Expand All @@ -233,6 +239,7 @@ extension Runner {
baseBuildOptions: baseBuildOptions,
buildOptionsMatrix: buildOptionsMatrix
)
self.shouldOnlyUseVersionsFromResolvedFile = shouldOnlyUseVersionsFromResolvedFile
self.cacheMode = cacheMode
self.overwrite = overwrite
self.verbose = verbose
Expand Down
1 change: 1 addition & 0 deletions Sources/scipio/CommandType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extension Runner {
)
let runnerOptions = Runner.Options(
baseBuildOptions: baseBuildOptions,
shouldOnlyUseVersionsFromResolvedFile: buildOptions.shouldOnlyUseVersionsFromResolvedFile,
cacheMode: Self.cacheMode(from: commandType),
overwrite: buildOptions.overwrite,
verbose: globalOptions.verbose
Expand Down
4 changes: 4 additions & 0 deletions Sources/scipio/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct BuildOptionGroup: ParsableArguments {
help: "Whether to enable Library Evolution feature or not")
var shouldEnableLibraryEvolution = false

@Flag(name: [.customLong("only-use-versions-from-resolved-file")],
help: "Whether to disable updating Package.resolved automatically")
var shouldOnlyUseVersionsFromResolvedFile: Bool = false

@Flag(name: [.customShort("f", allowingJoined: false), .long],
help: "Whether overwrite generated frameworks or not")
var overwrite: Bool = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ All XCFrameworks are generated into `MyAppDependencies/XCFramework` by default.
|-\-support-simulators|Whether also building for simulators of each SDKs or not|-|
|-\-cache-policy|How to reuse built frameworks|project|
|-\-enable-library-evolution|Whether to enable Library Evolution feature or not|-|
|-\-only-use-versions-from-resolved-file|Whether to disable updating Package.resolved automatically|false|


See `--help` for details.
Expand Down
18 changes: 15 additions & 3 deletions Tests/ScipioKitTests/DescriptionPackageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ private let fixturePath = URL(fileURLWithPath: #file)
final class DescriptionPackageTests: XCTestCase {
func testDescriptionPackage() throws {
let rootPath = fixturePath.appendingPathComponent("TestingPackage")
let package = try XCTUnwrap(try DescriptionPackage(packageDirectory: rootPath.absolutePath, mode: .prepareDependencies))
let package = try XCTUnwrap(try DescriptionPackage(
packageDirectory: rootPath.absolutePath,
mode: .prepareDependencies,
onlyUseVersionsFromResolvedFile: false
))
XCTAssertEqual(package.name, "TestingPackage")

let packageNames = package.graph.packages.map(\.manifest.displayName)
Expand All @@ -29,7 +33,11 @@ final class DescriptionPackageTests: XCTestCase {

func testBuildProductsInPrepareMode() throws {
let rootPath = fixturePath.appendingPathComponent("IntegrationTestPackage")
let package = try XCTUnwrap(try DescriptionPackage(packageDirectory: rootPath.absolutePath, mode: .prepareDependencies))
let package = try XCTUnwrap(try DescriptionPackage(
packageDirectory: rootPath.absolutePath,
mode: .prepareDependencies,
onlyUseVersionsFromResolvedFile: false
))
XCTAssertEqual(package.name, "IntegrationTestPackage")

XCTAssertEqual(
Expand Down Expand Up @@ -58,7 +66,11 @@ final class DescriptionPackageTests: XCTestCase {

func testBuildProductsInCreateMode() throws {
let rootPath = fixturePath.appendingPathComponent("BinaryPackage")
let package = try XCTUnwrap(try DescriptionPackage(packageDirectory: rootPath.absolutePath, mode: .createPackage))
let package = try XCTUnwrap(try DescriptionPackage(
packageDirectory: rootPath.absolutePath,
mode: .createPackage,
onlyUseVersionsFromResolvedFile: false
))
XCTAssertEqual(package.name, "BinaryPackage")

XCTAssertEqual(
Expand Down
1 change: 1 addition & 0 deletions Tests/ScipioKitTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ final class IntegrationTests: XCTestCase {
enableLibraryEvolution: false
),
buildOptionsMatrix: buildOptionsMatrix,
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .disabled,
overwrite: true,
verbose: false
Expand Down
34 changes: 26 additions & 8 deletions Tests/ScipioKitTests/RunnerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ final class RunnerTests: XCTestCase {
let runner = Runner(
mode: .prepareDependencies,
options: .init(
baseBuildOptions: .init(isSimulatorSupported: false, enableLibraryEvolution: true)
baseBuildOptions: .init(isSimulatorSupported: false, enableLibraryEvolution: true),
shouldOnlyUseVersionsFromResolvedFile: true
)
)
do {
Expand Down Expand Up @@ -83,7 +84,8 @@ final class RunnerTests: XCTestCase {
let runner = Runner(
mode: .createPackage,
options: .init(
baseBuildOptions: .init(isSimulatorSupported: false)
baseBuildOptions: .init(isSimulatorSupported: false),
shouldOnlyUseVersionsFromResolvedFile: true
)
)
do {
Expand Down Expand Up @@ -132,7 +134,8 @@ final class RunnerTests: XCTestCase {
let runner = Runner(
mode: .createPackage,
options: .init(
baseBuildOptions: .init(isSimulatorSupported: false)
baseBuildOptions: .init(isSimulatorSupported: false),
shouldOnlyUseVersionsFromResolvedFile: true
)
)
do {
Expand Down Expand Up @@ -177,7 +180,11 @@ final class RunnerTests: XCTestCase {
}

func testCacheIsValid() async throws {
let descriptionPackage = try DescriptionPackage(packageDirectory: testPackagePath.absolutePath, mode: .prepareDependencies)
let descriptionPackage = try DescriptionPackage(
packageDirectory: testPackagePath.absolutePath,
mode: .prepareDependencies,
onlyUseVersionsFromResolvedFile: false
)
let cacheSystem = CacheSystem(descriptionPackage: descriptionPackage,
outputDirectory: frameworkOutputDir,
storage: nil)
Expand Down Expand Up @@ -207,6 +214,7 @@ final class RunnerTests: XCTestCase {
mode: .prepareDependencies,
options: .init(
baseBuildOptions: .init(enableLibraryEvolution: true),
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .project
)
)
Expand Down Expand Up @@ -236,6 +244,7 @@ final class RunnerTests: XCTestCase {
let runner = Runner(
mode: .prepareDependencies,
options: .init(
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .storage(storage, [.consumer, .producer])
)
)
Expand Down Expand Up @@ -277,6 +286,7 @@ final class RunnerTests: XCTestCase {
isDebugSymbolsEmbedded: false,
frameworkType: .dynamic
),
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .project,
overwrite: false,
verbose: false)
Expand Down Expand Up @@ -305,6 +315,7 @@ final class RunnerTests: XCTestCase {
isDebugSymbolsEmbedded: false,
frameworkType: .dynamic
),
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .project,
overwrite: false,
verbose: false)
Expand Down Expand Up @@ -333,7 +344,8 @@ final class RunnerTests: XCTestCase {
// Generate VersionFile
let descriptionPackage = try DescriptionPackage(
packageDirectory: usingBinaryPackagePath.absolutePath,
mode: .prepareDependencies
mode: .prepareDependencies,
onlyUseVersionsFromResolvedFile: false
)
let cacheSystem = CacheSystem(descriptionPackage: descriptionPackage,
outputDirectory: frameworkOutputDir,
Expand Down Expand Up @@ -374,6 +386,7 @@ final class RunnerTests: XCTestCase {
frameworkType: .dynamic,
enableLibraryEvolution: true
),
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .project,
overwrite: false,
verbose: false)
Expand Down Expand Up @@ -411,6 +424,7 @@ final class RunnerTests: XCTestCase {
isSimulatorSupported: true
),
],
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .project,
overwrite: false,
verbose: false)
Expand Down Expand Up @@ -448,6 +462,7 @@ final class RunnerTests: XCTestCase {
platforms: .specific([.iOS]),
isSimulatorSupported: true
),
shouldOnlyUseVersionsFromResolvedFile: true,
cacheMode: .disabled
)
)
Expand Down Expand Up @@ -491,7 +506,8 @@ final class RunnerTests: XCTestCase {
extraBuildParameters: [
"SWIFT_OPTIMIZATION_LEVEL": "-Osize",
]
)
),
shouldOnlyUseVersionsFromResolvedFile: true
)
)

Expand Down Expand Up @@ -522,7 +538,8 @@ final class RunnerTests: XCTestCase {
baseBuildOptions: .init(
isSimulatorSupported: false,
enableLibraryEvolution: false
)
),
shouldOnlyUseVersionsFromResolvedFile: true
)
)
do {
Expand Down Expand Up @@ -567,7 +584,8 @@ final class RunnerTests: XCTestCase {
let runner = Runner(
mode: .createPackage,
options: .init(
baseBuildOptions: .init(platforms: .specific([.iOS]))
baseBuildOptions: .init(platforms: .specific([.iOS])),
shouldOnlyUseVersionsFromResolvedFile: true
)
)
do {
Expand Down

0 comments on commit 1d89d20

Please sign in to comment.