Skip to content
Merged
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
22 changes: 19 additions & 3 deletions eng/automation/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,17 @@ def sdk_automation(input_file: str, output_file: str):
logging.error("[GENERATE] Code generation failed. Unknown exception", exc_info=True)
if packages and len(packages) == 1:
packages[0]["result"] = "failed"
else:
sys.exit(1)
sys.exit(1)

with open(output_file, "w", encoding="utf-8") as fout:
output = {
"packages": packages,
}
json.dump(output, fout)

if packages and len(packages) == 1 and packages[0]["result"] == "failed":
sys.exit(1)


def sdk_automation_autorest(config: dict) -> List[dict]:
base_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
Expand Down Expand Up @@ -250,8 +252,22 @@ def sdk_automation_typespec(config: dict) -> List[dict]:
tsp_projects = [tsp_projects]

for tsp_project in tsp_projects:
# folder structure v2: specification/{service}/[data-plane|resource-manager]/{provider}/
folder_structure_v2_pattern = r"specification/.*/(data-plane|resource-manager)"
Copy link
Member

Choose a reason for hiding this comment

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

@XiaofeiCao {service} folder in V2 is only one level. So the regex should be specification/[^/]+/(data-plane|resource-manager)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. This is only for TypeSpec, and in v1 we don't have data-plane or resource-manager segment for TypeSpec. I think it should be fine.

match = re.compile(folder_structure_v2_pattern).search(tsp_project)
if match:
sdk_type = match.group(1)
if sdk_type == "data-plane":
logging.info("[GENERATE] Generating data-plane from folder structure v2: " + tsp_project)
packages.append(sdk_automation_typespec_project_data(tsp_project, config))
elif sdk_type == "resource-manager":
logging.info("[GENERATE] Generating mgmt-plane from folder structure v2: " + tsp_project)
packages.append(sdk_automation_typespec_project(tsp_project, config))
else:
raise ValueError("Unexpected sdk type: " + sdk_type)
# folder structure v1
# mgmt tsp project folder follow the pattern, e.g. specification/deviceregistry/DeviceRegistry.Management
if re.match(r"specification[\\/](.*)[\\/](.*)[\\.]Management", tsp_project):
elif re.match(r"specification[\\/](.*)[\\/](.*)[\\.]Management", tsp_project):
packages.append(sdk_automation_typespec_project(tsp_project, config))
else:
packages.append(sdk_automation_typespec_project_data(tsp_project, config))
Expand Down