Skip to content

Commit

Permalink
migrate to typespec, keep backward compatible to .cadl (Azure#34080)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Mar 17, 2023
1 parent 5bd215a commit b6b9000
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions eng/mgmt/automation/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ def sdk_automation_cadl(config: dict) -> List[dict]:
for cadl_project in cadl_projects:
cadl_dir = os.path.join(spec_root, cadl_project)

sdk_folder = get_cadl_sdk_folder(os.path.join(cadl_dir, 'cadl-project.yaml'))
sdk_folder = get_cadl_sdk_folder(os.path.join(cadl_dir, 'tspconfig.yaml'))
if not sdk_folder:
logging.warning('[Skip] "options.@azure-tools/cadl-java.emitter-output-dir" '
'or "parameters.service-directory-name.default" not found in cadl-project.yaml')
# fallback to cadl file
sdk_folder = get_cadl_sdk_folder(os.path.join(cadl_dir, 'cadl-project.yaml'))
if not sdk_folder:
logging.warning('[Skip] "options.@azure-tools/typespec-java.emitter-output-dir" '
'or "parameters.service-directory-name.default" not found '
'in tspconfig.yaml or cadl-project.yaml')
else:
sdk_folder_abspath = os.path.join(sdk_root, sdk_folder)
require_sdk_integration = not os.path.exists(os.path.join(sdk_folder_abspath, 'src'))
Expand Down Expand Up @@ -72,11 +76,14 @@ def sdk_automation_cadl(config: dict) -> List[dict]:

# check client.cadl
cadl_source = '.'
if os.path.exists(os.path.join(cadl_dir, 'client.cadl')):
if os.path.exists(os.path.join(cadl_dir, 'client.tsp')):
cadl_source = 'client.tsp'
if cadl_source == '.' and os.path.exists(os.path.join(cadl_dir, 'client.cadl')):
# fallback to cadl file
cadl_source = 'client.cadl'

# generate Java project
command = 'npx cadl compile {0} --emit=@azure-tools/cadl-java --arg="java-sdk-folder={1}"'\
command = 'npx tsp compile {0} --emit=@azure-tools/typespec-java --arg="java-sdk-folder={1}"'\
.format(cadl_source, sdk_root)
logging.info(command)
subprocess.run(command, shell=True, check=True)
Expand Down Expand Up @@ -128,9 +135,9 @@ def get_cadl_sdk_folder(project_filename: str) -> Optional[str]:
with open(project_filename, 'r', encoding='utf-8') as f_in:
project_yaml = yaml.safe_load(f_in)
if 'parameters' in project_yaml and 'service-directory-name' in project_yaml['parameters'] \
and 'options' in project_yaml and '@azure-tools/cadl-java' in project_yaml['options']:
and 'options' in project_yaml and '@azure-tools/typespec-java' in project_yaml['options']:
service: str = project_yaml['parameters']['service-directory-name']['default']
sdk_folder = project_yaml['options']['@azure-tools/cadl-java']['emitter-output-dir']
sdk_folder = project_yaml['options']['@azure-tools/typespec-java']['emitter-output-dir']
sdk_folder = sdk_folder.replace(
r'{java-sdk-folder}/sdk/{service-directory-name}/',
'sdk/{0}/'.format(service))
Expand Down

0 comments on commit b6b9000

Please sign in to comment.