Skip to content

Commit

Permalink
Get rid of unnecessary constructor parameters in ObjcCppSemantics
Browse files Browse the repository at this point in the history
This should make any Starlark migration easier.  Ideally the
constructor should have no arguments like CppSemantics -- we're not
there but this is at least a step in that direction.

PiperOrigin-RevId: 364580871
  • Loading branch information
googlewalt authored and copybara-github committed Mar 23, 2021
1 parent e3860b8 commit 49702ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ public class CompilationSupport {
"c-compile",
"c++-compile");

/** The kind of include processing to use. */
enum IncludeProcessingType {
INCLUDE_SCANNING,
NO_PROCESSING;
}

/** Returns the location of the xcrunwrapper tool. */
public static final FilesToRunProvider xcrunwrapper(RuleContext ruleContext) {
return ruleContext.getExecutablePrerequisite("$xcrunwrapper");
Expand Down Expand Up @@ -531,8 +525,6 @@ private CompilationResult ccCompileAndLink(

ObjcCppSemantics createObjcCppSemantics() {
return new ObjcCppSemantics(
includeProcessingType,
ruleContext.getFragment(ObjcConfiguration.class),
intermediateArtifacts,
buildConfiguration,
attributes.enableModules());
Expand Down Expand Up @@ -734,7 +726,6 @@ static ImmutableList<String> frameworkLibrarySearchPaths(ObjcProvider provider)
private final boolean usePch;
private final boolean disableLayeringCheck;
private final boolean disableParseHeaders;
private final IncludeProcessingType includeProcessingType;
private Optional<CcCompilationContext> ccCompilationContext;

private void setCcCompilationContext(CcCompilationContext ccCompilationContext) {
Expand Down Expand Up @@ -792,12 +783,6 @@ private CompilationSupport(
}

this.toolchain = toolchain;

if (objcConfiguration.shouldScanIncludes()) {
includeProcessingType = IncludeProcessingType.INCLUDE_SCANNING;
} else {
includeProcessingType = IncludeProcessingType.NO_PROCESSING;
}
}

/** Builder for {@link CompilationSupport} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package com.google.devtools.build.lib.rules.objc;

import static com.google.devtools.build.lib.rules.objc.CompilationSupport.IncludeProcessingType.INCLUDE_SCANNING;

import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.RuleErrorConsumer;
Expand All @@ -31,36 +29,27 @@
import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode;
import com.google.devtools.build.lib.rules.cpp.CppSemantics;
import com.google.devtools.build.lib.rules.cpp.HeaderDiscovery.DotdPruningMode;
import com.google.devtools.build.lib.rules.objc.CompilationSupport.IncludeProcessingType;

/**
* CppSemantics for objc builds.
*/
public class ObjcCppSemantics implements CppSemantics {

private final IncludeProcessingType includeProcessingType;
private final ObjcConfiguration config;
private final IntermediateArtifacts intermediateArtifacts;
private final BuildConfiguration buildConfiguration;
private final boolean enableModules;

/**
* Creates an instance of ObjcCppSemantics
*
* @param includeProcessingType The type of include processing to be run.
* @param config the ObjcConfiguration for this build
* @param intermediateArtifacts used to create headers_list artifacts
* @param buildConfiguration the build configuration for this build
* @param enableModules whether modules are enabled
*/
public ObjcCppSemantics(
IncludeProcessingType includeProcessingType,
ObjcConfiguration config,
IntermediateArtifacts intermediateArtifacts,
BuildConfiguration buildConfiguration,
boolean enableModules) {
this.includeProcessingType = includeProcessingType;
this.config = config;
this.intermediateArtifacts = intermediateArtifacts;
this.buildConfiguration = buildConfiguration;
this.enableModules = enableModules;
Expand All @@ -78,7 +67,8 @@ public void finalizeCompileActionBuilder(
// system framework headers since they are not being scanned right now.
// TODO(waltl): do better with include scanning.
.addTransitiveMandatoryInputs(actionBuilder.getToolchain().getAllFilesMiddleman())
.setShouldScanIncludes(includeProcessingType == INCLUDE_SCANNING);
.setShouldScanIncludes(
configuration.getFragment(ObjcConfiguration.class).shouldScanIncludes());
}

@Override
Expand All @@ -97,12 +87,13 @@ public HeadersCheckingMode determineStarlarkHeadersCheckingMode(

@Override
public boolean allowIncludeScanning() {
return includeProcessingType == IncludeProcessingType.INCLUDE_SCANNING;
return true;
}

@Override
public boolean needsDotdInputPruning(BuildConfiguration configuration) {
return config.getDotdPruningPlan() == DotdPruningMode.USE;
return configuration.getFragment(ObjcConfiguration.class).getDotdPruningPlan()
== DotdPruningMode.USE;
}

@Override
Expand All @@ -111,10 +102,10 @@ public void validateAttributes(RuleContext ruleContext) {

@Override
public boolean needsIncludeValidation() {
// We disable include valication when modules are enabled, because Apple uses absolute paths in
// We disable include validation when modules are enabled, because Apple uses absolute paths in
// its module maps, which include validation does not recognize. Modules should only be used
// rarely and in third party code anyways.
return (includeProcessingType == INCLUDE_SCANNING) && !enableModules;
return !enableModules;
}

/**
Expand Down

0 comments on commit 49702ed

Please sign in to comment.