Skip to content

Support hermetic index store data via path remappings #4207

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

Closed
wants to merge 6 commits into from

Conversation

DavidGoldman
Copy link

  • When indexing, -fdebug-prefix-map will be used to remap
    paths so the computed index data will be hermetic. This
    includes the unit files' names as well as all paths embedded
    in the unit files.

  • When reading, a reverse mapping can be used e.g. via
    indexstore_store_create_with_prefix_mapping to automatically
    remap the hermetic index data to the correct local paths.

@DavidGoldman
Copy link
Author

@swift-ci Please test

@keith
Copy link
Member

keith commented Apr 12, 2022

@swift-ci please test

DavidGoldman added a commit to DavidGoldman/indexstore-db that referenced this pull request Apr 15, 2022
swiftlang/llvm-project#4207 adds path remappings
to the index store to allow using hermetic index data but remapping
for local use without the need of any external tools like index-import.

This adds a new parameter to IndexStoreDB.init to allow giving the
prefix mapping to remap from hermetic --> local paths.
- When indexing, `-fdebug-prefix-map` will be used to remap
  paths so the computed index data will be hermetic. This
  includes the unit files' names as well as all paths embedded
  in the unit files.

- When reading, a reverse mapping can be used e.g. via
  `indexstore_store_create_with_prefix_mapping` to automatically
  remap the hermetic index data to the correct local paths.
@DavidGoldman
Copy link
Author

Updated the tests to confirm that the unit file names are deterministic by including the hash in the expected output

@bnbarham bnbarham requested review from bnbarham and akyrtzi April 19, 2022 17:17
Comment on lines 31 to 32
std::map<std::string, std::string, std::greater<std::string>>
PrefixMap,
Copy link

@bnbarham bnbarham Apr 19, 2022

Choose a reason for hiding this comment

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

I think it'd be nice to extract this out into a separate data structure. IIUC there's no need for this to be a map other than that it's convenient (though not really) to pass around. So if we had a separate class for this it could internally just store a SmallVector of <struct with original and remap path>.

Copy link

Choose a reason for hiding this comment

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

I agree, and as an input to the API I think conceptually it should be an array of string pairs. Whether then the underlying implementation uses a std::map or a llvm::StringMap for the lookups, it would be an implementation detail.

Choose a reason for hiding this comment

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

FWIW I don't think a "lookup" is ever actually performed, we only ever iterate over them all and check whether there's a prefix match (hence my suggestion of a SmallVector internally).

Copy link
Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Ideally those wouldn't be maps either 😅. So these are checked in alphabetical order rather than the order they were given on the CLI?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's my understanding. I think it would make sense to clean up, but not sure it's in scope for here. Thoughts?

Choose a reason for hiding this comment

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

I'd say it's worth making whatever you add usable in those cases, but we'd want to fix that upstream anyway (so no, not in scope).

Also increment INDEXSTORE_VERSION_MINOR
Also avoid storing relative paths in the index data - make them
absolute first, which means they can be stored using
UNIT_PATH_PREFIX_WORKDIR.
@DavidGoldman
Copy link
Author

Also went ahead and made sure paths are absolutized in IndexUnitWriter --> meaning they will be stored relative to UNIT_PATH_PREFIX_WORKDIR.

@DavidGoldman
Copy link
Author

@swift-ci please test

- The PathRemapper preserves insertion order of the remappings instead
  of sorting
DavidGoldman added a commit to DavidGoldman/swift that referenced this pull request May 11, 2022
DavidGoldman added a commit to DavidGoldman/swift that referenced this pull request May 16, 2022
Swiftc port of swiftlang/llvm-project#4207.

This introduces a new flag, `-file-prefix-map` which can be used
instead of the existing `-debug-prefix-map` and `-coverage-prefix-map`
flags, and also remaps paths in index information currently.
bnbarham added a commit that referenced this pull request May 16, 2022
Support hermetic index store data via path remappings #4207
@DavidGoldman
Copy link
Author

Closing, will re-open with cherry-picks from stable.

DavidGoldman added a commit to DavidGoldman/swift that referenced this pull request May 17, 2022
Swiftc port of swiftlang/llvm-project#4207.

This introduces a new flag, `-file-prefix-map` which can be used
instead of the existing `-debug-prefix-map` and `-coverage-prefix-map`
flags, and also remaps paths in index information currently.
DavidGoldman added a commit to DavidGoldman/indexstore-db that referenced this pull request Jun 2, 2022
swiftlang/llvm-project#4207 adds path remappings
to the index store to allow using hermetic index data but remapping
for local use without the need of any external tools like index-import.

This adds a new prefixMappings parameter to IndexStoreDB.init to allow giving the
prefix mapping to remap from hermetic/canonical --> local paths. If prefix
mappings are given while the new IndexStore API is unavailable,
indexstoredb creation will fail noting that the new API is only
available in newer versions of libIndexStore.

In addition, I've added a new `indexstoredb_creation_options_*` API to
allow configuring options when creating indexstoredb from Swift.

To support testing the remappings, TibsBuilder now supports
replacing arguments containing `$SRC_DIR` and `$BUILD_DIR` with
the respective directories.
DavidGoldman added a commit to DavidGoldman/indexstore-db that referenced this pull request Jun 3, 2022
swiftlang/llvm-project#4207 adds path remappings
to the index store to allow using hermetic index data but remapping
for local use without the need of any external tools like index-import.

This adds a new prefixMappings parameter to IndexStoreDB.init to allow giving the
prefix mapping to remap from hermetic/canonical --> local paths. If prefix
mappings are given while the new IndexStore API is unavailable,
indexstoredb creation will fail noting that the new API is only
available in newer versions of libIndexStore.

In addition, I've added a new `indexstoredb_creation_options_*` API to
allow configuring options when creating indexstoredb from Swift.

To support testing the remappings, TibsBuilder now supports
replacing arguments containing `$SRC_DIR` and `$BUILD_DIR` with
the respective directories.

(cherry picked from commit aff5369)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants