From 0a914c7b4316680e152fe65a6c6684596aeefe5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=ADcero=20Duarte?= Date: Mon, 29 Mar 2021 14:02:46 -0300 Subject: [PATCH] [Apple] Added command_line_arguments to xcode_workspace_config (#2560) * Adding commandLineArguments to XCScheme * Adding commandLineArguments to projectV2 * Renaming envVariableList to commandLineArgsList --- .../facebook/buck/apple/xcode/XCScheme.java | 21 +++++ .../XcodeWorkspaceConfigDescription.java | 3 + .../apple/project/SchemeGenerator.java | 42 ++++++++++ .../project/WorkspaceAndProjectGenerator.java | 4 + .../apple/projectV2/SchemeGenerator.java | 42 ++++++++++ .../WorkspaceAndProjectGenerator.java | 4 + .../apple/project/SchemeGeneratorTest.java | 79 ++++++++++++++++++ .../apple/projectV2/SchemeGeneratorTest.java | 80 +++++++++++++++++++ 8 files changed, 275 insertions(+) diff --git a/src/com/facebook/buck/apple/xcode/XCScheme.java b/src/com/facebook/buck/apple/xcode/XCScheme.java index 19b305b849f..2f955ca6aff 100644 --- a/src/com/facebook/buck/apple/xcode/XCScheme.java +++ b/src/com/facebook/buck/apple/xcode/XCScheme.java @@ -254,6 +254,7 @@ public enum WatchInterface { private final LaunchStyle launchStyle; private final Optional> environmentVariables; private final Optional expandVariablesBasedOn; + private final Optional> commandLineArguments; private final Optional notificationPayloadFile; private final Optional applicationLanguage; private final Optional applicationRegion; @@ -267,6 +268,7 @@ public LaunchAction( LaunchStyle launchStyle, Optional> environmentVariables, Optional expandVariablesBasedOn, + Optional> commandLineArguments, Optional> preActions, Optional> postActions, Optional notificationPayloadFile, @@ -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; @@ -322,6 +325,10 @@ public Optional getExpandVariablesBasedOn() { return expandVariablesBasedOn; } + public Optional> getCommandLineArguments() { + return commandLineArguments; + } + public Optional getApplicationLanguage() { return applicationLanguage; } @@ -336,12 +343,14 @@ public static class ProfileAction extends SchemeAction { private final String buildConfiguration; private final Optional> environmentVariables; private final Optional expandVariablesBasedOn; + private final Optional> commandLineArguments; public ProfileAction( BuildableReference buildableReference, String buildConfiguration, Optional> environmentVariables, Optional expandVariablesBasedOn, + Optional> commandLineArguments, Optional> preActions, Optional> postActions) { super(preActions, postActions); @@ -349,6 +358,7 @@ public ProfileAction( this.buildConfiguration = buildConfiguration; this.environmentVariables = environmentVariables; this.expandVariablesBasedOn = expandVariablesBasedOn; + this.commandLineArguments = commandLineArguments; } public BuildableReference getBuildableReference() { @@ -366,6 +376,10 @@ public Optional> getEnvironmentVariables() { public Optional getExpandVariablesBasedOn() { return expandVariablesBasedOn; } + + public Optional> getCommandLineArguments() { + return commandLineArguments; + } } public static class TestAction extends SchemeAction { @@ -373,6 +387,7 @@ public static class TestAction extends SchemeAction { private final String buildConfiguration; private final Optional> environmentVariables; private final Optional expandVariablesBasedOn; + private final Optional> commandLineArguments; private final Optional applicationLanguage; private final Optional applicationRegion; @@ -380,6 +395,7 @@ public TestAction( String buildConfiguration, Optional> environmentVariables, Optional expandVariablesBasedOn, + Optional> commandLineArguments, Optional> preActions, Optional> postActions, Optional applicationLanguage, @@ -389,6 +405,7 @@ public TestAction( this.buildConfiguration = buildConfiguration; this.environmentVariables = environmentVariables; this.expandVariablesBasedOn = expandVariablesBasedOn; + this.commandLineArguments = commandLineArguments; this.applicationLanguage = applicationLanguage; this.applicationRegion = applicationRegion; } @@ -413,6 +430,10 @@ public Optional getExpandVariablesBasedOn() { return expandVariablesBasedOn; } + public Optional> getCommandLineArguments() { + return commandLineArguments; + } + public Optional getApplicationLanguage() { return applicationLanguage; } diff --git a/src/com/facebook/buck/features/apple/common/XcodeWorkspaceConfigDescription.java b/src/com/facebook/buck/features/apple/common/XcodeWorkspaceConfigDescription.java index 8117ad07519..be3088704f9 100644 --- a/src/com/facebook/buck/features/apple/common/XcodeWorkspaceConfigDescription.java +++ b/src/com/facebook/buck/features/apple/common/XcodeWorkspaceConfigDescription.java @@ -100,6 +100,9 @@ interface AbstractXcodeWorkspaceConfigDescriptionArg extends BuildRuleArg { Optional>> getEnvironmentVariables(); + Optional>> + getCommandLineArguments(); + Optional getApplicationLanguage(); Optional getApplicationRegion(); diff --git a/src/com/facebook/buck/features/apple/project/SchemeGenerator.java b/src/com/facebook/buck/features/apple/project/SchemeGenerator.java index 1e5d08fade8..01af304e4dc 100644 --- a/src/com/facebook/buck/features/apple/project/SchemeGenerator.java +++ b/src/com/facebook/buck/features/apple/project/SchemeGenerator.java @@ -89,6 +89,8 @@ class SchemeGenerator { private final Optional>> environmentVariables; private final Optional> expandVariablesBasedOn; + private final Optional>> + commandLineArguments; private Optional< ImmutableMap< SchemeActionType, ImmutableMap>>> @@ -112,6 +114,7 @@ public SchemeGenerator( ImmutableMap targetToProjectPathMap, Optional>> environmentVariables, Optional> expandVariablesBasedOn, + Optional>> commandLineArguments, Optional< ImmutableMap< SchemeActionType, @@ -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; @@ -255,11 +259,17 @@ public Path writeScheme() throws IOException { } } + ImmutableMap> 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( @@ -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, @@ -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, @@ -409,6 +421,18 @@ public static Element serializeEnvironmentVariables( return rootElement; } + public static Element serializeCommandLineArguments( + Document doc, ImmutableMap 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); @@ -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()); } @@ -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()); } @@ -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; } diff --git a/src/com/facebook/buck/features/apple/project/WorkspaceAndProjectGenerator.java b/src/com/facebook/buck/features/apple/project/WorkspaceAndProjectGenerator.java index 0a8081a8b4d..20f0233e691 100644 --- a/src/com/facebook/buck/features/apple/project/WorkspaceAndProjectGenerator.java +++ b/src/com/facebook/buck/features/apple/project/WorkspaceAndProjectGenerator.java @@ -1264,6 +1264,8 @@ private SchemeGenerator buildSchemeGenerator( Optional> expandVariablesBasedOn) { Optional>> environmentVariables = Optional.empty(); + Optional>> commandLineArguments = + Optional.empty(); Optional< ImmutableMap< SchemeActionType, ImmutableMap>>> @@ -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(); @@ -1302,6 +1305,7 @@ private SchemeGenerator buildSchemeGenerator( targetToProjectPathMap, environmentVariables, expandVariablesBasedOn, + commandLineArguments, additionalSchemeActions, launchStyle, watchInterface, diff --git a/src/com/facebook/buck/features/apple/projectV2/SchemeGenerator.java b/src/com/facebook/buck/features/apple/projectV2/SchemeGenerator.java index 4b66208622a..851f4f46a1a 100644 --- a/src/com/facebook/buck/features/apple/projectV2/SchemeGenerator.java +++ b/src/com/facebook/buck/features/apple/projectV2/SchemeGenerator.java @@ -90,6 +90,8 @@ class SchemeGenerator { private final Optional>> environmentVariables; private final Optional> expandVariablesBasedOn; + private final Optional>> + commandLineArguments; private Optional< ImmutableMap>>> additionalSchemeActions; @@ -112,6 +114,7 @@ public SchemeGenerator( ImmutableMap targetToProjectPathMap, Optional>> environmentVariables, Optional> expandVariablesBasedOn, + Optional>> commandLineArguments, Optional< ImmutableMap< SchemeActionType, ImmutableMap>>> @@ -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; @@ -250,11 +254,17 @@ public Path writeScheme() throws IOException { } } + ImmutableMap> 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( @@ -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, @@ -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, @@ -446,6 +458,18 @@ public static Element serializeEnvironmentVariables( return rootElement; } + public static Element serializeCommandLineArguments( + Document doc, ImmutableMap 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); @@ -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()); } @@ -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()); } @@ -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; } diff --git a/src/com/facebook/buck/features/apple/projectV2/WorkspaceAndProjectGenerator.java b/src/com/facebook/buck/features/apple/projectV2/WorkspaceAndProjectGenerator.java index 95a2d51f438..5e472e623f7 100644 --- a/src/com/facebook/buck/features/apple/projectV2/WorkspaceAndProjectGenerator.java +++ b/src/com/facebook/buck/features/apple/projectV2/WorkspaceAndProjectGenerator.java @@ -940,6 +940,8 @@ private SchemeGenerator buildSchemeGenerator( Optional> expandVariablesBasedOn) { Optional>> environmentVariables = Optional.empty(); + Optional>> commandLineArguments = + Optional.empty(); Optional< ImmutableMap< SchemeActionType, ImmutableMap>>> @@ -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(); @@ -978,6 +981,7 @@ private SchemeGenerator buildSchemeGenerator( targetToProjectPathMap, environmentVariables, expandVariablesBasedOn, + commandLineArguments, additionalSchemeActions, launchStyle, watchInterface, diff --git a/test/com/facebook/buck/features/apple/project/SchemeGeneratorTest.java b/test/com/facebook/buck/features/apple/project/SchemeGeneratorTest.java index 3c37e6b0ca5..f42e117b94e 100644 --- a/test/com/facebook/buck/features/apple/project/SchemeGeneratorTest.java +++ b/test/com/facebook/buck/features/apple/project/SchemeGeneratorTest.java @@ -129,6 +129,7 @@ public void schemeWithMultipleTargetsBuildsInCorrectOrder() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -218,6 +219,7 @@ public void schemeBuildsAndTestsAppleTestTargets() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -316,6 +318,7 @@ public void schemeIncludesAllExpectedActions() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -399,6 +402,7 @@ public void buildableReferenceShouldHaveExpectedProperties() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -466,6 +470,7 @@ public void allActionsShouldBePresentInSchemeWithDefaultBuildConfigurations() th Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -556,6 +561,7 @@ public void schemeIsRewrittenIfContentsHaveChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -597,6 +603,7 @@ public void schemeIsRewrittenIfContentsHaveChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -641,6 +648,7 @@ public void schemeIsNotRewrittenIfContentsHaveNotChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -682,6 +690,7 @@ public void schemeIsNotRewrittenIfContentsHaveNotChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -747,6 +756,7 @@ public void schemeWithNoPrimaryRuleCanIncludeTests() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -859,6 +869,7 @@ public void launchActionShouldNotContainRemoteRunnableWhenNotProvided() throws E Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -915,6 +926,7 @@ public void launchActionShouldContainRemoteRunnableWhenProvided() throws Excepti Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -999,6 +1011,7 @@ public void prePostActionsSerializedWithRootBuildable() throws Exception { targetToProjectPathMapBuilder.build(), Optional.empty(), Optional.empty(), + Optional.empty(), Optional.of(schemeActions), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ @@ -1079,6 +1092,7 @@ public void enablingParallelizeBuild() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1145,6 +1159,7 @@ public void serializesEnvironmentVariables() throws Exception { Optional.of(environmentVariables), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1169,6 +1184,67 @@ public void serializesEnvironmentVariables() throws Exception { assertThat(envVar.getAttributes().getNamedItem("value").getNodeValue(), equalTo("IS_SET")); } + @Test + public void serializesCommandLineArguments() throws Exception { + ImmutableMap.Builder targetToProjectPathMapBuilder = ImmutableMap.builder(); + + PBXTarget rootTarget = + new PBXNativeTarget("rootRule", AbstractPBXObjectFactory.DefaultFactory()); + rootTarget.setGlobalID("rootGID"); + rootTarget.setProductReference( + new PBXFileReference( + "root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty())); + rootTarget.setProductType(ProductTypes.STATIC_LIBRARY); + + Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj"); + targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath); + + ImmutableMap> commandLineArguments = + ImmutableMap.of(SchemeActionType.LAUNCH, ImmutableMap.of("COMMAND_ARG", "YES")); + + SchemeGenerator schemeGenerator = + new SchemeGenerator( + projectFilesystem, + Optional.of(rootTarget), + ImmutableSet.of(rootTarget), + ImmutableSet.of(), + ImmutableSet.of(), + "TestScheme", + Paths.get("_gen/Foo.xcworkspace/xcshareddata/xcshemes"), + true /* parallelizeBuild */, + Optional.of(true) /* wasCreatedForAppExtension */, + Optional.empty() /* runnablePath */, + Optional.empty() /* remoteRunnablePath */, + SchemeActionType.DEFAULT_CONFIG_NAMES, + targetToProjectPathMapBuilder.build(), + Optional.empty(), + Optional.empty(), + Optional.of(commandLineArguments), /* commandLineArguments */ + Optional.empty(), + XCScheme.LaunchAction.LaunchStyle.AUTO, + Optional.empty(), /* watchAdapter */ + Optional.empty(), /* notificationPayloadFile */ + Optional.empty(), /* applicationRegion */ + Optional.empty() /* applicationLanguage */); + + Path schemePath = schemeGenerator.writeScheme(); + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath)); + + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath buildActionXpath = xpathFactory.newXPath(); + XPathExpression buildActionExpr = + buildActionXpath.compile("//LaunchAction/CommandLineArguments/CommandLineArgument"); + NodeList commandLineArgsList = (NodeList) buildActionExpr.evaluate(scheme, XPathConstants.NODESET); + + assertThat(commandLineArgsList.getLength(), is(1)); + Node commandLineArgument = commandLineArgsList.item(0); + assertThat(commandLineArgument.getAttributes().getNamedItem("argument").getNodeValue(), equalTo("COMMAND_ARG")); + assertThat(commandLineArgument.getAttributes().getNamedItem("isEnabled").getNodeValue(), equalTo("YES")); + } + @Test public void serializesRegionAndLanguage() throws Exception { ImmutableMap.Builder targetToProjectPathMapBuilder = ImmutableMap.builder(); @@ -1205,6 +1281,7 @@ public void serializesRegionAndLanguage() throws Exception { Optional.empty() /* environmentVariables */, Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1271,6 +1348,7 @@ public void serializesWasCreatedForAppExtension() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1337,6 +1415,7 @@ public void excludesWasCreatedForAppExtension() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ diff --git a/test/com/facebook/buck/features/apple/projectV2/SchemeGeneratorTest.java b/test/com/facebook/buck/features/apple/projectV2/SchemeGeneratorTest.java index 0a92f43b9a8..c9f0a0498ec 100644 --- a/test/com/facebook/buck/features/apple/projectV2/SchemeGeneratorTest.java +++ b/test/com/facebook/buck/features/apple/projectV2/SchemeGeneratorTest.java @@ -130,6 +130,7 @@ public void schemeWithMultipleTargetsBuildsInCorrectOrder() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -219,6 +220,7 @@ public void schemeBuildsAndTestsAppleTestTargets() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -317,6 +319,7 @@ public void schemeIncludesAllExpectedActions() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -401,6 +404,7 @@ public void buildableReferenceShouldHaveExpectedProperties() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -467,6 +471,7 @@ public void allActionsShouldBePresentInSchemeWithDefaultBuildConfigurations() th Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -557,6 +562,7 @@ public void schemeIsRewrittenIfContentsHaveChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -598,6 +604,7 @@ public void schemeIsRewrittenIfContentsHaveChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -642,6 +649,7 @@ public void schemeIsNotRewrittenIfContentsHaveNotChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -683,6 +691,7 @@ public void schemeIsNotRewrittenIfContentsHaveNotChanged() throws IOException { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -748,6 +757,7 @@ public void schemeWithNoPrimaryRuleCanIncludeTests() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -860,6 +870,7 @@ public void launchActionShouldNotContainRemoteRunnableWhenNotProvided() throws E Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -916,6 +927,7 @@ public void launchActionShouldContainRemoteRunnableWhenProvided() throws Excepti Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1000,6 +1012,7 @@ public void prePostActionsSerializedWithRootBuildable() throws Exception { targetToProjectPathMapBuilder.build(), Optional.empty(), Optional.empty(), + Optional.empty(), Optional.of(schemeActions), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ @@ -1080,6 +1093,7 @@ public void enablingParallelizeBuild() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1146,6 +1160,7 @@ public void serializesEnvironmentVariables() throws Exception { Optional.of(environmentVariables), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1170,6 +1185,67 @@ public void serializesEnvironmentVariables() throws Exception { assertThat(envVar.getAttributes().getNamedItem("value").getNodeValue(), equalTo("IS_SET")); } + @Test + public void serializesCommandLineArguments() throws Exception { + ImmutableMap.Builder targetToProjectPathMapBuilder = ImmutableMap.builder(); + + PBXTarget rootTarget = + new PBXNativeTarget("rootRule", AbstractPBXObjectFactory.DefaultFactory()); + rootTarget.setGlobalID("rootGID"); + rootTarget.setProductReference( + new PBXFileReference( + "root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty())); + rootTarget.setProductType(ProductTypes.STATIC_LIBRARY); + + Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj"); + targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath); + + ImmutableMap> commandLineArguments = + ImmutableMap.of(SchemeActionType.LAUNCH, ImmutableMap.of("COMMAND_ARG", "YES")); + + SchemeGenerator schemeGenerator = + new SchemeGenerator( + projectFilesystem, + Optional.of(rootTarget), + ImmutableSet.of(rootTarget), + ImmutableSet.of(), + ImmutableSet.of(), + "TestScheme", + Paths.get("_gen/Foo.xcworkspace/xcshareddata/xcshemes"), + true /* parallelizeBuild */, + Optional.of(true) /* wasCreatedForAppExtension */, + Optional.empty() /* runnablePath */, + Optional.empty() /* remoteRunnablePath */, + SchemeActionType.DEFAULT_CONFIG_NAMES, + targetToProjectPathMapBuilder.build(), + Optional.empty(), + Optional.empty(), + Optional.of(commandLineArguments), /* commandLineArguments */ + Optional.empty(), + XCScheme.LaunchAction.LaunchStyle.AUTO, + Optional.empty(), /* watchAdapter */ + Optional.empty(), /* notificationPayloadFile */ + Optional.empty(), /* applicationRegion */ + Optional.empty() /* applicationLanguage */); + + Path schemePath = schemeGenerator.writeScheme(); + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath)); + + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath buildActionXpath = xpathFactory.newXPath(); + XPathExpression buildActionExpr = + buildActionXpath.compile("//LaunchAction/CommandLineArguments/CommandLineArgument"); + NodeList commandLineArgsList = (NodeList) buildActionExpr.evaluate(scheme, XPathConstants.NODESET); + + assertThat(commandLineArgsList.getLength(), is(1)); + Node commandLineArgument = commandLineArgsList.item(0); + assertThat(commandLineArgument.getAttributes().getNamedItem("argument").getNodeValue(), equalTo("COMMAND_ARG")); + assertThat(commandLineArgument.getAttributes().getNamedItem("isEnabled").getNodeValue(), equalTo("YES")); + } + @Test public void serializesRegionAndLanguage() throws Exception { ImmutableMap.Builder targetToProjectPathMapBuilder = ImmutableMap.builder(); @@ -1206,6 +1282,7 @@ public void serializesRegionAndLanguage() throws Exception { Optional.empty() /* environmentVariables */, Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1272,6 +1349,7 @@ public void expandVariablesBasedOnSetIfPresent() throws Exception { Optional.of(environmentVariables), Optional.of(expandVariablesBasedOn), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1338,6 +1416,7 @@ public void serializesWasCreatedForAppExtension() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */ @@ -1404,6 +1483,7 @@ public void excludesWasCreatedForAppExtension() throws Exception { Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), XCScheme.LaunchAction.LaunchStyle.AUTO, Optional.empty(), /* watchAdapter */ Optional.empty(), /* notificationPayloadFile */