from waftools.pebble_test import clar

import generate_c_byte_array
import generate_timezone_data

def build(ctx):
    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/normal/filesystem/flash_translation.c" \
            " src/fw/services/normal/filesystem/pfs.c" \
            " src/fw/system/hexdump.c" \
            " src/fw/flash_region/flash_region.c" \
            " src/fw/flash_region/filesystem_regions.c" \
            " tests/fakes/fake_spi_flash.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/legacy_checksum.c" \
            " tests/fakes/fake_rtc.c",
        test_sources_ant_glob = "test_pfs.c",
        defines=['DUMA_DISABLED'],  # PBL-18355 Invalid memory read access
        override_includes=['dummy_board'],
        platforms=['tintin'])

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/common/put_bytes/put_bytes.c" \
            " src/fw/services/common/put_bytes/put_bytes_storage.c" \
            " tests/fakes/fake_session.c" \
            " src/fw/util/legacy_checksum.c" \
            " tests/fakes/fake_events.c" \
            " tests/fakes/fake_put_bytes_storage_mem.c" \
            " tests/fakes/fake_queue.c"
            " tests/fakes/fake_resource_storage.c" \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_spi_flash.c",
        test_sources_ant_glob = "test_put_bytes.c",
        platforms=['snowy','silk'],
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/normal/analytics/analytics.c" \
            " src/fw/services/normal/analytics/analytics_heartbeat.c" \
            " src/fw/services/normal/analytics/analytics_metric.c" \
            " src/fw/services/normal/analytics/analytics_storage.c" \
            " src/fw/services/normal/analytics/analytics_logging.c" \
            " src/fw/services/normal/analytics/analytics_event.c" \
            " tests/fakes/fake_rtc.c" \
            " src/fw/util/rand/rand.c" \
            " third_party/tinymt/TinyMT/tinymt/tinymt32.c",
        test_sources_ant_glob = "test_analytics.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
            " tests/fakes/fake_rtc.c" \
            " src/fw/services/common/cron.c" \
            " src/fw/util/time/time.c" \
            " src/fw/util/time/mktime.c",
        test_sources_ant_glob = "test_cron.c")

    clar(ctx,
        sources_ant_glob = \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_spi_flash.c" \
            " src/fw/flash_region/flash_region.c" \
            " src/fw/flash_region/filesystem_regions.c" \
            " src/fw/services/normal/contacts/attributes_address.c" \
            " src/fw/services/normal/contacts/contacts.c" \
            " src/fw/services/normal/blob_db/contacts_db.c" \
            " src/fw/services/normal/filesystem/flash_translation.c" \
            " src/fw/services/normal/filesystem/pfs.c" \
            " src/fw/services/normal/settings/settings_file.c" \
            " src/fw/services/normal/settings/settings_raw_iter.c" \
            " src/fw/services/normal/timeline/item.c" \
            " src/fw/services/normal/timeline/attributes_actions.c" \
            " src/fw/services/normal/timeline/attribute_group.c" \
            " src/fw/services/normal/timeline/attribute.c" \
            " src/fw/util/stringlist.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/legacy_checksum.c" \
            " src/fw/util/rand/rand.c" \
            " src/fw/util/time/time.c" \
            " third_party/tinymt/TinyMT/tinymt/tinymt32.c",
        test_sources_ant_glob = "test_contacts.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/common/evented_timer.c",
        test_sources_ant_glob = "test_evented_timer.c")

    clar(ctx,
        sources_ant_glob = \
            " tests/fakes/fake_events.c" \
            " tests/fakes/fake_session.c" \
            " tests/fakes/fake_rtc.c" \
            " src/fw/services/normal/music_endpoint.c" \
            " src/fw/services/normal/music.c",
        test_sources_ant_glob = "test_music_endpoint.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/common/ecompass_correction.c",
        test_sources_ant_glob = "test_compass_cal.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/common/light.c",
        test_sources_ant_glob = "test_light.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
            " tests/fakes/fake_events.c" \
            " tests/fakes/fake_session.c" \
            " src/fw/services/normal/phone_call_util.c" \
            " src/fw/services/common/phone_pp.c",
        test_sources_ant_glob = "test_phone_pp.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/normal/phone_call.c",
        test_sources_ant_glob = "test_phone_call.c",)

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/common/regular_timer.c" \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_session.c" \
            " src/fw/services/common/debounced_connection_service.c",
        test_sources_ant_glob = "test_debounced_connection_service.c")

    clar(ctx,
        sources_ant_glob = \
            " tests/fakes/fake_rtc.c" \
            " src/fw/util/rand/rand.c" \
            " third_party/tinymt/TinyMT/tinymt/tinymt32.c" \
            " src/fw/services/normal/timeline/item.c" \
            " src/fw/services/normal/timeline/attributes_actions.c" \
            " src/fw/services/normal/timeline/attribute_group.c" \
            " src/fw/services/normal/timeline/attribute.c" \
            " src/fw/util/stringlist.c" \
            " src/fw/util/time/time.c",
        test_sources_ant_glob = "test_timeline_item.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/services/common/i18n/i18n.c" \
            " src/fw/flash_region/flash_region.c" \
            " src/fw/flash_region/filesystem_regions.c" \
            " src/fw/resource/resource.c" \
            " src/fw/resource/resource_storage.c" \
            " src/fw/resource/resource_storage_builtin.c" \
            " src/fw/resource/resource_storage_file.c" \
            " src/fw/resource/resource_storage_flash.c" \
            " src/fw/services/normal/filesystem/flash_translation.c" \
            " src/fw/services/normal/filesystem/pfs.c" \
            " src/fw/services/normal/filesystem/app_file.c" \
            " src/fw/util/time/time.c" \
            " src/fw/util/time/mktime.c" \
            " tests/fakes/fake_bootbits.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/legacy_checksum.c" \
            " src/fw/drivers/flash/flash_crc.c" \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_events.c" \
            " tests/fakes/fake_spi_flash.c" \
            " tests/fixtures/resources/builtin_resources.auto.c" \
            " tests/fixtures/resources/pfs_resource_table.c" \
            " src/fw/services/normal/timezone_database.c" \
            " src/fw/services/common/clock.c",
        test_sources_ant_glob = "test_clock.c",
        override_includes=['test_timezone', 'dummy_board'])


    olson_txt = ctx.srcnode.make_node('resources/normal/base/tzdata/timezones_olson.txt')
    timezone_fixture_h = ctx.path.get_bld().make_node('timezone_fixture.auto.h')

    def _generate_timezone_fixture_h(task):
        reso = generate_timezone_data.generate_resource_object(task.inputs[0].abspath())
        with open(task.outputs[0].abspath(), 'w') as f:
            generate_c_byte_array.write(f, reso.data, 's_timezone_database')
    ctx(rule=_generate_timezone_fixture_h, source=olson_txt, target=timezone_fixture_h)

    clar(ctx,
         sources_ant_glob = \
            " tests/fakes/fake_spi_flash.c" \
            " src/fw/services/normal/timezone_database.c",
         test_sources_ant_glob="test_timezone_database.c",
         override_includes=['test_timezone'])

    clar(ctx,
        sources_ant_glob = " ".join([
            " src/fw/flash_region/flash_region.c" \
            " src/fw/flash_region/filesystem_regions.c" \
            " src/fw/util/rand/rand.c" \
            " third_party/tinymt/TinyMT/tinymt/tinymt32.c" \
            " src/fw/process_management/pebble_process_info.c" \
            " src/fw/resource/resource.c" \
            " src/fw/resource/resource_storage.c" \
            " src/fw/resource/resource_storage_builtin.c" \
            " src/fw/resource/resource_storage_file.c" \
            " src/fw/resource/resource_storage_flash.c" \
            " src/fw/services/normal/filesystem/flash_translation.c" \
            " src/fw/services/normal/filesystem/pfs.c" \
            " src/fw/services/normal/filesystem/app_file.c" \
            " src/fw/services/normal/settings/settings_file.c" \
            " src/fw/services/normal/settings/settings_raw_iter.c" \
            " src/fw/services/normal/wakeup.c" \
            " tests/fakes/fake_bootbits.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/legacy_checksum.c" \
            " src/fw/drivers/flash/flash_crc.c" \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_spi_flash.c" \
            " tests/fixtures/resources/builtin_resources.auto.c" \
            " tests/fixtures/resources/pfs_resource_table.c"]),
        test_sources_ant_glob = "test_wakeup.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = " ".join([
            " src/fw/drivers/flash/flash_crc.c" \
            " src/fw/flash_region/filesystem_regions.c" \
            " src/fw/flash_region/flash_region.c" \
            " src/fw/process_management/pebble_process_info.c" \
            " src/fw/resource/resource.c" \
            " src/fw/resource/resource_storage.c" \
            " src/fw/resource/resource_storage_builtin.c" \
            " src/fw/resource/resource_storage_file.c" \
            " src/fw/resource/resource_storage_flash.c" \
            " src/fw/services/normal/filesystem/app_file.c" \
            " src/fw/services/normal/filesystem/flash_translation.c" \
            " src/fw/services/normal/filesystem/pfs.c" \
            " src/fw/services/normal/settings/settings_file.c" \
            " src/fw/services/normal/settings/settings_raw_iter.c" \
            " src/fw/services/normal/wakeup.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/legacy_checksum.c" \
            " src/fw/util/rand/rand.c" \
            " third_party/tinymt/TinyMT/tinymt/tinymt32.c" \
            " tests/fakes/fake_bootbits.c" \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_spi_flash.c" \
            " tests/fixtures/resources/builtin_resources.auto.c" \
            " tests/fixtures/resources/pfs_resource_table.c" \
        ]),
        test_sources_ant_glob = "test_migrate_wakeup.c",
        override_includes=['dummy_board'])


    clar(ctx,
        sources_ant_glob = " ".join([
            "src/fw/services/common/registry_endpoint.c"]),
        test_sources_ant_glob = "test_registry_endpoint.c")

    clar(ctx,
        defines=["PLATFORM_SNOWY"],
        sources_ant_glob = " ".join([
            " src/fw/services/normal/audio_endpoint.c " \
            " tests/fakes/fake_session.c"]),\
        test_sources_ant_glob = "test_audio_endpoint.c")

    clar(ctx,
        sources_ant_glob = " ".join([
            " src/fw/services/normal/voice/transcription.c"]),
        test_sources_ant_glob = "test_transcription.c")

    clar(ctx,
        sources_ant_glob = " ".join([
            " src/fw/util/rand/rand.c" \
            " third_party/tinymt/TinyMT/tinymt/tinymt32.c" \
            " src/fw/util/generic_attribute.c" \
            " src/fw/services/normal/voice/transcription.c" \
            " src/fw/services/normal/voice_endpoint.c " \
            " tests/fakes/fake_session.c " \
            ]),
        defines=["PLATFORM_SNOWY", "CAPABILITY_HAS_MICROPHONE=1"],
        test_sources_ant_glob = "test_voice_endpoint.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
        "  src/fw/flash_region/flash_region.c" \
        "  src/fw/flash_region/filesystem_regions.c" \
        "  src/fw/services/normal/filesystem/app_file.c" \
        "  src/fw/services/normal/filesystem/flash_translation.c" \
        "  src/fw/services/normal/filesystem/pfs.c" \
        "  src/fw/services/normal/app_cache.c" \
        "  src/fw/services/normal/settings/settings_file.c" \
        "  src/fw/services/normal/settings/settings_raw_iter.c" \
        "  src/fw/util/crc8.c" \
        "  src/fw/util/legacy_checksum.c" \
        "  tests/fakes/fake_rtc.c" \
        "  tests/fakes/fake_spi_flash.c" \
        "  tests/fakes/fake_events.c",
        test_sources_ant_glob = "test_app_cache.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
        "  src/fw/flash_region/flash_region.c" \
        "  src/fw/flash_region/filesystem_regions.c" \
        "  src/fw/resource/resource.c" \
        "  src/fw/resource/resource_storage.c" \
        "  src/fw/resource/resource_storage_builtin.c" \
        "  src/fw/resource/resource_storage_file.c" \
        "  src/fw/resource/resource_storage_flash.c" \
        "  src/fw/services/normal/filesystem/flash_translation.c" \
        "  src/fw/services/normal/filesystem/pfs.c" \
        "  src/fw/services/normal/filesystem/app_file.c" \
        "  src/fw/services/normal/app_cache.c" \
        "  src/fw/services/normal/process_management/app_storage.c" \
        "  src/fw/process_management/app_install_manager.c" \
        "  src/fw/process_management/pebble_process_md.c" \
        "  src/fw/services/normal/blob_db/app_db.c" \
        "  src/fw/services/normal/settings/settings_file.c" \
        "  src/fw/services/normal/settings/settings_raw_iter.c" \
        "  src/fw/util/rand/rand.c" \
        "  third_party/tinymt/TinyMT/tinymt/tinymt32.c" \
        "  src/fw/applib/graphics/gcolor_definitions.c" \
        "  src/fw/applib/graphics/gtypes.c" \
        "  src/fw/process_management/pebble_process_info.c" \
        "  src/fw/util/crc8.c" \
        "  src/fw/util/legacy_checksum.c" \
        "  src/fw/drivers/flash/flash_crc.c" \
        "  tests/fakes/fake_rtc.c" \
        "  tests/fixtures/resources/builtin_resources.auto.c" \
        "  tests/fakes/fake_system_app_registry_apps.c" \
        "  tests/fakes/fake_spi_flash.c",
        test_sources_ant_glob = "test_app_install_manager.c",
        override_includes=['dummy_board', 'fake_app_registry'])

    clar(ctx,
         sources_ant_glob=(
             "src/fw/applib/graphics/gcolor_definitions.c "
             "src/fw/applib/graphics/gtypes.c "
             "src/fw/drivers/flash/flash_crc.c "
             "src/fw/flash_region/filesystem_regions.c "
             "src/fw/flash_region/flash_region.c "
             "src/fw/process_management/app_install_manager.c "
             "src/fw/process_management/app_menu_data_source.c "
             "src/fw/process_management/pebble_process_info.c "
             "src/fw/process_management/pebble_process_md.c "
             "src/fw/resource/resource.c "
             "src/fw/resource/resource_storage.c "
             "src/fw/resource/resource_storage_builtin.c "
             "src/fw/resource/resource_storage_file.c "
             "src/fw/resource/resource_storage_flash.c "
             "src/fw/services/normal/app_cache.c "
             "src/fw/services/normal/blob_db/app_db.c "
             "src/fw/services/normal/filesystem/app_file.c "
             "src/fw/services/normal/filesystem/flash_translation.c "
             "src/fw/services/normal/filesystem/pfs.c "
             "src/fw/services/normal/process_management/app_order_storage.c "
             "src/fw/services/normal/process_management/app_storage.c "
             "src/fw/services/normal/settings/settings_file.c "
             "src/fw/services/normal/settings/settings_raw_iter.c "
             "src/fw/util/crc8.c "
             "src/fw/util/legacy_checksum.c "
             "src/fw/util/rand/rand.c "
             "third_party/tinymt/TinyMT/tinymt/tinymt32.c "
             "tests/fakes/fake_rtc.c "
             "tests/fakes/fake_spi_flash.c "
             "tests/fakes/fake_system_app_registry_apps.c "
             "tests/fixtures/resources/builtin_resources.auto.c "
         ),
         test_sources_ant_glob="test_app_menu_data_source.c",
         override_includes=['dummy_board', 'fake_app_registry'])

    clar(ctx,
        sources_ant_glob =
            "  src/fw/util/rand/rand.c" \
            "  third_party/tinymt/TinyMT/tinymt/tinymt32.c" \
            "  src/fw/services/normal/app_fetch_endpoint.c" \
            "  tests/fakes/fake_events.c " \
            "  tests/fakes/fake_session.c ",
        test_sources_ant_glob = "test_app_fetch_endpoint.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob =
            "  src/fw/util/shared_circular_buffer.c" \
            "  src/fw/services/common/accel_manager.c" \
            "  tests/fakes/fake_events.c " \
            ,
        test_sources_ant_glob = "test_accel_manager.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = " ".join([
            " src/fw/services/common/shared_prf_storage/v3_sprf/shared_prf_storage.c " \
            " tests/fakes/fake_flash_region.c" \
            " tests/fakes/fake_spi_flash.c" \
            ]),
        test_sources_ant_glob = "test_shared_prf_storage_v3.c",
        platforms=['silk'],
        override_includes=['shared_prf_storage_v3'])

    clar(ctx,
         sources_ant_glob = " ".join([
             " src/fw/services/common/shared_prf_storage/v2_sprf/shared_prf_storage.c " \
             " tests/fakes/fake_spi_flash.c" \
             ]),
         test_sources_ant_glob = "test_shared_prf_storage_v2.c",
         override_includes=['snowy_mfg_board'])

    clar(ctx,
        sources_ant_glob = 'src/fw/services/normal/filesystem/app_file.c',
        test_sources_ant_glob = 'test_app_file.c')

    clar(ctx,
        sources_ant_glob = \
            " src/fw/flash_region/flash_region.c" \
            " src/fw/flash_region/filesystem_regions.c" \
            " src/fw/services/normal/filesystem/flash_translation.c" \
            " src/fw/services/normal/filesystem/pfs.c" \
            " src/fw/services/normal/settings/settings_file.c" \
            " src/fw/services/normal/settings/settings_raw_iter.c" \
            " src/fw/services/normal/notifications/alerts_preferences.c" \
            " src/fw/services/normal/notifications/do_not_disturb.c" \
            " src/fw/util/time/time.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/legacy_checksum.c" \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_spi_flash.c",
        defines=['CAPABILITY_HAS_HEALTH_TRACKING=1'],
        test_sources_ant_glob = "test_do_not_disturb.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = \
            " src/fw/util/pstring.c" \
            " src/fw/util/time/time.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/legacy_checksum.c" \
            " tests/fakes/fake_rtc.c" \
            " tests/fakes/fake_spi_flash.c" \
            " src/fw/flash_region/flash_region.c" \
            " src/fw/flash_region/filesystem_regions.c" \
            " src/fw/services/normal/settings/settings_file.c" \
            " src/fw/services/normal/settings/settings_raw_iter.c" \
            " src/fw/services/normal/filesystem/flash_translation.c" \
            " src/fw/services/normal/filesystem/pfs.c" \
            " src/fw/services/normal/blob_db/weather_db.c" \
            " src/fw/services/normal/weather/weather_service.c" \
            " tests/fw/services/blob_db/weather_data_shared.c",
        test_sources_ant_glob = "test_weather_service.c",
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob = "src/fw/services/normal/accessory/smartstrap_comms.c" \
            " src/fw/util/crc8.c" \
            " src/fw/util/hdlc.c" \
            " src/fw/util/mbuf.c" \
            " src/fw/util/mbuf_iterator.c" \
            " tests/fakes/fake_accessory.c" \
            " tests/fakes/fake_smartstrap_profiles.c" \
            " tests/fakes/fake_smartstrap_state.c",
        test_sources_ant_glob = "test_smartstrap_comms.c")

    clar(ctx,
        sources_ant_glob = "src/fw/services/common/vibe_pattern.c" \
            " src/fw/applib/ui/vibes.c" \
            " tests/fakes/fake_events.c" \
            " tests/fakes/fake_rtc.c",
        test_sources_ant_glob = "test_vibe.c")

    clar(ctx,
         sources_ant_glob = "src/fw/services/normal/vibes/vibe_intensity.c",
         test_sources_ant_glob = "test_vibe_intensity.c")

    clar(ctx,
        sources_ant_glob = "src/fw/services/normal/vibes/vibe_score.c" \
            " src/fw/util/generic_attribute.c",
        test_sources_ant_glob = "test_vibe_score.c")

    clar(ctx,
        sources_ant_glob = "src/fw/services/normal/vibes/vibe_score_info.c",
        test_sources_ant_glob = "test_vibe_score_info.c")

    clar(ctx,
        sources_ant_glob = "src/fw/services/common/touch/touch.c" \
            " tests/fakes/fake_events.c",
        test_sources_ant_glob = "test_touch.c")

    clar(ctx,
        sources_ant_glob = \
            "src/fw/services/common/hrm/hrm_manager.c " \
            "src/libos/tick.c " \
            "tests/fakes/fake_events.c " \
            "tests/fakes/fake_rtc.c " \
            "tests/fakes/fake_accel_service.c ",
        test_sources_ant_glob = "test_hrm_manager.c",
        override_includes=['dummy_board'],
        defines=["CAPABILITY_HAS_BUILTIN_HRM=1"])

    clar(ctx,
         sources_ant_glob=(
             " src/fw/services/normal/app_glances/app_glance_service.c"
             " src/fw/services/normal/blob_db/app_glance_db.c"
             " src/fw/services/normal/timeline/attribute.c"
             " src/fw/util/crc8.c"
             " tests/fakes/fake_rtc.c"
             " tests/fakes/fake_settings_file.c"
         ),
         test_sources_ant_glob="test_app_glance_service.c",
         override_includes=['dummy_board'])

# vim:filetype=python
