Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
[Apple] Added command_line_arguments to xcode_workspace_config (#2560)
Browse files Browse the repository at this point in the history
* Adding commandLineArguments to XCScheme

* Adding commandLineArguments to projectV2

* Renaming envVariableList to commandLineArgsList
  • Loading branch information
ciceroduarte authored Mar 29, 2021
1 parent 78f3d37 commit 0a914c7
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/com/facebook/buck/apple/xcode/XCScheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public enum WatchInterface {
private final LaunchStyle launchStyle;
private final Optional<ImmutableMap<String, String>> environmentVariables;
private final Optional<BuildableReference> expandVariablesBasedOn;
private final Optional<ImmutableMap<String, String>> commandLineArguments;
private final Optional<String> notificationPayloadFile;
private final Optional<String> applicationLanguage;
private final Optional<String> applicationRegion;
Expand All @@ -267,6 +268,7 @@ public LaunchAction(
LaunchStyle launchStyle,
Optional<ImmutableMap<String, String>> environmentVariables,
Optional<BuildableReference> expandVariablesBasedOn,
Optional<ImmutableMap<String, String>> commandLineArguments,
Optional<ImmutableList<SchemePrePostAction>> preActions,
Optional<ImmutableList<SchemePrePostAction>> postActions,
Optional<String> notificationPayloadFile,
Expand All @@ -281,6 +283,7 @@ public LaunchAction(
this.launchStyle = launchStyle;
this.environmentVariables = environmentVariables;
this.expandVariablesBasedOn = expandVariablesBasedOn;
this.commandLineArguments = commandLineArguments;
this.notificationPayloadFile = notificationPayloadFile;
this.applicationLanguage = applicationLanguage;
this.applicationRegion = applicationRegion;
Expand Down Expand Up @@ -322,6 +325,10 @@ public Optional<BuildableReference> getExpandVariablesBasedOn() {
return expandVariablesBasedOn;
}

public Optional<ImmutableMap<String, String>> getCommandLineArguments() {
return commandLineArguments;
}

public Optional<String> getApplicationLanguage() {
return applicationLanguage;
}
Expand All @@ -336,19 +343,22 @@ public static class ProfileAction extends SchemeAction {
private final String buildConfiguration;
private final Optional<ImmutableMap<String, String>> environmentVariables;
private final Optional<BuildableReference> expandVariablesBasedOn;
private final Optional<ImmutableMap<String, String>> commandLineArguments;

public ProfileAction(
BuildableReference buildableReference,
String buildConfiguration,
Optional<ImmutableMap<String, String>> environmentVariables,
Optional<BuildableReference> expandVariablesBasedOn,
Optional<ImmutableMap<String, String>> commandLineArguments,
Optional<ImmutableList<SchemePrePostAction>> preActions,
Optional<ImmutableList<SchemePrePostAction>> postActions) {
super(preActions, postActions);
this.buildableReference = buildableReference;
this.buildConfiguration = buildConfiguration;
this.environmentVariables = environmentVariables;
this.expandVariablesBasedOn = expandVariablesBasedOn;
this.commandLineArguments = commandLineArguments;
}

public BuildableReference getBuildableReference() {
Expand All @@ -366,20 +376,26 @@ public Optional<ImmutableMap<String, String>> getEnvironmentVariables() {
public Optional<BuildableReference> getExpandVariablesBasedOn() {
return expandVariablesBasedOn;
}

public Optional<ImmutableMap<String, String>> getCommandLineArguments() {
return commandLineArguments;
}
}

public static class TestAction extends SchemeAction {
List<TestableReference> testables;
private final String buildConfiguration;
private final Optional<ImmutableMap<String, String>> environmentVariables;
private final Optional<BuildableReference> expandVariablesBasedOn;
private final Optional<ImmutableMap<String, String>> commandLineArguments;
private final Optional<String> applicationLanguage;
private final Optional<String> applicationRegion;

public TestAction(
String buildConfiguration,
Optional<ImmutableMap<String, String>> environmentVariables,
Optional<BuildableReference> expandVariablesBasedOn,
Optional<ImmutableMap<String, String>> commandLineArguments,
Optional<ImmutableList<SchemePrePostAction>> preActions,
Optional<ImmutableList<SchemePrePostAction>> postActions,
Optional<String> applicationLanguage,
Expand All @@ -389,6 +405,7 @@ public TestAction(
this.buildConfiguration = buildConfiguration;
this.environmentVariables = environmentVariables;
this.expandVariablesBasedOn = expandVariablesBasedOn;
this.commandLineArguments = commandLineArguments;
this.applicationLanguage = applicationLanguage;
this.applicationRegion = applicationRegion;
}
Expand All @@ -413,6 +430,10 @@ public Optional<BuildableReference> getExpandVariablesBasedOn() {
return expandVariablesBasedOn;
}

public Optional<ImmutableMap<String, String>> getCommandLineArguments() {
return commandLineArguments;
}

public Optional<String> getApplicationLanguage() {
return applicationLanguage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ interface AbstractXcodeWorkspaceConfigDescriptionArg extends BuildRuleArg {
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>>
getEnvironmentVariables();

Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>>
getCommandLineArguments();

Optional<String> getApplicationLanguage();

Optional<String> getApplicationRegion();
Expand Down
42 changes: 42 additions & 0 deletions src/com/facebook/buck/features/apple/project/SchemeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class SchemeGenerator {
private final Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>>
environmentVariables;
private final Optional<ImmutableMap<SchemeActionType, PBXTarget>> expandVariablesBasedOn;
private final Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>>
commandLineArguments;
private Optional<
ImmutableMap<
SchemeActionType, ImmutableMap<XCScheme.AdditionalActions, ImmutableList<String>>>>
Expand All @@ -112,6 +114,7 @@ public SchemeGenerator(
ImmutableMap<PBXTarget, Path> targetToProjectPathMap,
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> environmentVariables,
Optional<ImmutableMap<SchemeActionType, PBXTarget>> expandVariablesBasedOn,
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> commandLineArguments,
Optional<
ImmutableMap<
SchemeActionType,
Expand Down Expand Up @@ -139,6 +142,7 @@ public SchemeGenerator(
this.targetToProjectPathMap = targetToProjectPathMap;
this.environmentVariables = environmentVariables;
this.expandVariablesBasedOn = expandVariablesBasedOn;
this.commandLineArguments = commandLineArguments;
this.additionalSchemeActions = additionalSchemeActions;
this.notificationPayloadFile = notificationPayloadFile;
this.applicationLanguage = applicationLanguage;
Expand Down Expand Up @@ -255,11 +259,17 @@ public Path writeScheme() throws IOException {
}
}

ImmutableMap<SchemeActionType, ImmutableMap<String, String>> commandLineArgs = ImmutableMap.of();
if (commandLineArguments.isPresent()) {
commandLineArgs = commandLineArguments.get();
}

XCScheme.TestAction testAction =
new XCScheme.TestAction(
Objects.requireNonNull(actionConfigNames.get(SchemeActionType.TEST)),
Optional.ofNullable(envVariables.get(SchemeActionType.TEST)),
Optional.ofNullable(envVariablesBasedOn.get(SchemeActionType.TEST)),
Optional.ofNullable(commandLineArgs.get(SchemeActionType.TEST)),
additionalCommandsForSchemeAction(
SchemeActionType.TEST, AdditionalActions.PRE_SCHEME_ACTIONS, primaryBuildReference),
additionalCommandsForSchemeAction(
Expand Down Expand Up @@ -295,6 +305,7 @@ public Path writeScheme() throws IOException {
launchStyle,
Optional.ofNullable(envVariables.get(SchemeActionType.LAUNCH)),
Optional.ofNullable(envVariablesBasedOn.get(SchemeActionType.LAUNCH)),
Optional.ofNullable(commandLineArgs.get(SchemeActionType.LAUNCH)),
additionalCommandsForSchemeAction(
SchemeActionType.LAUNCH,
AdditionalActions.PRE_SCHEME_ACTIONS,
Expand All @@ -314,6 +325,7 @@ public Path writeScheme() throws IOException {
Objects.requireNonNull(actionConfigNames.get(SchemeActionType.PROFILE)),
Optional.ofNullable(envVariables.get(SchemeActionType.PROFILE)),
Optional.ofNullable(envVariablesBasedOn.get(SchemeActionType.PROFILE)),
Optional.ofNullable(commandLineArgs.get(SchemeActionType.PROFILE)),
additionalCommandsForSchemeAction(
SchemeActionType.PROFILE,
AdditionalActions.PRE_SCHEME_ACTIONS,
Expand Down Expand Up @@ -409,6 +421,18 @@ public static Element serializeEnvironmentVariables(
return rootElement;
}

public static Element serializeCommandLineArguments(
Document doc, ImmutableMap<String, String> commandLineArguments) {
Element rootElement = doc.createElement("CommandLineArguments");
for (String argumentKey : commandLineArguments.keySet()) {
Element argumentElement = doc.createElement("CommandLineArgument");
argumentElement.setAttribute("argument", argumentKey);
argumentElement.setAttribute("isEnabled", commandLineArguments.get(argumentKey));
rootElement.appendChild(argumentElement);
}
return rootElement;
}

public static Element serializeExpandVariablesBasedOn(
Document doc, XCScheme.BuildableReference reference) {
Element referenceElement = serializeBuildableReference(doc, reference);
Expand Down Expand Up @@ -485,6 +509,12 @@ public static Element serializeTestAction(Document doc, XCScheme.TestAction test
testActionElem.appendChild(environmentVariablesElement);
}

if (testAction.getCommandLineArguments().isPresent()) {
Element commandLineArgumentElement =
serializeCommandLineArguments(doc, testAction.getCommandLineArguments().get());
testActionElem.appendChild(commandLineArgumentElement);
}

if (testAction.getApplicationLanguage().isPresent()) {
testActionElem.setAttribute("language", testAction.getApplicationLanguage().get());
}
Expand Down Expand Up @@ -569,6 +599,12 @@ public static Element serializeLaunchAction(Document doc, XCScheme.LaunchAction
launchActionElem.appendChild(environmentVariablesElement);
}

if (launchAction.getCommandLineArguments().isPresent()) {
Element commandLineArgumentElement =
serializeCommandLineArguments(doc, launchAction.getCommandLineArguments().get());
launchActionElem.appendChild(commandLineArgumentElement);
}

if (launchAction.getApplicationLanguage().isPresent()) {
launchActionElem.setAttribute("language", launchAction.getApplicationLanguage().get());
}
Expand Down Expand Up @@ -607,6 +643,12 @@ public static Element serializeProfileAction(Document doc, XCScheme.ProfileActio
profileActionElem.appendChild(environmentVariablesElement);
}

if (profileAction.getCommandLineArguments().isPresent()) {
Element commandLineArgumentElement =
serializeCommandLineArguments(doc, profileAction.getCommandLineArguments().get());
profileActionElem.appendChild(commandLineArgumentElement);
}

return profileActionElem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,8 @@ private SchemeGenerator buildSchemeGenerator(
Optional<ImmutableMap<SchemeActionType, PBXTarget>> expandVariablesBasedOn) {
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> environmentVariables =
Optional.empty();
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> commandLineArguments =
Optional.empty();
Optional<
ImmutableMap<
SchemeActionType, ImmutableMap<XCScheme.AdditionalActions, ImmutableList<String>>>>
Expand All @@ -1277,6 +1279,7 @@ private SchemeGenerator buildSchemeGenerator(

if (schemeConfigArg.isPresent()) {
environmentVariables = schemeConfigArg.get().getEnvironmentVariables();
commandLineArguments = schemeConfigArg.get().getCommandLineArguments();
additionalSchemeActions = schemeConfigArg.get().getAdditionalSchemeActions();
launchStyle = schemeConfigArg.get().getLaunchStyle().orElse(launchStyle);
watchInterface = schemeConfigArg.get().getWatchInterface();
Expand All @@ -1302,6 +1305,7 @@ private SchemeGenerator buildSchemeGenerator(
targetToProjectPathMap,
environmentVariables,
expandVariablesBasedOn,
commandLineArguments,
additionalSchemeActions,
launchStyle,
watchInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class SchemeGenerator {
private final Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>>
environmentVariables;
private final Optional<ImmutableMap<SchemeActionType, PBXTarget>> expandVariablesBasedOn;
private final Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>>
commandLineArguments;
private Optional<
ImmutableMap<SchemeActionType, ImmutableMap<AdditionalActions, ImmutableList<String>>>>
additionalSchemeActions;
Expand All @@ -112,6 +114,7 @@ public SchemeGenerator(
ImmutableMap<PBXTarget, Path> targetToProjectPathMap,
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> environmentVariables,
Optional<ImmutableMap<SchemeActionType, PBXTarget>> expandVariablesBasedOn,
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> commandLineArguments,
Optional<
ImmutableMap<
SchemeActionType, ImmutableMap<AdditionalActions, ImmutableList<String>>>>
Expand All @@ -138,6 +141,7 @@ public SchemeGenerator(
this.targetToProjectPathMap = targetToProjectPathMap;
this.environmentVariables = environmentVariables;
this.expandVariablesBasedOn = expandVariablesBasedOn;
this.commandLineArguments = commandLineArguments;
this.additionalSchemeActions = additionalSchemeActions;
this.notificationPayloadFile = notificationPayloadFile;
this.applicationLanguage = applicationLanguage;
Expand Down Expand Up @@ -250,11 +254,17 @@ public Path writeScheme() throws IOException {
}
}

ImmutableMap<SchemeActionType, ImmutableMap<String, String>> commandLineArgs = ImmutableMap.of();
if (commandLineArguments.isPresent()) {
commandLineArgs = commandLineArguments.get();
}

XCScheme.TestAction testAction =
new XCScheme.TestAction(
Objects.requireNonNull(actionConfigNames.get(SchemeActionType.TEST)),
Optional.ofNullable(envVariables.get(SchemeActionType.TEST)),
Optional.ofNullable(envVariablesBasedOn.get(SchemeActionType.TEST)),
Optional.ofNullable(commandLineArgs.get(SchemeActionType.TEST)),
additionalCommandsForSchemeAction(
SchemeActionType.TEST, AdditionalActions.PRE_SCHEME_ACTIONS, primaryBuildReference),
additionalCommandsForSchemeAction(
Expand Down Expand Up @@ -290,6 +300,7 @@ public Path writeScheme() throws IOException {
launchStyle,
Optional.ofNullable(envVariables.get(SchemeActionType.LAUNCH)),
Optional.ofNullable(envVariablesBasedOn.get(SchemeActionType.LAUNCH)),
Optional.ofNullable(commandLineArgs.get(SchemeActionType.LAUNCH)),
additionalCommandsForSchemeAction(
SchemeActionType.LAUNCH,
AdditionalActions.PRE_SCHEME_ACTIONS,
Expand All @@ -309,6 +320,7 @@ public Path writeScheme() throws IOException {
Objects.requireNonNull(actionConfigNames.get(SchemeActionType.PROFILE)),
Optional.ofNullable(envVariables.get(SchemeActionType.PROFILE)),
Optional.ofNullable(envVariablesBasedOn.get(SchemeActionType.PROFILE)),
Optional.ofNullable(commandLineArgs.get(SchemeActionType.PROFILE)),
additionalCommandsForSchemeAction(
SchemeActionType.PROFILE,
AdditionalActions.PRE_SCHEME_ACTIONS,
Expand Down Expand Up @@ -446,6 +458,18 @@ public static Element serializeEnvironmentVariables(
return rootElement;
}

public static Element serializeCommandLineArguments(
Document doc, ImmutableMap<String, String> commandLineArguments) {
Element rootElement = doc.createElement("CommandLineArguments");
for (String argumentKey : commandLineArguments.keySet()) {
Element argumentElement = doc.createElement("CommandLineArgument");
argumentElement.setAttribute("argument", argumentKey);
argumentElement.setAttribute("isEnabled", commandLineArguments.get(argumentKey));
rootElement.appendChild(argumentElement);
}
return rootElement;
}

public static Element serializeExpandVariablesBasedOn(
Document doc, XCScheme.BuildableReference reference) {
Element referenceElement = serializeBuildableReference(doc, reference);
Expand Down Expand Up @@ -522,6 +546,12 @@ public static Element serializeTestAction(Document doc, XCScheme.TestAction test
testActionElem.appendChild(environmentVariablesElement);
}

if (testAction.getCommandLineArguments().isPresent()) {
Element commandLineArgumentElement =
serializeCommandLineArguments(doc, testAction.getCommandLineArguments().get());
testActionElem.appendChild(commandLineArgumentElement);
}

if (testAction.getApplicationLanguage().isPresent()) {
testActionElem.setAttribute("language", testAction.getApplicationLanguage().get());
}
Expand Down Expand Up @@ -605,6 +635,12 @@ public static Element serializeLaunchAction(Document doc, XCScheme.LaunchAction
launchActionElem.appendChild(environmentVariablesElement);
}

if (launchAction.getCommandLineArguments().isPresent()) {
Element commandLineArgumentElement =
serializeCommandLineArguments(doc, launchAction.getCommandLineArguments().get());
launchActionElem.appendChild(commandLineArgumentElement);
}

if (launchAction.getApplicationLanguage().isPresent()) {
launchActionElem.setAttribute("language", launchAction.getApplicationLanguage().get());
}
Expand Down Expand Up @@ -643,6 +679,12 @@ public static Element serializeProfileAction(Document doc, XCScheme.ProfileActio
profileActionElem.appendChild(environmentVariablesElement);
}

if (profileAction.getCommandLineArguments().isPresent()) {
Element commandLineArgumentElement =
serializeCommandLineArguments(doc, profileAction.getCommandLineArguments().get());
profileActionElem.appendChild(commandLineArgumentElement);
}

return profileActionElem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ private SchemeGenerator buildSchemeGenerator(
Optional<ImmutableMap<SchemeActionType, PBXTarget>> expandVariablesBasedOn) {
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> environmentVariables =
Optional.empty();
Optional<ImmutableMap<SchemeActionType, ImmutableMap<String, String>>> commandLineArguments =
Optional.empty();
Optional<
ImmutableMap<
SchemeActionType, ImmutableMap<XCScheme.AdditionalActions, ImmutableList<String>>>>
Expand All @@ -953,6 +955,7 @@ private SchemeGenerator buildSchemeGenerator(

if (schemeConfigArg.isPresent()) {
environmentVariables = schemeConfigArg.get().getEnvironmentVariables();
commandLineArguments = schemeConfigArg.get().getCommandLineArguments();
additionalSchemeActions = schemeConfigArg.get().getAdditionalSchemeActions();
launchStyle = schemeConfigArg.get().getLaunchStyle().orElse(launchStyle);
watchInterface = schemeConfigArg.get().getWatchInterface();
Expand All @@ -978,6 +981,7 @@ private SchemeGenerator buildSchemeGenerator(
targetToProjectPathMap,
environmentVariables,
expandVariablesBasedOn,
commandLineArguments,
additionalSchemeActions,
launchStyle,
watchInterface,
Expand Down
Loading

0 comments on commit 0a914c7

Please sign in to comment.