Skip to content

Commit 286e8f2

Browse files
authored
Introduce Zip File Builder (in Swift) (#2407)
* Introduce tooling to build the Zip file. * Cleanup to prepare for review. This moves argument parsing into its own file, moves some methods into CocoaPodUtils and consolidates some related types. * Add modulemap and Firebase.h * Adding CoreDiagnostics, WIP * Refactored paths into separate struct. * Organized methods. * Remove unused utility import. * Properly passed in custom spec repos. * Added licenses, outputDir argument. * Fix the Zip command to use the working directory. * Fixing bundles and headers being copied. * Fixing the resources directories. * More iterations to come closer to Released zip. - Fixed the caching of OSS pods - Add custom Crash objects - Move resources around properly. * Missing comment. * Fix resources for MLKit and others. * Remove unused URL extension. * Add priorities to README, exclude Firebase.framework * Run style.sh * Fully ran style.sh * Add license to files that don't have it. * Address feedback from first review. * Add missing custom spec repo flag.
1 parent 55a3ac6 commit 286e8f2

32 files changed

+5545
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ DerivedData
3232
*.hmap
3333
*.ipa
3434

35+
# Swift Package Manager
36+
*/.build
37+
ZipBuilder/Packages
38+
ZipBuilder/*.xcodeproj
39+
ZipBuilder/Package.resolved
40+
41+
3542
# IntelliJ
3643
.idea
3744

ZipBuilder/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj

ZipBuilder/FirebaseSDKs.proto

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
syntax = "proto3";
2+
3+
package ZipBuilder;
4+
5+
// A list of all Firebase SDKs.
6+
message FirebaseSDKs {
7+
repeated SDK sdk = 1;
8+
}
9+
10+
// Represents a single SDK that should be released.
11+
message SDK {
12+
// SDK name
13+
string name = 1;
14+
15+
// MPM name for the blueprint. For internal use only.
16+
string mpm_name = 2;
17+
18+
// Public version
19+
string public_version = 3;
20+
21+
// List of MPM patterns to build
22+
repeated string mpm_pattern = 4;
23+
24+
// An optional list of additional build flags. For internal use only.
25+
BuildFlag build_flags = 5;
26+
27+
// List of MPM patterns to build (optional nightly override). For internal use only.
28+
repeated string nightly_mpm_pattern = 6;
29+
30+
// Whether or not the SDK is built from open-source. For internal use only.
31+
bool open_source = 7;
32+
33+
// Whether or not to strip the i386 architecture from the build.
34+
bool strip_i386 = 8;
35+
}
36+
37+
// Any extra build flags needed to build the SDK. For internal use only.
38+
message BuildFlag {
39+
// An additional build flag needed to build the SDK
40+
repeated string flag = 1;
41+
}

ZipBuilder/Package.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// swift-tools-version:4.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
/*
5+
* Copyright 2019 Google
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import PackageDescription
21+
22+
let package = Package(
23+
name: "ZipBuilder",
24+
dependencies: [
25+
.package(url: "https://github.com/apple/swift-protobuf.git", .exact("1.2.0")),
26+
],
27+
targets: [
28+
.target(
29+
name: "ZipBuilder",
30+
dependencies: ["SwiftProtobuf"]
31+
),
32+
]
33+
)

ZipBuilder/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Firebase Zip File Builder
2+
3+
This project builds the Firebase iOS Zip file for distribution.
4+
More instructions to come.
5+
6+
## Priorities
7+
8+
The following section describes the priorities taken while building this tool and should be followed
9+
for any modifications.
10+
11+
### Readable and Maintainable
12+
This code will rarely be modified outside of bug fixes, but read very frequently. There should be no
13+
"magic lines" that do multiple things. Verbosity is preferred over making the code shorter and
14+
performing multiple actions at once. All functions should be well documented.
15+
16+
### Avoid Calling bash Commands Where Possible
17+
Instead of using `cat`, `find`, `grep`, or `perl` use `String` APIs to read the contents of a file,
18+
`FileManager` to properly list contents of a directory, `RegularExpression` for pattern matching,
19+
etc. If there's a `Foundation` API available, it should be used.
20+
21+
### Understandable Output
22+
The output of the script should make it immediately obvious if there were any issues and exactly
23+
what those issues were, without looking at the code. It should also be very clear if the Zip file
24+
was properly built and output the file location.
25+
26+
### Show Xcode and API Output on Failures
27+
In the event that there's an Xcode build failure, the logs should be surfaced immediately to aid
28+
debugging. Release engineers should not have to find the Xcode project manually. That being said, a
29+
link to the Xcode project file should be logged as well in case it's necessary. Same goes for errors
30+
logged by exceptions (ex: `FileManager`).
31+
32+
### Testable and Debuggable
33+
Components and functions should be split up in a way that make them easy to test and easy to debug.
34+
Prefer small functions that have proper failure conditions and input validated with `guard`
35+
statements, throwing `fatalError` with a well written error message if it's a critical issue that
36+
prevents the Zip file from being built properly.
37+
38+
### Works from the Command Line or Xcode (Environment Agnostic)
39+
The script should be able to run from the command line to allow for easier automation and Xcode for
40+
simpler debugging and maintenance.
41+
42+
### Any Failure Exits Immediately
43+
The script should not continue if anything necessary for a successful Zip file fails. This includes
44+
things like compiling storyboards, moving resources, missing files, etc. This is to ensure the
45+
integrity of the zip file and that any issues during testing are SDK bugs and not related to the
46+
files and folders.
47+
48+
### Prefer File `URL`s over Strings
49+
Instead of relying on `String`s to represent file paths, use `URL`s as soon as possible to avoid any
50+
missed or double slashes along with other issues.

0 commit comments

Comments
 (0)