Skip to content

[Macros] Add a library to make simple executable plugins for testing #63927

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

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 26, 2023

Add _swiftMockPlugin library.
Usage:

 #include "swift/swift-c/MockPlugin/MockPlugin.h"

 MOCK_PLUGIN([
   {"expect": {...},
    "response: {...}},
   ...
 ])

Replaces utils/mock_plugin.py

@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2023

@swift-ci Please smoke test

@rintaro rintaro force-pushed the macros-mockplugin-lib branch from 45cb439 to 548e896 Compare February 26, 2023 19:29
@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2023

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2023

@bnbarham wdyt?
I wished to make it a static library, but that made the clang invocation in the test file long (i.e. specify all dependent libs -lLLVMSupport etc.) and made it non-portable. Do we have a way to archive multiple static libs into one, and strip dead code?

@rintaro rintaro requested a review from bnbarham February 26, 2023 19:46
@rintaro rintaro force-pushed the macros-mockplugin-lib branch from 548e896 to 38cf3a4 Compare February 26, 2023 19:52
@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2023

@swift-ci Please smoke test

Add `_swiftMockPlugin` library.
Usage:
  #include "swift/swift-c/MockPlugin/MockPlugin.h"

  MOCK_PLUGIN([
    {"expect": {...},
     "response: {...}}
  ])
@rintaro rintaro force-pushed the macros-mockplugin-lib branch from 38cf3a4 to 761cbb0 Compare February 26, 2023 20:17
@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2023

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2023

@swift-ci Please smoke test Linux

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

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

I haven't fully reviewed the plugin itself, but yeah, this looks better to me. Thanks :).

Ideally we'd also have the current test plugin as a tool and then we could have a lit substitution for that as well.

Comment on lines +6 to +12
// RUN: %clang \
// RUN: -isysroot %sdk \
// RUN: -I %swift_src_root/include \
// RUN: -L %swift-lib-dir -l_swiftMockPlugin \
// RUN: -Wl,-rpath,%swift-lib-dir \
// RUN: -o %t/mock-plugin \
// RUN: %t/plugin.c
Copy link
Contributor

Choose a reason for hiding this comment

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

You could add a lit.cfg substitution that handles the flags part of this

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do it when we introduce second usage.

Comment on lines +14 to +17
// RUN: %swift-target-frontend \
// RUN: -typecheck -verify \
// RUN: -swift-version 5 -enable-experimental-feature Macros \
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
Copy link
Contributor

Choose a reason for hiding this comment

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

Could maybe also have a substitution for this one that could take an optional name... not sure how useful it would be though.

Copy link
Member Author

Choose a reason for hiding this comment

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

the binary name (mock-plugin) and the module name (TestPlugin) are both test-file-specific.
I don't think we can reuse much.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be fine with them all being mock-plugin/TestPlugin :P. But you could give them as inputs 🤷

@rintaro rintaro merged commit e490466 into swiftlang:main Feb 27, 2023
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.

2 participants