Skip to content
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

Create param files with absolute path #3115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/generators/target_build_settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The generator accepts the following command-line arguments:
- If `swift-debug-settings-output-path` is set: positional `include-self-swift-debug-settings`
- If `swift-debug-settings-output-path` is set: positional `transitive-swift-debug-setting-paths-count`
- If `swift-debug-settings-output-path` is set: positional list `<transitive-swift-debug-setting-paths> ...`
- Positional `execution-root-file-path`
- Positional `device-family`
- Positional `extension-safe`
- Positional `generates-dsyms`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ struct Generator {
transitiveSwiftDebugSettingPaths = []
}

let executionRootFilePath = try rawArguments.consumeArg("execution-root-file-path", as: URL?.self)

let (buildSettings, clangArgs, frameworkIncludes, swiftIncludes) =
try await environment.processArgs(
rawArguments: rawArguments,
generateBuildSettings: buildSettingsOutputPath != nil,
includeSelfSwiftDebugSettings: includeSelfSwiftDebugSettings,
transitiveSwiftDebugSettingPaths:
transitiveSwiftDebugSettingPaths
transitiveSwiftDebugSettingPaths,
executionRootFilePath: executionRootFilePath
)

let writeBuildSettingsTask = Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ extension Generator {
rawArguments: Array<String>.SubSequence,
generateBuildSettings: Bool,
includeSelfSwiftDebugSettings: Bool,
transitiveSwiftDebugSettingPaths: [URL]
transitiveSwiftDebugSettingPaths: [URL],
executionRootFilePath: URL?
) async throws -> (
buildSettings: [(key: String, value: String)],
clangArgs: [String],
Expand All @@ -44,6 +45,7 @@ extension Generator {
includeSelfSwiftDebugSettings,
/*transitiveSwiftDebugSettingPaths:*/
transitiveSwiftDebugSettingPaths,
/*executionRootFilePath:*/ executionRootFilePath,
/*processCArgs:*/ processCArgs,
/*processCxxArgs:*/ processCxxArgs,
/*processSwiftArgs:*/ processSwiftArgs
Expand All @@ -60,6 +62,7 @@ extension Generator.ProcessArgs {
_ generateBuildSettings: Bool,
_ includeSelfSwiftDebugSettings: Bool,
_ transitiveSwiftDebugSettingPaths: [URL],
_ executionRootFilePath: URL?,
_ processCArgs: Generator.ProcessCArgs,
_ processCxxArgs: Generator.ProcessCxxArgs,
_ processSwiftArgs: Generator.ProcessSwiftArgs
Expand All @@ -75,6 +78,7 @@ extension Generator.ProcessArgs {
generateBuildSettings: Bool,
includeSelfSwiftDebugSettings: Bool,
transitiveSwiftDebugSettingPaths: [URL],
executionRootFilePath: URL?,
processCArgs: Generator.ProcessCArgs,
processCxxArgs: Generator.ProcessCxxArgs,
processSwiftArgs: Generator.ProcessSwiftArgs
Expand Down Expand Up @@ -130,12 +134,14 @@ extension Generator.ProcessArgs {

let cHasDebugInfo = try await processCArgs(
argsStream: argsStream,
buildSettings: &buildSettings
buildSettings: &buildSettings,
executionRootFilePath: executionRootFilePath
)

let cxxHasDebugInfo = try await processCxxArgs(
argsStream: argsStream,
buildSettings: &buildSettings
buildSettings: &buildSettings,
executionRootFilePath: executionRootFilePath
)

if generatesDsyms || swiftHasDebugInfo || cHasDebugInfo ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import PBXProj
import ToolCommon

extension Generator {
struct ProcessCArgs {
Expand All @@ -25,11 +26,13 @@ extension Generator {
/// Processes all the C/Objective-C arguments.
func callAsFunction(
argsStream: AsyncThrowingStream<String, Error>,
buildSettings: inout [(key: String, value: String)]
buildSettings: inout [(key: String, value: String)],
executionRootFilePath: URL?
) async throws -> Bool {
try await callable(
/*argsStream:*/ argsStream,
/*buildSettings:*/ &buildSettings,
executionRootFilePath,
/*processCcArgs:*/ processCcArgs,
/*write:*/ write
)
Expand All @@ -43,13 +46,15 @@ extension Generator.ProcessCArgs {
typealias Callable = (
_ argsStream: AsyncThrowingStream<String, Error>,
_ buildSettings: inout [(key: String, value: String)],
_ executionRootFilePath: URL?,
_ processCcArgs: Generator.ProcessCcArgs,
_ write: Write
) async throws -> Bool

static func defaultCallable(
argsStream: AsyncThrowingStream<String, Error>,
buildSettings: inout [(key: String, value: String)],
executionRootFilePath: URL?,
processCcArgs: Generator.ProcessCcArgs,
write: Write
) async throws -> Bool {
Expand All @@ -70,7 +75,34 @@ extension Generator.ProcessCArgs {
argsStream: argsStream
)

let content = args.map { $0 + "\n" }.joined()
var PROJECT_DIR = ""
if let execRootURL = executionRootFilePath {
PROJECT_DIR = try String(contentsOf: execRootURL, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines)
}
let BAZEL_OUT = PROJECT_DIR + "/bazel-out"

let (DEVELOPER_DIR, SDKROOT) = (ProcessInfo.processInfo.environment["DEVELOPER_DIR"] ?? "", ProcessInfo.processInfo.environment["SDKROOT"] ?? "")
guard !DEVELOPER_DIR.isEmpty, !SDKROOT.isEmpty, !PROJECT_DIR.isEmpty else {
throw PreconditionError(message: """
`DEVELOPER_DIR`, `SDKROOT`, and `PROJECT_DIR` must be set in the environment.
""")
}

let environmentVariables: [String: String] = [
"$(PROJECT_DIR)": PROJECT_DIR,
"$(BAZEL_OUT)": BAZEL_OUT,
"$(DEVELOPER_DIR)": DEVELOPER_DIR,
"$(SDKROOT)": SDKROOT
]

let content = try args.map { arg -> String in
var newArg = arg
for (key, value) in environmentVariables {
newArg = newArg.replacingOccurrences(of: key, with: value)
}
return newArg + "\n"
}.joined()

try write(content, to: URL(fileURLWithPath: String(outputPath)))

buildSettings.append(
Expand All @@ -92,15 +124,17 @@ extension Generator.ProcessCArgs {
(
"ASAN_OTHER_CFLAGS__NO",
#"""
"@$(DERIVED_FILE_DIR)/c.compile.params \#
"@$(BAZEL_OUT)\#(outputPath.dropFirst(9)) \#
-D_FORTIFY_SOURCE=\#(fortifySourceLevel)"
"""#
)
)
buildSettings.append(
(
"ASAN_OTHER_CFLAGS__YES",
#""@$(DERIVED_FILE_DIR)/c.compile.params""#
#"""
"@$(BAZEL_OUT)\#(outputPath.dropFirst(9))"
"""#
)
)
buildSettings.append(
Expand All @@ -115,7 +149,9 @@ extension Generator.ProcessCArgs {
buildSettings.append(
(
"OTHER_CFLAGS",
#""@$(DERIVED_FILE_DIR)/c.compile.params""#
#"""
"@$(BAZEL_OUT)\#(outputPath.dropFirst(9))"
"""#
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import PBXProj
import ToolCommon

extension Generator {
struct ProcessCxxArgs {
Expand All @@ -25,11 +26,13 @@ extension Generator {
/// Processes all the C++/Objective-C++ arguments.
func callAsFunction(
argsStream: AsyncThrowingStream<String, Error>,
buildSettings: inout [(key: String, value: String)]
buildSettings: inout [(key: String, value: String)],
executionRootFilePath: URL?
) async throws -> Bool {
try await callable(
/*argsStream:*/ argsStream,
/*buildSettings:*/ &buildSettings,
executionRootFilePath,
/*processCcArgs:*/ processCcArgs,
/*write:*/ write
)
Expand All @@ -43,13 +46,15 @@ extension Generator.ProcessCxxArgs {
typealias Callable = (
_ argsStream: AsyncThrowingStream<String, Error>,
_ buildSettings: inout [(key: String, value: String)],
_ executionRootFilePath: URL?,
_ processCcArgs: Generator.ProcessCcArgs,
_ write: Write
) async throws -> Bool

static func defaultCallable(
argsStream: AsyncThrowingStream<String, Error>,
buildSettings: inout [(key: String, value: String)],
executionRootFilePath: URL?,
processCcArgs: Generator.ProcessCcArgs,
write: Write
) async throws -> Bool {
Expand All @@ -70,7 +75,34 @@ extension Generator.ProcessCxxArgs {
argsStream: argsStream
)

let content = args.map { $0 + "\n" }.joined()
var PROJECT_DIR = ""
if let execRootURL = executionRootFilePath {
PROJECT_DIR = try String(contentsOf: execRootURL, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines)
}
let BAZEL_OUT = PROJECT_DIR + "/bazel-out"

let (DEVELOPER_DIR, SDKROOT) = (ProcessInfo.processInfo.environment["DEVELOPER_DIR"] ?? "", ProcessInfo.processInfo.environment["SDKROOT"] ?? "")
guard !DEVELOPER_DIR.isEmpty, !SDKROOT.isEmpty, !PROJECT_DIR.isEmpty else {
throw PreconditionError(message: """
`DEVELOPER_DIR`, `SDKROOT`, and `PROJECT_DIR` must be set in the environment.
""")
}

let environmentVariables: [String: String] = [
"$(PROJECT_DIR)": PROJECT_DIR,
"$(BAZEL_OUT)": BAZEL_OUT,
"$(DEVELOPER_DIR)": DEVELOPER_DIR,
"$(SDKROOT)": SDKROOT
]

let content = try args.map { arg -> String in
var newArg = arg
for (key, value) in environmentVariables {
newArg = newArg.replacingOccurrences(of: key, with: value)
}
return newArg + "\n"
}.joined()

try write(content, to: URL(fileURLWithPath: String(outputPath)))

buildSettings.append(
Expand All @@ -93,15 +125,17 @@ extension Generator.ProcessCxxArgs {
(
"ASAN_OTHER_CPLUSPLUSFLAGS__NO",
#"""
"@$(DERIVED_FILE_DIR)/cxx.compile.params \#
"@$(BAZEL_OUT)\#(outputPath.dropFirst(9)) \#
-D_FORTIFY_SOURCE=\#(fortifySourceLevel)"
"""#
)
)
buildSettings.append(
(
"ASAN_OTHER_CPLUSPLUSFLAGS__YES",
#""@$(DERIVED_FILE_DIR)/cxx.compile.params""#
#"""
"@$(BAZEL_OUT)\#(outputPath.dropFirst(9))"
"""#
)
)
buildSettings.append(
Expand All @@ -116,7 +150,9 @@ extension Generator.ProcessCxxArgs {
buildSettings.append(
(
"OTHER_CPLUSPLUSFLAGS",
#""@$(DERIVED_FILE_DIR)/cxx.compile.params""#
#"""
"@$(BAZEL_OUT)\#(outputPath.dropFirst(9))"
"""#
)
)
}
Expand Down
27 changes: 23 additions & 4 deletions xcodeproj/internal/pbxproj_partials.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Actions for creating `PBXProj` partials."""

load("//xcodeproj/internal/files:files.bzl", "join_paths_ignoring_empty")
load("//xcodeproj/internal:execution_root.bzl", "write_execution_root_file")
load(":collections.bzl", "uniq")
load(
":memory_efficiency.bzl",
Expand All @@ -11,6 +12,7 @@ load(
"TRUE_ARG",
)
load(":platforms.bzl", "PLATFORM_NAME")
load("@build_bazel_apple_support//lib:apple_support.bzl", "apple_support")

_UNIT_TEST_PRODUCT_TYPE = "u" # com.apple.product-type.bundle.unit-test

Expand Down Expand Up @@ -1092,6 +1094,9 @@ def _write_target_build_settings(
swift_args,
swift_debug_settings_to_merge = EMPTY_DEPSET,
team_id = None,
xcode_config,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brentleyjones Got a question on handling this param in the unit test for this function. Right now, apple_support.run() would try to validate xcode_config and fails in unit test.

I would like to mock XcodeVersionConfig, but can we even mock it?

apple_fragment,
bin_dir_path,
tool):
"""Creates the `OTHER_SWIFT_FLAGS` build setting string file for a target.

Expand Down Expand Up @@ -1129,6 +1134,9 @@ def _write_target_build_settings(
swift_debug_settings_to_merge: A `depset` of `Files` containing
Swift debug settings from dependencies.
team_id: The team ID to use for code signing.
xcode_config: `apple_common.XcodeVersionConfig` providerfound in ccontext
apple_fragment: A reference to the apple fragment `ctx.fragments.apple`.
bin_dir_path: `ctx.bin_dir.path`
tool: The executable that will generate the output files.

Returns:
Expand All @@ -1147,6 +1155,12 @@ def _write_target_build_settings(
outputs = []
params = []

execution_root_file = write_execution_root_file(
actions = actions,
bin_dir_path = bin_dir_path,
name = name,
)

args = actions.args()

# colorize
Expand Down Expand Up @@ -1185,15 +1199,17 @@ def _write_target_build_settings(
terminate_with = "",
)

inputs = swift_debug_settings_to_merge
inputs = depset(transitive = [swift_debug_settings_to_merge, depset([execution_root_file])])
else:
debug_settings_output = None

# swiftDebugSettingsOutputPath
args.add("")
inputs = [execution_root_file]

inputs = []

# executionRootFilePath
args.add(execution_root_file)

# deviceFamily
args.add(device_family)

Expand Down Expand Up @@ -1263,7 +1279,10 @@ def _write_target_build_settings(
# cxxParams
cxx_output_args.add(cxx_params)

actions.run(
apple_support.run(
actions = actions,
xcode_config = xcode_config,
apple_fragment = apple_fragment,
arguments = (
[args] + swift_args + [c_output_args] + conly_args +
[cxx_output_args] + cxx_args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def _process_incremental_library_target(
target = target,
)

xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
apple_fragment = ctx.fragments.apple

(
target_build_settings,
swift_debug_settings_file,
Expand All @@ -144,6 +147,9 @@ def _process_incremental_library_target(
name = label.name,
swift_args = args.swift,
tool = ctx.executable._target_build_settings_generator,
xcode_config = xcode_config,
apple_fragment = apple_fragment,
bin_dir_path = bin_dir_path,
)

swift_debug_settings = depset(
Expand Down
Loading
Loading