This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow creation of an "umbrella directory" module map
Summary: This adds a separate mode for module map generation that uses an umbrella directory declaration, rather than an umbrella header declaration. This fits Buck's general approach to headers better - it's kind of like an autoglob for every header in the library, without the need to either generate or manually maintain a valid umbrella header. It's implemented by adding a new `ModuleMapMode` enum, and a new case to `HeaderMode` to differentiate between the two associated forms of module maps. I decided to have it specified at the `.buckconfig` level, rather than per-library, as this is simpler and is sufficient for the use-case. Reviewed By: williamtwilson shipit-source-id: 10842bbd24
- Loading branch information
1 parent
ef8007c
commit 89981e5
Showing
33 changed files
with
436 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2014-present Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.facebook.buck.apple.clang; | ||
|
||
/** | ||
* Creates module map instances. | ||
* | ||
* <p>Use this instead of directly creating UmbrellaHeaderModuleMap or UmbrellaDirectoryModuleMap | ||
* instances. | ||
*/ | ||
public class ModuleMapFactory { | ||
|
||
/** | ||
* Creates a module map. | ||
* | ||
* @param moduleName The name of the module. | ||
* @param moduleMapMode The module map mode to use. | ||
* @param swiftMode The Swift mode to use for umbrella header module maps. This parameter is | ||
* unused with umbrella directory module maps. | ||
* @return A module map instance. | ||
*/ | ||
public static ModuleMap createModuleMap( | ||
String moduleName, ModuleMapMode moduleMapMode, UmbrellaHeaderModuleMap.SwiftMode swiftMode) { | ||
switch (moduleMapMode) { | ||
case UMBRELLA_HEADER: | ||
return new UmbrellaHeaderModuleMap(moduleName, swiftMode); | ||
case UMBRELLA_DIRECTORY: | ||
return new UmbrellaDirectoryModuleMap(moduleName); | ||
} | ||
|
||
throw new RuntimeException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2014-present Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.facebook.buck.apple.clang; | ||
|
||
/** Enumerates the module map generation modes that Buck supports. */ | ||
public enum ModuleMapMode { | ||
/** Generate a module map that requires an umbrella header. */ | ||
UMBRELLA_HEADER, | ||
|
||
/** Generate a module map that uses the library's headers in an umbrella directory. */ | ||
UMBRELLA_DIRECTORY, | ||
} |
66 changes: 66 additions & 0 deletions
66
src/com/facebook/buck/apple/clang/UmbrellaDirectoryModuleMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2014-present Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.facebook.buck.apple.clang; | ||
|
||
import com.google.common.base.Objects; | ||
import javax.annotation.Nullable; | ||
import org.stringtemplate.v4.ST; | ||
|
||
/** | ||
* A module map using an umbrella directory, rather than an umbrella header. This removes the need | ||
* to maintain or generate an umbrella header: all exported headers in the library will be included | ||
* in the module automatically. | ||
*/ | ||
public class UmbrellaDirectoryModuleMap implements ModuleMap { | ||
private final String moduleName; | ||
|
||
@Nullable private String generatedModule; | ||
private static final String template = | ||
"module <module_name> {\n" | ||
+ " umbrella \".\"\n" | ||
+ "\n" | ||
+ " module * { export * }\n" | ||
+ "}\n" | ||
+ "\n"; | ||
|
||
public UmbrellaDirectoryModuleMap(String moduleName) { | ||
this.moduleName = moduleName; | ||
} | ||
|
||
@Override | ||
public String render() { | ||
if (this.generatedModule == null) { | ||
ST st = new ST(template).add("module_name", moduleName); | ||
this.generatedModule = st.render(); | ||
} | ||
return this.generatedModule; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof UmbrellaDirectoryModuleMap)) { | ||
return false; | ||
} | ||
UmbrellaDirectoryModuleMap that = (UmbrellaDirectoryModuleMap) obj; | ||
return Objects.equal(this.moduleName, that.moduleName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(moduleName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.