Skip to content

Commit 671a878

Browse files
authored
[Release Tooling] xcprivacy generation tooling (2) (#12141)
1 parent 8fe1ddc commit 671a878

File tree

5 files changed

+96
-8
lines changed

5 files changed

+96
-8
lines changed

ReleaseTooling/Sources/PrivacyKit/PrivacyManifest.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ import Foundation
1616

1717
/// Represents a Privacy Manifest as described in
1818
/// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
19+
// TODO(ncooke3): Add example of Privacy Manifest.
1920
public struct PrivacyManifest {
2021
public init() {}
22+
public class Builder {
23+
public init() {}
24+
public func build() -> PrivacyManifest? {
25+
// TODO(ncooke3): Implement.
26+
nil
27+
}
28+
}
2129
}

ReleaseTooling/Sources/PrivacyManifestGenerator/PrivacyManifestWizard.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,34 @@ import PrivacyKit
1818
/// Provides an API to walk the client through the creation of a Privacy
1919
/// Manifest via a series of questions.
2020
final class PrivacyManifestWizard {
21-
private let xcframework: URL
21+
private let builder: PrivacyManifest.Builder
22+
private var questionnaire: Questionnaire
2223

23-
init(xcframework: URL) {
24-
self.xcframework = xcframework
24+
static func makeWizard(xcframework: URL) -> Self {
25+
let builder = PrivacyManifest.Builder()
26+
let privacyQuestionnaire = Questionnaire.makePrivacyQuestionnaire(
27+
for: xcframework,
28+
with: builder
29+
)
30+
return Self(builder: builder, questionnaire: privacyQuestionnaire)
31+
}
32+
33+
private init(builder: PrivacyManifest.Builder,
34+
questionnaire: Questionnaire) {
35+
self.builder = builder
36+
self.questionnaire = questionnaire
2537
}
2638

2739
func nextQuestion() -> String? {
28-
// TODO(ncooke3): Implement.
29-
nil
40+
questionnaire.nextQuestion()?.question
3041
}
3142

3243
func processAnswer(_ answer: String) throws {
33-
// TODO(ncooke3): Implement.
44+
try questionnaire.processAnswer(answer)
3445
}
3546

3647
func createManifest() throws -> PrivacyManifest {
3748
// TODO(ncooke3): Implement.
38-
return PrivacyManifest()
49+
builder.build()!
3950
}
4051
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
import PrivacyKit
17+
18+
extension Questionnaire {
19+
/// Creates a questionnaire that, when complete, can be used to generate a Privacy Manifest.
20+
///
21+
/// - Parameters:
22+
/// - xcframework: The xcframework to generate the Privacy Manifest for.
23+
/// - builder: The Privacy Manifest builder to mutate in each question's answer handler closure.
24+
/// - Returns: A questionnaire that can be used to generate a Privacy Manifest.
25+
static func makePrivacyQuestionnaire(for xcframework: URL,
26+
with builder: PrivacyManifest.Builder) -> Self {
27+
// TODO(ncooke3): Implement.
28+
Questionnaire()
29+
}
30+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
/// A structure representing a series of questions.
18+
struct Questionnaire {
19+
/// A structure representing a question within a questionnaire.
20+
struct Question {
21+
/// The question's string query, for example, _What is your name?_.
22+
let question: String
23+
/// A closure to be invoked with the answer to the question.
24+
let answerHandler: (_ answer: Any) throws -> Void
25+
}
26+
27+
/// Moves to and returns the next question in the questionnaire.
28+
/// - Returns: The next question in the questionnaire, if any.
29+
mutating func nextQuestion() -> Question? {
30+
// TODO(ncooke3): Implement.
31+
nil
32+
}
33+
34+
/// Calls the current question's answer handling closure with the given answer.
35+
/// - Parameter answer: The answer to pass to the current question's answer handling closure.
36+
func processAnswer(_ answer: String) throws {
37+
// TODO(ncooke3): Implement.
38+
}
39+
}

ReleaseTooling/Sources/PrivacyManifestGenerator/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct PrivacyManifestGenerator: ParsableCommand {
2929
}
3030

3131
func run() throws {
32-
let wizard = PrivacyManifestWizard(xcframework: xcframework)
32+
let wizard = PrivacyManifestWizard.makeWizard(xcframework: xcframework)
3333

3434
while let question = wizard.nextQuestion() {
3535
print(question)

0 commit comments

Comments
 (0)