Skip to content

Allow lookup template attributes from globalTemplateAttributes #1400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You can also use environment variables in your configuration file, by using `${S
- [Legacy Target](#legacy-target)
- [Aggregate Target](#aggregate-target)
- [Target Template](#target-template)
- [Global Template Attributes](#global-template-attributes)
- [Scheme](#scheme)
- [Build](#build)
- [Common Build Action options](#common-build-action-options)
Expand Down Expand Up @@ -973,6 +974,15 @@ targetTemplates:
- ${frameworkName}/${target_name}
```

## Global template attributes

This is place to define global variables used to resolve missing `${target_name}` within each template. This also helps share attributes between yaml files.

```yaml
globalTemplateAttributes:
version: legacy
```

## Scheme

Schemes allows for more control than the convenience [Target Scheme](#target-scheme) on [Target](#target)
Expand Down
4 changes: 4 additions & 0 deletions Sources/ProjectSpec/Template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ private func resolveTemplates(jsonDictionary: JSONDictionary, templateStructure:
if let templateAttributes = reference["templateAttributes"] as? [String: String] {
reference = reference.expand(variables: templateAttributes)
}

if let globalVariables = jsonDictionary["globalTemplateAttributes"] as? [String: String] {
reference = reference.expand(variables: globalVariables)
}
}
baseDictionary[referenceName] = reference
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_PATH = https://dev.google.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_PATH = https://release.google.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import UIKit
import MobileCoreServices

class ContentBlockerRequestHandler: NSObject, NSExtensionRequestHandling {

func beginRequest(with context: NSExtensionContext) {
let attachment = NSItemProvider(contentsOf: Bundle.main.url(forResource: "blockerList", withExtension: "json"))!

let item = NSExtensionItem()
item.attachments = [attachment]

context.completeRequest(returningItems: [item], completionHandler: nil)
}

}
13 changes: 13 additions & 0 deletions Tests/Fixtures/TestProject/ContentBlocker/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.content-blocker</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ContentBlockerRequestHandler</string>
</dict>
</dict>
</plist>
10 changes: 10 additions & 0 deletions Tests/Fixtures/TestProject/ContentBlocker/blockerList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": "webkit.svg"
}
}
]
186 changes: 186 additions & 0 deletions Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion Tests/Fixtures/TestProject/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ options:
buildPhase: none
abcd:
buildPhase: none
globalTemplateAttributes:
version: legacy
fileGroups:
- Configs
- FileGroup
Expand Down Expand Up @@ -79,7 +81,9 @@ targets:
legacy:
toolPath: /usr/bin/true
passSettings: true

ContentBlocker:
templates:
- ContentBlockerTemplate
App_macOS:
type: application
platform: macOS
Expand Down Expand Up @@ -520,6 +524,20 @@ schemes:
targetTemplates:
MyTemplate:
scheme: {}
ContentBlockerTemplate:
platform: iOS
type: app-extension
settings:
CODE_SIGN_IDENTITY: Apple Development
configFiles:
Test Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Staging Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Production Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Test Release: ContentBlocker/Configs/${version}/Release.xcconfig
Staging Release: ContentBlocker/Configs/${version}/Release.xcconfig
Production Release: ContentBlocker/Configs/${version}/Release.xcconfig
sources:
- ContentBlocker
aggregateTargets:
SuperTarget:
attributes:
Expand Down
32 changes: 32 additions & 0 deletions Tests/Fixtures/global_template_attributes_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
targetTemplates:
ContentBlockerTemplate:
platform: iOS
type: app-extension
settings:
CODE_SIGN_IDENTITY: Apple Development
configFiles:
Test Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Staging Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Production Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Test Release: ContentBlocker/Configs/${version}/Release.xcconfig
Staging Release: ContentBlocker/Configs/${version}/Release.xcconfig
Production Release: ContentBlocker/Configs/${version}/Release.xcconfig
sources:
- ContentBlocker

globalTemplateAttributes:
version: legacy

name: Demo
options:
createIntermediateGroups: True
targets:
Demo:
type: application
platform: iOS
deploymentTarget: "10.0"
sources:
- DemoXcodeGenGlobalTemplateAttribute
ContentBlocker:
templates:
- ContentBlockerTemplate
9 changes: 9 additions & 0 deletions Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ class SpecLoadingTests: XCTestCase {
]
try expect(project.targets.last?.sources) == ["SomeTarget", "doesWin", "templateVariable"]
}

$0.it("lookup global template attributes") {
let path = fixturePath + "global_template_attributes_test.yml"

let project = try loadSpec(path: path)
let extensionTarget = project.targets.first!
try expect(extensionTarget.configFiles["Production Debug"]) == "ContentBlocker/Configs/legacy/Debug.xcconfig"
try expect(extensionTarget.configFiles["Production Release"]) == "ContentBlocker/Configs/legacy/Release.xcconfig"
}
}
}

Expand Down