Skip to content

Commit

Permalink
Copybara import of the project:
Browse files Browse the repository at this point in the history
--
878ab77 by Dave Lee <[email protected]>:

Stop declaring module swiftdeps output

--
ac3ceba by Dave Lee <[email protected]>:

Remove unused swift_dependencies_file()

RELNOTES: None.
PiperOrigin-RevId: 277068373
  • Loading branch information
allevato authored and swiple-rules-gardener committed Oct 28, 2019
1 parent 99b2353 commit 31bae7a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 55 deletions.
9 changes: 0 additions & 9 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ def declare_compile_outputs(

output_map[src.path] = struct(**src_output_map)

# Output the module-wide `.swiftdeps` file, which is used for incremental
# builds.
swiftdeps = derived_files.swift_dependencies_file(
actions = actions,
target_name = target_name,
)
other_outputs.append(swiftdeps)
output_map[""] = {"swift-dependencies": swiftdeps.path}

actions.write(
content = struct(**output_map).to_json(),
output = output_map_file,
Expand Down
24 changes: 0 additions & 24 deletions swift/internal/derived_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,6 @@ def _swiftmodule(actions, module_name):
"""
return actions.declare_file("{}.swiftmodule".format(module_name))

def _swift_dependencies_file(actions, target_name, src = None):
"""Declares a file for compiler-generated Swift dependencies for a target.
This file is used during incremental compilation to determine which object
files and partial modules need to be rebuilt when a particular source file
changes.
Args:
actions: The context's actions object.
target_name: The name of the target being built.
src: An optional `File` representing the source file being compiled.
Returns:
The declared `File`.
"""
if src:
dirname, basename = _intermediate_frontend_file_path(target_name, src)
return actions.declare_file(
paths.join(dirname, "{}.swiftdeps".format(basename)),
)

return actions.declare_file("{}.swiftdeps".format(target_name))

def _whole_module_object_file(actions, target_name):
"""Declares a file for object files created with whole module optimization.
Expand Down Expand Up @@ -328,7 +305,6 @@ derived_files = struct(
swiftdoc = _swiftdoc,
swiftinterface = _swiftinterface,
swiftmodule = _swiftmodule,
swift_dependencies_file = _swift_dependencies_file,
whole_module_object_file = _whole_module_object_file,
xctest_bundle = _xctest_bundle,
xctest_runner_script = _xctest_runner_script,
Expand Down
29 changes: 23 additions & 6 deletions tools/common/path_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,31 @@ std::string Dirname(const std::string &path) {
}

std::string ReplaceExtension(const std::string &path,
const std::string &new_extension) {
auto last_dot = path.rfind('.');
const std::string &new_extension,
bool all_extensions) {
auto last_slash = path.rfind('/');

// If there was no dot, or if it was part of a previous path segment, append
// the extension to the path.
if (last_dot == std::string::npos || last_dot < last_slash) {
std::string::size_type dot;
if (all_extensions) {
// Find the first dot, signifying the first of all extensions.
if (last_slash != std::string::npos) {
dot = path.find('.', last_slash);
} else {
dot = path.find('.');
}
} else {
// Find the last extension only.
dot = path.rfind('.');
if (dot < last_slash) {
// If the dot was part of a previous path segment, treat it as if it
// wasn't found (it's not an extension of the filename).
dot = std::string::npos;
}
}

// If there was no dot append the extension to the path.
if (dot == std::string::npos) {
return path + new_extension;
}
return path.substr(0, last_dot) + new_extension;
return path.substr(0, dot) + new_extension;
}
3 changes: 2 additions & 1 deletion tools/common/path_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ std::string Dirname(const std::string &path);
// extension in the returned path. If the path does not have a file extension,
// then new_extension is appended to it.
std::string ReplaceExtension(const std::string &path,
const std::string &new_extension);
const std::string &new_extension,
bool all_extensions = false);

#endif // BUILD_BAZEL_RULES_SWIFT_TOOLS_COMMON_PATH_UTILS_H_
25 changes: 11 additions & 14 deletions tools/worker/output_file_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,31 @@ static std::string MakeIncrementalOutputPath(std::string path) {
void OutputFileMap::ReadFromPath(const std::string &path) {
std::ifstream stream(path);
stream >> json_;
UpdateForIncremental();
UpdateForIncremental(path);
}

void OutputFileMap::WriteToPath(const std::string &path) {
std::ofstream stream(path);
stream << json_;
}

void OutputFileMap::UpdateForIncremental() {
void OutputFileMap::UpdateForIncremental(const std::string &path) {
nlohmann::json new_output_file_map;
std::map<std::string, std::string> incremental_outputs;

// The empty string key is used to represent outputs that are for the whole
// module, rather than for a particular source file.
nlohmann::json module_map;
// Derive the swiftdeps file name from the .output-file-map.json name.
auto new_path = ReplaceExtension(path, ".swiftdeps", /*all_extensions=*/true);
auto swiftdeps_path = MakeIncrementalOutputPath(new_path);
module_map["swift-dependencies"] = swiftdeps_path;
new_output_file_map[""] = module_map;

for (auto &element : json_.items()) {
auto src = element.key();
auto outputs = element.value();

// The empty string key is used to represent outputs that are for the whole
// module, rather than for a particular source file.
if (src.empty()) {
nlohmann::json empty_map = outputs;
auto path = outputs["swift-dependencies"].get<std::string>();
auto new_path = MakeIncrementalOutputPath(path);
empty_map["swift-dependencies"] = new_path;
incremental_outputs[path] = new_path;
new_output_file_map[""] = empty_map;
continue;
}

nlohmann::json src_map;

// Process the outputs for the current source file.
Expand Down
2 changes: 1 addition & 1 deletion tools/worker/output_file_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OutputFileMap {
private:
// Modifies the output file map's JSON structure in-place to replace file
// paths with equivalents in the incremental storage area.
void UpdateForIncremental();
void UpdateForIncremental(const std::string &path);

nlohmann::json json_;
std::map<std::string, std::string> incremental_outputs_;
Expand Down

0 comments on commit 31bae7a

Please sign in to comment.