Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10427 from yurenju/bug848604
Browse files Browse the repository at this point in the history
Bug 848604 - used apps.list to pick apps from apps/*, external-apps/* & ... r=timdream r=ochameau
  • Loading branch information
yurenju committed Jun 27, 2013
2 parents 979277a + 027c819 commit f1a33dc
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 120 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -48,3 +48,9 @@ manifest.appcache
/outoftree_apps/

/distribution/

/external-apps/*/test/unit/_sandbox.html
/external-apps/*/test/unit/_proxy.html

/test_external_apps/*/test/unit/_sandbox.html
/test_external_apps/*/test/unit/_proxy.html
118 changes: 78 additions & 40 deletions Makefile
Expand Up @@ -15,7 +15,8 @@
# #
# REPORTER : Mocha reporter to use for test output. #
# #
# GAIA_APP_SRCDIRS : list of directories to search for web apps #
# GAIA_APP_CONFIG : The app.list file representing applications to include in #
# Gaia #
# #
###############################################################################
-include local.mk
Expand All @@ -32,6 +33,7 @@ GAIA_OPTIMIZE?=0
GAIA_DEV_PIXELS_PER_PX?=1
DOGFOOD?=0
TEST_AGENT_PORT?=8789
GAIA_APP_TARGET?=engineering

# Enable compatibility to run in Firefox Desktop
DESKTOP?=$(DEBUG)
Expand Down Expand Up @@ -70,15 +72,12 @@ endif

REPORTER?=Spec

GAIA_APP_SRCDIRS?=apps test_apps showcase_apps
GAIA_INSTALL_PARENT?=/data/local
ADB_REMOUNT?=0

GAIA_ALL_APP_SRCDIRS=$(GAIA_APP_SRCDIRS)

ifeq ($(MAKECMDGOALS), demo)
GAIA_DOMAIN=thisdomaindoesnotexist.org
GAIA_APP_SRCDIRS=apps showcase_apps
GAIA_APP_TARGET=demo
else ifeq ($(MAKECMDGOALS), dogfood)
DOGFOOD=1
else ifeq ($(MAKECMDGOALS), production)
Expand All @@ -93,32 +92,18 @@ endif
ifeq ($(PRODUCTION), 1)
GAIA_OPTIMIZE=1
B2G_SYSTEM_APPS=1
GAIA_APP_SRCDIRS=apps
GAIA_APP_TARGET=production
ADB_REMOUNT=1
endif

ifeq ($(DOGFOOD), 1)
GAIA_APP_SRCDIRS+=dogfood_apps
GAIA_APP_TARGET=dogfood
endif

ifeq ($(B2G_SYSTEM_APPS), 1)
GAIA_INSTALL_PARENT=/system/b2g
endif

ifneq ($(GAIA_OUTOFTREE_APP_SRCDIRS),)
$(shell mkdir -p outoftree_apps \
$(foreach dir,$(GAIA_OUTOFTREE_APP_SRCDIRS),\
$(foreach appdir,$(wildcard $(dir)/*),\
&& ln -sf $(appdir) outoftree_apps/)))
GAIA_APP_SRCDIRS += outoftree_apps
endif

GAIA_LOCALES_PATH?=locales
LOCALES_FILE?=shared/resources/languages.json
GAIA_LOCALE_SRCDIRS=shared $(GAIA_APP_SRCDIRS)
GAIA_DEFAULT_LOCALE?=en-US
GAIA_INLINE_LOCALES?=1

###############################################################################
# The above rules generate the profile/ folder and all its content. #
# The profile folder content depends on different rules: #
Expand Down Expand Up @@ -160,20 +145,25 @@ ifeq (${SYS}/${ARCH},Darwin/i386)
ARCH=x86_64
endif
SEP=/
SEP_FOR_SED=/
ifneq (,$(findstring MINGW32_,$(SYS)))
CURDIR:=$(shell pwd -W | sed -e 's|/|\\\\|g')
SEP=\\
SEP_FOR_SED=\\\\
# Mingw mangle path and append c:\mozilla-build\msys\data in front of paths
MSYS_FIX=/
endif

ifndef GAIA_APP_CONFIG
GAIA_APP_CONFIG=build$(SEP)apps-$(GAIA_APP_TARGET).list
endif

ifndef GAIA_DISTRIBUTION_DIR
GAIA_DISTRIBUTION_DIR := $(CURDIR)$(SEP)distribution
else
ifneq (,$(findstring MINGW32_,$(SYS)))
GAIA_DISTRIBUTION_DIR := $(join \
$(filter %:,$(subst :,: ,$GAIA_DISTRIBUTION_DIR)),\
$(realpath $(filter-out %:,$(subst :,: ,$GAIA_DISTRIBUTION_DIR))))
GAIA_DISTRIBUTION_DIR := $(shell pushd $(GAIA_DISTRIBUTION_DIR) > /dev/null; \
pwd -W | sed 's|/|\\\\|g'; popd > /dev/null;)
else
GAIA_DISTRIBUTION_DIR := $(realpath $(GAIA_DISTRIBUTION_DIR))
endif
Expand All @@ -183,22 +173,63 @@ SETTINGS_PATH := build/custom-settings.json
ifdef GAIA_DISTRIBUTION_DIR
DISTRIBUTION_SETTINGS := $(realpath $(GAIA_DISTRIBUTION_DIR))$(SEP)settings.json
DISTRIBUTION_CONTACTS := $(realpath $(GAIA_DISTRIBUTION_DIR))$(SEP)contacts.json
DISTRIBUTION_APP_CONFIG := $(realpath $(GAIA_DISTRIBUTION_DIR))$(SEP)apps.list
ifneq ($(wildcard $(DISTRIBUTION_SETTINGS)),)
SETTINGS_PATH := $(DISTRIBUTION_SETTINGS)
endif
ifneq ($(wildcard $(DISTRIBUTION_CONTACTS)),)
CONTACTS_PATH := $(DISTRIBUTION_CONTACTS)
endif
ifneq ($(wildcard $(DISTRIBUTION_APP_CONFIG)),)
GAIA_APP_CONFIG := $(DISTRIBUTION_APP_CONFIG)
endif
endif

# Add apps from customization package
ifdef GAIA_DISTRIBUTION_DIR
DISTRIBUTION_APPS := $(realpath $(GAIA_DISTRIBUTION_DIR))$(SEP)apps
ifneq ($(wildcard $(DISTRIBUTION_APPS)),)
GAIA_APP_SRCDIRS += $(DISTRIBUTION_APPS)
endif
# Read the file specified in $GAIA_APP_CONFIG and turn them into $GAIA_APPDIRS,
# i.e., absolute path of each app.
# Path ending in wildcard (*) will be expanded, non-absolute path in the list will be matched against
# $GAIA_DISTRIBUTION_DIR and $GAIA_DIR.
# See MDN for more information.
#
# explain shell magic here:
# "$${LINE\#$${LINE%?}}": get last character
# sed 's/.\{2\}$$//': remove last two character

ifdef GAIA_APP_SRCDIRS
$(shell printf "`echo $(GAIA_APP_SRCDIRS) | sed 's| |/*\\\n|g'`/*\n" > /tmp/gaia-apps-temp.list)
GAIA_APP_CONFIG := /tmp/gaia-apps-temp.list
$(warning GAIA_APP_SRCDIRS is deprecated, please use GAIA_APP_CONFIG)
endif

GAIA_APPDIRS=$(shell while read LINE; do \
if [ "$${LINE\#$${LINE%?}}" = "*" ]; then \
srcdir="`echo "$$LINE" | sed 's/.\{2\}$$//'`"; \
[ -d $(CURDIR)$(SEP)$$srcdir ] && find $(CURDIR)$(SEP)$$srcdir -mindepth 1 -maxdepth 1 -type d | sed 's@[/\\]@$(SEP_FOR_SED)@g'; \
[ -d $(GAIA_DISTRIBUTION_DIR)$(SEP)$$srcdir ] && find $(GAIA_DISTRIBUTION_DIR)$(SEP)$$srcdir -mindepth 1 -maxdepth 1 -type d | sed 's@[/\\]@$(SEP_FOR_SED)@g'; \
else \
if [ -d "$(GAIA_DISTRIBUTION_DIR)$(SEP)$$LINE" ]; then \
echo "$(GAIA_DISTRIBUTION_DIR)$(SEP)$$LINE" | sed 's@[/\\]@$(SEP_FOR_SED)@g'; \
elif [ -d "$(CURDIR)$(SEP)$$LINE" ]; then \
echo "$(CURDIR)$(SEP)$$LINE" | sed 's@[/\\]@$(SEP_FOR_SED)@g'; \
elif [ -d "$$LINE" ]; then \
echo "$$LINE" | sed 's@[/\\]@$(SEP_FOR_SED)@g'; \
fi \
fi \
done < $(GAIA_APP_CONFIG))

ifneq ($(GAIA_OUTOFTREE_APP_SRCDIRS),)
$(shell mkdir -p outoftree_apps \
$(foreach dir,$(GAIA_OUTOFTREE_APP_SRCDIRS),\
$(foreach appdir,$(wildcard $(dir)/*),\
&& ln -sf $(appdir) outoftree_apps/)))
endif

GAIA_LOCALES_PATH?=locales
LOCALES_FILE?=shared/resources/languages.json
GAIA_LOCALE_SRCDIRS=shared $(GAIA_APPDIRS)
GAIA_DEFAULT_LOCALE?=en-US
GAIA_INLINE_LOCALES?=1

ifeq ($(SYS),Darwin)
MD5SUM = md5 -r
SED_INPLACE_NO_SUFFIX = /usr/bin/sed -i ''
Expand Down Expand Up @@ -279,9 +310,9 @@ endif
endif

app-makefiles:
@for d in ${GAIA_APP_SRCDIRS}; \
@for d in ${GAIA_APPDIRS}; \
do \
for mfile in `find $$d -mindepth 2 -maxdepth 2 -name "Makefile"` ;\
for mfile in `find $$d -mindepth 1 -maxdepth 1 -name "Makefile"` ;\
do \
make -C `dirname $$mfile`; \
done; \
Expand Down Expand Up @@ -425,7 +456,6 @@ define run-js-command
const DEBUG = $(DEBUG); const LOCAL_DOMAINS = $(LOCAL_DOMAINS); \
const DESKTOP = $(DESKTOP); \
const HOMESCREEN = "$(HOMESCREEN)"; const GAIA_PORT = "$(GAIA_PORT)"; \
const GAIA_APP_SRCDIRS = "$(GAIA_APP_SRCDIRS)"; \
const GAIA_LOCALES_PATH = "$(GAIA_LOCALES_PATH)"; \
const LOCALES_FILE = "$(subst \,\\,$(LOCALES_FILE))"; \
const BUILD_APP_NAME = "$(BUILD_APP_NAME)"; \
Expand All @@ -438,6 +468,7 @@ define run-js-command
const GAIA_INLINE_LOCALES = "$(GAIA_INLINE_LOCALES)"; \
const GAIA_ENGINE = "xpcshell"; \
const GAIA_DISTRIBUTION_DIR = "$(GAIA_DISTRIBUTION_DIR)"; \
const GAIA_APPDIRS = "$(GAIA_APPDIRS)"; \
'; \
$(XULRUNNERSDK) $(XPCSHELLSDK) -e "$$JS_CONSTS" -f build/utils.js "build/$(strip $1).js"
endef
Expand Down Expand Up @@ -582,9 +613,11 @@ test-agent-config: test-agent-bootstrap-apps
@touch $(TEST_AGENT_CONFIG)
@rm -f /tmp/test-agent-config;
@# Build json array of all test files
@for d in ${GAIA_APP_SRCDIRS}; \
@for d in ${GAIA_APPDIRS}; \
do \
find $$d -name '*_test.js' | sed "s:$$d/::g" >> /tmp/test-agent-config; \
parent="`dirname $$d`"; \
pathlen=`expr $${#parent} + 2`; \
find "$$d" -name '*_test.js' | awk '{print substr($$0,'$${pathlen}')}' >> /tmp/test-agent-config; \
done;
@echo '{"tests": [' >> $(TEST_AGENT_CONFIG)
@cat /tmp/test-agent-config | \
Expand All @@ -597,12 +630,17 @@ test-agent-config: test-agent-bootstrap-apps

.PHONY: test-agent-bootstrap-apps
test-agent-bootstrap-apps:
@for d in `find -L ${GAIA_APP_SRCDIRS} -mindepth 1 -maxdepth 1 -type d` ;\
@for d in ${GAIA_APPDIRS} ;\
do \
mkdir -p $$d/test/unit ; \
mkdir -p $$d/test/integration ; \
cp -f $(TEST_COMMON)/test/boilerplate/_proxy.html $$d/test/unit/_proxy.html; \
cp -f $(TEST_COMMON)/test/boilerplate/_sandbox.html $$d/test/unit/_sandbox.html; \
if [[ "$(SYS)" != *MINGW32_* ]]; then \
mkdir -p $$d$(SEP)test$(SEP)unit ; \
mkdir -p $$d$(SEP)test$(SEP)integration ; \
else \
mkdir -p `echo "$$d" | sed 's|^\(\w\):|/\1|g' | sed 's|\\\\|/|g'`/test/unit ; \
mkdir -p `echo "$$d" | sed 's|^\(\w\):|/\1|g' | sed 's|\\\\|/|g'`/test/integration ; \
fi; \
cp -f $(TEST_COMMON)$(SEP)test$(SEP)boilerplate$(SEP)_proxy.html $$d$(SEP)test$(SEP)unit$(SEP)_proxy.html; \
cp -f $(TEST_COMMON)$(SEP)test$(SEP)boilerplate$(SEP)_sandbox.html $$d$(SEP)test$(SEP)unit$(SEP)_sandbox.html; \
done
@echo "Finished: bootstrapping test proxies/sandboxes";

Expand Down
4 changes: 4 additions & 0 deletions build/apps-demo.list
@@ -0,0 +1,4 @@
apps/*
showcase_apps/*
external-apps/*
outoftree_apps/*
6 changes: 6 additions & 0 deletions build/apps-dogfood.list
@@ -0,0 +1,6 @@
apps/*
showcase_apps/*
external-apps/*
dogfood_apps/*
external-dogfood-apps/*
outoftree_apps/*
6 changes: 6 additions & 0 deletions build/apps-engineering.list
@@ -0,0 +1,6 @@
apps/*
test_apps/*
showcase_apps/*
test_external_apps/*
external-apps/*
outoftree_apps/*
3 changes: 3 additions & 0 deletions build/apps-production.list
@@ -0,0 +1,3 @@
apps/*
external-apps/*
outoftree_apps/*
2 changes: 1 addition & 1 deletion build/preferences.js
Expand Up @@ -114,7 +114,7 @@ if (DEBUG) {
prefs.push(["extensions.gaia.dir", GAIA_DIR]);
prefs.push(["extensions.gaia.domain", GAIA_DOMAIN]);
prefs.push(["extensions.gaia.port", parseInt(GAIA_PORT.replace(/:/g, ""))]);
prefs.push(["extensions.gaia.app_src_dirs", GAIA_APP_SRCDIRS]);
prefs.push(["extensions.gaia.appdirs", GAIA_APPDIRS]);
prefs.push(["extensions.gaia.locales_debug_path", GAIA_LOCALES_PATH]);
prefs.push(["extensions.gaia.official", Boolean(OFFICIAL)]);

Expand Down
102 changes: 42 additions & 60 deletions build/utils.js
Expand Up @@ -165,76 +165,58 @@ function getJSON(file) {
}
}

function makeWebappsObject(dirs) {
function makeWebappsObject(appdirs) {
return {
forEach: function(fun) {
let appSrcDirNames = dirs.split(' ');
appSrcDirNames.forEach(function parseDirectory(directoryName) {

// Convert the dirName to a File object
let appSrcDir = getDir(directoryName, true);

let appDirs = getSubDirs(appSrcDir);
appDirs.forEach(function readManifests(appDir) {
let manifestFile = appDir.clone();
manifestFile.append('manifest.webapp');

let updateFile = appDir.clone();
updateFile.append('update.webapp');

// Ignore directories without manifest
if (!manifestFile.exists() && !updateFile.exists()) {
return;
}

let manifest = manifestFile.exists() ? manifestFile : updateFile;

// Use the folder name as the the domain name
let domain = appDir.leafName + '.' + GAIA_DOMAIN;

let webapp = {
manifest: getJSON(manifest),
manifestFile: manifest,
url: GAIA_SCHEME + domain + (GAIA_PORT ? GAIA_PORT : ''),
domain: domain,
sourceDirectoryFile: manifestFile.parent,
sourceDirectoryName: appDir.leafName,
sourceAppDirectoryName: directoryName
};

// External webapps have a `metadata.json` file
let metaData = webapp.sourceDirectoryFile.clone();
metaData.append('metadata.json');
if (metaData.exists()) {
webapp.metaData = getJSON(metaData);
}

fun(webapp);
});
appdirs.forEach(function(app) {
let appDir = getFile(app);
if (!appDir.exists()) {
throw new Error(' -*- build/utils.js: file not found (' + app + ')\n');
}

let manifestFile = appDir.clone();
manifestFile.append('manifest.webapp');

let updateFile = appDir.clone();
updateFile.append('update.webapp');

// Ignore directories without manifest
if (!manifestFile.exists() && !updateFile.exists()) {
return;
}

let manifest = manifestFile.exists() ? manifestFile : updateFile;

// Use the folder name as the the domain name
let domain = appDir.leafName + '.' + GAIA_DOMAIN;

let webapp = {
manifest: getJSON(manifest),
manifestFile: manifest,
url: GAIA_SCHEME + domain + (GAIA_PORT ? GAIA_PORT : ''),
domain: domain,
sourceDirectoryFile: manifestFile.parent,
sourceDirectoryName: appDir.leafName,
sourceAppDirectoryName: appDir.parent.leafName
};

// External webapps have a `metadata.json` file
let metaData = webapp.sourceDirectoryFile.clone();
metaData.append('metadata.json');
if (metaData.exists()) {
webapp.metaData = getJSON(metaData);
}

fun(webapp);
});
}
};
}

let additionalSrcDirNames = ['external-apps'];

if (DOGFOOD === '0' && PRODUCTION === '0') {
additionalSrcDirNames.push('test_external_apps');
}

if (GAIA_DISTRIBUTION_DIR) {
let externalAppsDir = new FileUtils.File(GAIA_DISTRIBUTION_DIR);
externalAppsDir.append('external-apps');
if (externalAppsDir.exists()) {
additionalSrcDirNames.push(externalAppsDir.path);
}
}

const Gaia = {
engine: GAIA_ENGINE,
sharedFolder: getFile(GAIA_DIR, 'shared'),
webapps: makeWebappsObject(GAIA_APP_SRCDIRS + ' ' +
additionalSrcDirNames.join(' ')),
webapps: makeWebappsObject(GAIA_APPDIRS.split(' ')),
aggregatePrefix: 'gaia_build_',
distributionDir: GAIA_DISTRIBUTION_DIR
};
Expand Down

0 comments on commit f1a33dc

Please sign in to comment.