-
Notifications
You must be signed in to change notification settings - Fork 43
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
Expand list of reserved objc keywords to cover most conflicting cases… #79
Changes from 9 commits
eef72d1
1363c8f
7f94d5b
571b08f
a32b28f
321a526
8feaa44
44e9437
7a609d6
807adba
fe9dec1
ce6d1af
5d3455c
c26e63a
0c0c432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
steps: | ||
- name: ":docker: Build base image with sources" | ||
plugins: | ||
docker-compose#v1.5.0: | ||
build: app | ||
image-repository: buildkite-registry.pinadmin.com/registry | ||
volumes: | ||
- ".:/app/mnt/buildkite-builds/volumes" | ||
config: docker-compose.yml | ||
agents: | ||
queue: pinboard | ||
- wait: ~ | ||
- name: "Build :iphone: :airplane:" | ||
command: "swift build" | ||
timeout_in_minutes: 30 | ||
agents: | ||
queue: pinboard | ||
plugins: | ||
docker-compose#v1.5.0: | ||
run: app | ||
config: docker-compose.yml | ||
- name: "Test :iphone: :airplane:" | ||
command: "swift test" | ||
timeout_in_minutes: 30 | ||
agents: | ||
queue: pinboard | ||
plugins: | ||
docker-compose#v1.5.0: | ||
run: app | ||
config: docker-compose.yml | ||
- name: "Integration Test :iphone: :airplane:" | ||
command: "swift build && ./Utility/integration-test.sh" | ||
timeout_in_minutes: 30 | ||
agents: | ||
queue: pinboard | ||
plugins: | ||
docker-compose#v1.5.0: | ||
run: app | ||
config: docker-compose.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.1 | ||
4.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
# Base image from Swiftenv with Swift version 3.0.2 | ||
|
||
FROM kylef/swiftenv:latest | ||
# Base image from SwiftDocker | ||
# https://hub.docker.com/r/swiftdocker/swift/ | ||
FROM swiftdocker/swift | ||
MAINTAINER Pinterest | ||
RUN swiftenv install 3.1 | ||
|
||
# Vim config so we have an editor available | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
vim clang libicu-dev libcurl4-openssl-dev libssl-dev | ||
|
||
# Install plank | ||
COPY . /usr/local/plank | ||
RUN cd /usr/local/plank && swift build -c release | ||
|
||
ENV plank_HOME /usr/local/plank | ||
ENV PATH ${plank_HOME}/.build/release:${PATH} | ||
|
||
# Uncomment to make `plank` the default action of `docker run [image_name]` | ||
#ENTRYPOINT ["plank"] | ||
#CMD ["help"] | ||
# Copy plank sources | ||
COPY . /plank | ||
WORKDIR /plank | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,31 +52,114 @@ prefix func --> (body: () -> [String]) -> String { | |
return -->body() | ||
} | ||
|
||
// Most of these are derived from https://www.binpress.com/tutorial/objective-c-reserved-keywords/43 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should create some abstraction for each language. Could be for example a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maicki - I agree since there will be different reserved words per language. Only caveat is that the names must be consistent for any languages that bridge (Objc, Flow, Swift, etc.) so we might need a global set of all languages at runtime to utilize for consistent results. |
||
// other language conflicts should be ideally added here. | ||
// TODO: Find a way to separate this by language since the reserved keywords will differ. | ||
let objectiveCReservedWordReplacements = [ | ||
"description": "description_text", | ||
"id": "identifier" | ||
// TODO: Fill out more objc keywords with replacements. | ||
] | ||
|
||
let objectiveCReservedWords = Set<String>([ | ||
"@catch()", | ||
"@class", | ||
"@dynamic", | ||
"@end", | ||
"@finally", | ||
"@implementation", | ||
"@interface", | ||
"@private", | ||
"@property", | ||
"@protected", | ||
"@protocol", | ||
"@public", | ||
"@selector", | ||
"@synthesize", | ||
"@throw", | ||
"@try", | ||
"BOOL", | ||
"Class", | ||
"IMP", | ||
"NO", | ||
"NULL", | ||
"Protocol", | ||
"SEL", | ||
"YES", | ||
"_Bool", | ||
"_Complex", | ||
"_Imaginery", | ||
"atomic", | ||
"auto", | ||
"break", | ||
"bycopy", | ||
"byref", | ||
"case", | ||
"char", | ||
"const", | ||
"continue", | ||
"default", | ||
"do", | ||
"double", | ||
"else", | ||
"enum", | ||
"extern", | ||
"float", | ||
"for", | ||
"goto", | ||
"id", | ||
"if", | ||
"in", | ||
"inline", | ||
"inout", | ||
"int", | ||
"long", | ||
"nil", | ||
"nonatomic", | ||
"oneway", | ||
"out", | ||
"register", | ||
"restrict", | ||
"retain", | ||
"return", | ||
"self", | ||
"short", | ||
"signed", | ||
"sizeof", | ||
"static", | ||
"struct", | ||
"super", | ||
"switch", | ||
"typedef", | ||
"union", | ||
"unsigned", | ||
"void", | ||
"volatile", | ||
"while" | ||
]) | ||
|
||
extension String { | ||
/// All components separated by _ will be capitalized including the first one | ||
func snakeCaseToCamelCase() -> String { | ||
var str: String = self | ||
|
||
if let replacementString = objectiveCReservedWordReplacements[self] as String? { | ||
if let replacementString = objectiveCReservedWordReplacements[self.lowercased()] as String? { | ||
str = replacementString | ||
} | ||
|
||
let components = str.components(separatedBy: "_") | ||
let name = components.map { return $0.uppercaseFirst } | ||
return name.joined(separator: "") | ||
let formattedName = name.joined(separator: "") | ||
if objectiveCReservedWords.contains(formattedName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this clash if you would like to use "void" for something but it's a reserved word in objective c? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you used "void" it would just become "voidProperty" or "VoidProperty" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of this PR is to prevent reserved words from being generated as identifiers. I don't believe this will cause issues for most since naming anything as a reserved keyword is probably unlikely. |
||
return "\(formattedName)Property" | ||
} | ||
return formattedName | ||
} | ||
|
||
/// All components separated by _ will be capitalized execpt the first | ||
func snakeCaseToPropertyName() -> String { | ||
var str: String = self | ||
|
||
if let replacementString = objectiveCReservedWordReplacements[self] as String? { | ||
if let replacementString = objectiveCReservedWordReplacements[self.lowercased()] as String? { | ||
str = replacementString | ||
} | ||
|
||
|
@@ -97,6 +180,10 @@ extension String { | |
} | ||
} | ||
|
||
if objectiveCReservedWords.contains(name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above? |
||
return "\(name)Property" | ||
} | ||
|
||
return name | ||
} | ||
|
||
|
@@ -108,7 +195,8 @@ extension String { | |
|
||
/// Get the last n characters of a string | ||
func suffixSubstring(_ length: Int) -> String { | ||
return self.substring(from: self.characters.index(self.endIndex, offsetBy: -length)) | ||
let index = self.characters.index(self.endIndex, offsetBy: -length) | ||
return String(self[index...]) | ||
} | ||
|
||
/// Uppercase the first character | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: '2.1' | ||
services: | ||
app: | ||
shm_size: 2g | ||
build: . | ||
tmpfs: /tmp | ||
volumes: | ||
- ./:/plank | ||
environment: | ||
BUILDKITE_BRANCH: | ||
BUILDKITE_BUILD_URL: | ||
BUILDKITE_COMMIT: | ||
BUILDKITE_MESSAGE: | ||
BUILDKITE_PIPELINE_SLUG: | ||
BUILDKITE_AGENT_ACCESS_TOKEN: | ||
BUILDKITE_JOB_ID: | ||
BUILDKITE_BUILD_ID: | ||
BUILDKITE_BUILD_NUMBER: | ||
BUILDKITE_PARALLEL_JOB_COUNT: | ||
BUILDKITE_PARALLEL_JOB: | ||
network_mode: "host" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to move
swift build
either into the Docker container (if you're adding all files), or run this before integration-test.sh.You might also create a single shell script that wraps both of these commands, but I think you can only run a single thing in the command here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw that you were copying everything into the docker container with
COPY . /plank
. Because we're copying files this will invalidate the docker cache for basically every PR, which is fine, but might mean that we want to also runswift build
inside of the docker container. This would also let you use the build for other steps in the pipeline if needed in parallel to integration tests.