Skip to content

Conversation

@fredzqm
Copy link
Contributor

@fredzqm fredzqm commented Aug 9, 2024

Description

The existing behavior

From an empty directory. Run firebase init dataconnect and then firebase init dataconnect:sdk 3 times for each platform.

We got connector.yaml:

connectorId: default-connector
authMode: PUBLIC
generate:
  swiftSdk:
    outputDir: ../../generated/default-connector
    package: defaultConnector
  javascriptSdk:
    outputDir: ../../generated/default-connector
    package: "@firebasegen/default-connector"
  kotlinSdk:
    outputDir: ../../generated
    package: connectors.default_connector

Then firebase dataconnect:sdk:generate fails with

I0808 17:27:31.361713   50729 codegen.go:78] [connector "default-connector" javascriptSdk] Generating sources into "/Users/fredzqm/dev/fdc-free/generated/default-connector"
I0808 17:27:31.369158   50729 codegen.go:78] [connector "default-connector" kotlinSdk] Generating sources into "/Users/fredzqm/dev/fdc-free/generated/connectors/default_connector"
I0808 17:27:31.371549   50729 codegen.go:78] [connector "default-connector" swiftSdk] Generating sources into "/Users/fredzqm/dev/fdc-free/generated/default-connector/defaultConnector"
E0808 17:27:31.373203   50729 cmd.go:45] Failed to generate SDKs:
outputDir must be disjoint, but found "/Users/fredzqm/dev/fdc-free/generated/default-connector" [connector "default-connector" javascriptSdk] is a parent folder of "/Users/fredzqm/dev/fdc-free/generated/default-connector/defaultConnector" [connector "default-connector" swiftSdk]

Using Google Analytics in DEBUG mode. Emulators (+ UI) events will be shown in GA Debug View only.

Error: Unable to generate your Data Connect SDKs (exit code 1): I0808 17:27:31.361713   50729 codegen.go:78] [connector "default-connector" javascriptSdk] Generating sources into "/Users/fredzqm/dev/fdc-free/generated/default-connector"
I0808 17:27:31.369158   50729 codegen.go:78] [connector "default-connector" kotlinSdk] Generating sources into "/Users/fredzqm/dev/fdc-free/generated/connectors/default_connector"
I0808 17:27:31.371549   50729 codegen.go:78] [connector "default-connector" swiftSdk] Generating sources into "/Users/fredzqm/dev/fdc-free/generated/default-connector/defaultConnector"
E0808 17:27:31.373203   50729 cmd.go:45] Failed to generate SDKs:
outputDir must be disjoint, but found "/Users/fredzqm/dev/fdc-free/generated/default-connector" [connector "default-connector" javascriptSdk] is a parent folder of "/Users/fredzqm/dev/fdc-free/generated/default-connector/defaultConnector" [connector "default-connector" swiftSdk]

Scenarios Tested

> cat dataconnect/default-connector/connector.yaml 
connectorId: default-connector
authMode: PUBLIC
generate:
  javascriptSdk:
    outputDir: ../../generated/javascript/default-connector
    package: "@firebasegen/default-connector"
    packageJsonDir: ../..
  swiftSdk:
    outputDir: ../../generated/swift
    package: DefaultConnector
  kotlinSdk:
    outputDir: ../../generated/kotlin
    package: connectors.default_connector

> tree generated
generated
├── javascript
│   └── default-connector
│       ├── esm
│       │   ├── index.esm.js
│       │   └── package.json
│       ├── index.cjs.js
│       ├── index.d.ts
│       └── package.json
├── kotlin
│   └── connectors
│       └── default_connector
│           ├── DefaultConnectorConnector.kt
│           └── DefaultConnectorConnectorKeys.kt
└── swift
    └── DefaultConnector
        ├── DefaultConnectorClient.swift
        ├── DefaultConnectorKeys.swift
        ├── DefaultConnectorOperations.swift
        └── Package.swift

9 directories, 11 files

When app/src/main/kotlin is present:

> cat dataconnect/default-connector/connector.yaml 
connectorId: default-connector
authMode: PUBLIC
generate:
  javascriptSdk:
    outputDir: ../../generated/javascript/default-connector
    package: "@firebasegen/default-connector"
    packageJsonDir: ../..
  swiftSdk:
    outputDir: ../../generated/swift
    package: DefaultConnector
  kotlinSdk:
    outputDir: ../../app/src/main/kotlin
    package: connectors.default_connector

> tree .
.
├── app
│   └── src
│       └── main
│           └── kotlin
│               └── connectors
│                   └── default_connector
│                       ├── DefaultConnectorConnector.kt
│                       └── DefaultConnectorConnectorKeys.kt
├── build.gradle
├── dataconnect
│   ├── dataconnect.yaml
│   ├── default-connector
│   │   ├── connector.yaml
│   │   ├── mutations.gql
│   │   └── queries.gql
│   └── schema
│       └── schema.gql
├── firebase.json
├── generated
│   ├── javascript
│   │   └── default-connector
│   │       ├── esm
│   │       │   ├── index.esm.js
│   │       │   └── package.json
│   │       ├── index.cjs.js
│   │       ├── index.d.ts
│   │       └── package.json
│   └── swift
│       └── DefaultConnector
│           ├── DefaultConnectorClient.swift
│           ├── DefaultConnectorKeys.swift
│           ├── DefaultConnectorOperations.swift
│           └── Package.swift
├── package.json
└── podfile

16 directories, 20 files

if (fs.existsSync(candidateDir)) {
baseDir = candidateDir;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't needed. @dconeybe and I made it always append the package path after the output path.

Just did the same for Swift as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you chat about this recently? @dconeybe requested this behavior in comments on #7522

Copy link
Contributor Author

@fredzqm fredzqm Aug 9, 2024

Choose a reason for hiding this comment

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

Yeah, this was fairly recent.

He actually added this logic to emulator.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fredzqm, this logic was added by me in #7535. If there is no app/src/main/java or app/src/main/kotlin then it creates a folder named "generated" and puts the connector into its own directory under there. If, however, one of those two directories do exist, then they are used. This is the desirable behavior. The other SDKs also go into a "generated" directory, so it made sense, to me, to put them all in there. Hopefully customers will change it anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

There must be some confusion here. The preference of using app/src/main/... is a special case that follows the conventional folder structure of basic Android apps. If you're going to remove this logic, please remove the comment above it as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the was some miscommunication here. AFAICT, we want to keep this logic - #7547 adds it back in.

Separately, even after that tweak, the output looks redundant/weird to me - by default, the connectorID shows up 2x in the output path
Screenshot 2024-08-09 at 6 45 57 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline. Reverted that change.

Thanks for catching it!

@fredzqm fredzqm enabled auto-merge (squash) August 9, 2024 00:32
@fredzqm fredzqm disabled auto-merge August 9, 2024 00:42
if (fs.existsSync(candidateDir)) {
baseDir = candidateDir;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There must be some confusion here. The preference of using app/src/main/... is a special case that follows the conventional folder structure of basic Android apps. If you're going to remove this logic, please remove the comment above it as well.

@joehan joehan mentioned this pull request Aug 9, 2024
Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

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

Not sure that we want this - lets sync up when we're all online

Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

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

LGTM!

@joehan joehan merged commit 2f4e343 into master Aug 9, 2024
@joehan joehan deleted the fz/sdk-init-default branch August 9, 2024 17:56
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