summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python/msa2inf/ConvertModule.py
blob: af9aa1d8ec82dca1597088501d58337845630a58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
## @file
# Convert an MSA Module class object ot an INF Module class object by filling
# several info required by INF file.
#
# Copyright (c) 2007 - 2010, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution.  The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#

##
# Import Modules
#
from LoadMsa import LoadMsa
from StoreInf import StoreInf
from Common.MigrationUtilities import *
from EdkIIWorkspaceGuidsInfo import gEdkIIWorkspaceGuidsInfo

#The default INF version number tool generates.
gInfVersion = "0x00010005"

## Add required version information.
#
# Add the default INF version, EFI specificiation version and EDK release
# version to Module class object.
#
# @param  Module              An input Module class object.
#
def AddModuleMiscVersion(Module):
    Version = gInfVersion
    Module.Header.InfVersion = Version

    Version = Module.Header.Specification.get("EFI_SPECIFICATION_VERSION", "")
    Module.Header.UefiSpecificationVersion = Version
    
    Version = Module.Header.Specification.get("EDK_RELEASE_VERSION", "")
    Module.Header.EdkReleaseVersion = Version


## Add Module produced library class.
#
# Add the produced library class from library class list whose usage type is
# always produced.
#
# @param  Module              An input Module class object.
#
def AddModuleProducedLibraryClass(Module):
    for LibraryClass in Module.LibraryClasses:
        if "ALWAYS_PRODUCED" in LibraryClass.Usage:
            Module.Header.LibraryClass.append(LibraryClass)


## Add Module Package Dependency path.
#
# Translate Package Dependency Guid to a file path relative to workspace.
#
# @param  Module              An input Module class object.
#
def AddModulePackageDependencyPath(Module):
    for PackageDependency in Module.PackageDependencies:
        PackageGuid = PackageDependency.PackageGuid
        PackageVersion = PackageDependency.PackageVersion
        
        GuidToFilePath = gEdkIIWorkspaceGuidsInfo.ResolvePackageFilePath
        PackageFilePath = GuidToFilePath(PackageGuid, PackageVersion)
        PackageDependency.FilePath = PackageFilePath


## Add Module Recommended Library Instance path.
#
# Translate Module Recommened Library Instance Guid to a file path relative to
# workspace.
#
# @param  Module              An input Module class object.
#
def AddModuleRecommonedLibraryInstancePath(Module):
    for LibraryClass in Module.LibraryClasses:
        if "ALWAYS_PRODUCED" in LibraryClass.Usage:
            continue

        if LibraryClass.RecommendedInstanceGuid == "":
            continue
        
        LibraryGuid = LibraryClass.RecommendedInstanceGuid
        LibraryVersion = LibraryClass.RecommendedIntanceVersion
        
        GuidToFilePath = gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath
        LibraryInstance = GuidToFilePath(LibraryGuid, LibraryVersion)
        LibraryClass.RecommendedIntance = LibraryInstance


## Convert MSA Module class object to INF Module class object.
#
# Convert MSA module class ojbect to INF Module class object by filling in
# several information required by INF file.
#
# @param  Module              An input Module class object.
#
def ConvertMsaModuleToInfModule(Module):
    AddModuleMiscVersion(Module)
    AddModuleProducedLibraryClass(Module)
    AddModulePackageDependencyPath(Module)
    AddModuleRecommonedLibraryInstancePath(Module)


if __name__ == '__main__':
    pass