Skip to content

Commit 18aa7a4

Browse files
Deomid Ryabkovcesantabot
authored andcommitted
Support for new repo layout: fw/platforms -> platforms
Maintains compatibility with old layout. CL: mos: Support for new repo layout: fw/platforms -> platforms PUBLISHED_FROM=72ed329a5c67e7dd98d1bad529e26b72f1d968b1
1 parent 2034cc0 commit 18aa7a4

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

mos/build_local.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ func buildLocal2(ctx context.Context, bParams *buildParams, clean bool) (err err
240240

241241
var errs error
242242
for k, v := range map[string]string{
243-
"MGOS_PATH": dockerMgosPath,
244243
"PLATFORM": manifest.Platform,
245244
"BUILD_DIR": objsDirDocker,
246245
"FW_DIR": fwDirDocker,
@@ -278,9 +277,9 @@ func buildLocal2(ctx context.Context, bParams *buildParams, clean bool) (err err
278277
return errors.Trace(err)
279278
}
280279

280+
makeFilePath := moscommon.GetPlatformMakefilePath(fp.MosDirEffective, manifest.Platform)
281281
makeVarsFileSupported := false
282-
if data, err := ioutil.ReadFile(
283-
moscommon.GetPlatformMakefilePath(fp.MosDirEffective, manifest.Platform)); err == nil {
282+
if data, err := ioutil.ReadFile(makeFilePath); err == nil {
284283
makeVarsFileSupported = bytes.Contains(data, []byte("MGOS_VARS_FILE"))
285284
}
286285

@@ -317,6 +316,8 @@ func buildLocal2(ctx context.Context, bParams *buildParams, clean bool) (err err
317316
mp.addMountPoint(fp.MosDirEffective, dockerMgosPath)
318317
mp.addMountPoint(fp.MosDirEffective, ourutil.GetPathForDocker(fp.MosDirEffective))
319318

319+
manifest.BuildVars["MGOS_PATH"] = ourutil.GetPathForDocker(fp.MosDirEffective)
320+
320321
// Mount build dir
321322
mp.addMountPoint(buildDirAbs, ourutil.GetPathForDocker(buildDirAbs))
322323

@@ -396,6 +397,7 @@ func buildLocal2(ctx context.Context, bParams *buildParams, clean bool) (err err
396397

397398
makeArgs, err := getMakeArgs(
398399
filepath.ToSlash(fmt.Sprintf("%s%s", dockerAppPath, appSubdir)),
400+
makeFilePath,
399401
bParams.BuildTarget,
400402
buildDirAbs,
401403
manifest,
@@ -420,7 +422,14 @@ func buildLocal2(ctx context.Context, bParams *buildParams, clean bool) (err err
420422

421423
manifest.BuildVars["MGOS_PATH"] = fp.MosDirEffective
422424

423-
makeArgs, err := getMakeArgs(appPath, bParams.BuildTarget, buildDirAbs, manifest, makeVarsFileSupported)
425+
makeArgs, err := getMakeArgs(
426+
appPath,
427+
makeFilePath,
428+
bParams.BuildTarget,
429+
buildDirAbs,
430+
manifest,
431+
makeVarsFileSupported,
432+
)
424433
if err != nil {
425434
return errors.Trace(err)
426435
}
@@ -468,7 +477,7 @@ func isInDockerToolbox() bool {
468477
return os.Getenv("DOCKER_HOST") != ""
469478
}
470479

471-
func getMakeArgs(dir, target, buildDirAbs string, manifest *build.FWAppManifest, makeVarsFileSupported bool) ([]string, error) {
480+
func getMakeArgs(dir, makeFilePath, target, buildDirAbs string, manifest *build.FWAppManifest, makeVarsFileSupported bool) ([]string, error) {
472481
j := *buildParalellism
473482
if j == 0 {
474483
j = runtime.NumCPU()
@@ -489,10 +498,7 @@ func getMakeArgs(dir, target, buildDirAbs string, manifest *build.FWAppManifest,
489498
makeArgs := []string{
490499
"-j", fmt.Sprintf("%d", j),
491500
"-C", dir,
492-
// NOTE that we use path instead of filepath, because it'll run in a docker
493-
// container, and thus will use Linux path separator
494-
"-f", ourutil.GetPathForDocker(moscommon.GetPlatformMakefilePath(
495-
manifest.BuildVars["MGOS_PATH"], manifest.BuildVars["PLATFORM"])),
501+
"-f", ourutil.GetPathForDocker(makeFilePath),
496502
target,
497503
}
498504

mos/common/paths.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package moscommon
22

33
import (
44
"fmt"
5+
"os"
56
"path/filepath"
67

78
flag "github.com/spf13/pflag"
@@ -46,7 +47,23 @@ func GetFilesystemStagingDir(buildDir string) string {
4647
}
4748

4849
func GetPlatformMakefilePath(mosDir, platform string) string {
49-
return filepath.Join(mosDir, "fw", "platforms", platform, "Makefile.build")
50+
// New repo layout introduced on 2019/04/29, current release is 2.13.1.
51+
oldPath := filepath.Join(mosDir, "fw", "platforms", platform, "Makefile.build")
52+
newPath := filepath.Join(mosDir, "platforms", platform, "Makefile.build")
53+
if _, err := os.Stat(newPath); err == nil {
54+
return newPath
55+
}
56+
return oldPath
57+
}
58+
59+
func GetSdkVersionFile(mosDir, platform string) string {
60+
// New repo layout introduced on 2019/04/29, current release is 2.13.1.
61+
oldPath := filepath.Join(mosDir, "fw", "platforms", platform, "sdk.version")
62+
newPath := filepath.Join(mosDir, "platforms", platform, "sdk.version")
63+
if _, err := os.Stat(newPath); err == nil {
64+
return newPath
65+
}
66+
return oldPath
5067
}
5168

5269
func GetBuildCtxFilePath(buildDir string) string {
@@ -104,7 +121,3 @@ func GetBinaryLibFilePath(buildDir, name, variant, version string) string {
104121
}
105122
return filepath.Join(bld, fmt.Sprintf("lib%s-%s-%s.a", name, variant, version))
106123
}
107-
108-
func GetSdkVersionFile(mosDir, platform string) string {
109-
return filepath.Join(mosDir, "fw", "platforms", platform, "sdk.version")
110-
}

mos/manifest_parser/manifest_parser.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,10 +1618,10 @@ func globify(srcPaths []string, globs []string) (sources []string, dirs []string
16181618
}
16191619

16201620
func getAllSupportedPlatforms(mosDir string) ([]string, error) {
1621-
paths, err := filepath.Glob(moscommon.GetSdkVersionFile(mosDir, "*"))
1622-
if err != nil {
1623-
return nil, errors.Trace(err)
1624-
}
1621+
// New repo layout introduced on 2019/04/29, current release is 2.13.1.
1622+
pathsOld, _ := filepath.Glob(filepath.Join(mosDir, "fw", "platforms", "*", "sdk.version"))
1623+
pathsNew, _ := filepath.Glob(filepath.Join(mosDir, "platforms", "*", "sdk.version"))
1624+
paths := append(pathsOld, pathsNew...)
16251625

16261626
ret := []string{}
16271627

0 commit comments

Comments
 (0)